
POST api/v1/summits/{id}/members/me/schedule/{event_id}/rsvp Payload anwers: array of answer DTO answer DTO question_id: int value: string or string array ( depending on type of question multivalue or not) Required Scopes REALM_BASE_URL/summits/write PUT api/v1/summits/{id}/members/me/schedule/{event_id}/rsvp Payload anwers: array of answer DTO answer DTO question_id: int value: string or string array ( depending on type of question multivalue or not) Required Scopes REALM_BASE_URL/summits/write DELETE api/v1/summits/{id}/members/me/schedule/{event_id}/rsvp Required Scopes REALM_BASE_URL/summits/write Change-Id: I9ea4388effd44617e5122e1b1a23c9c74473d2e6
83 lines
3.2 KiB
PHP
83 lines
3.2 KiB
PHP
<?php namespace ModelSerializers;
|
|
/**
|
|
* Copyright 2018 OpenStack Foundation
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
**/
|
|
use Libs\ModelSerializers\AbstractSerializer;
|
|
use models\summit\RSVP;
|
|
/**
|
|
* Class RSVPSerializer
|
|
* @package ModelSerializers
|
|
*/
|
|
final class RSVPSerializer extends SilverStripeSerializer
|
|
{
|
|
protected static $array_mappings = [
|
|
'OwnerId' => 'owner_id:json_int',
|
|
'EventId' => 'event_id:json_int',
|
|
'SeatType' => 'seat_type:json_string',
|
|
'Created' => 'created:datetime_epoch',
|
|
'ConfirmationNumber' => 'confirmation_number:json_string',
|
|
'EventUri' => 'event_uri:json_string',
|
|
];
|
|
|
|
/**
|
|
* @param null $expand
|
|
* @param array $fields
|
|
* @param array $relations
|
|
* @param array $params
|
|
* @return array
|
|
*/
|
|
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = [])
|
|
{
|
|
$rsvp = $this->object;
|
|
if(! $rsvp instanceof RSVP) return [];
|
|
$values = parent::serialize($expand, $fields, $relations, $params);
|
|
|
|
$answers = [];
|
|
foreach ($rsvp->getAnswers() as $answer){
|
|
$answers[] = $answer->getId();
|
|
}
|
|
$values['answers'] = $answers;
|
|
|
|
if (!empty($expand)) {
|
|
foreach (explode(',', $expand) as $relation) {
|
|
$relation = trim($relation);
|
|
switch ($relation) {
|
|
|
|
case 'owner': {
|
|
if(!$rsvp->hasOwner()) continue;
|
|
unset($values['owner_id']);
|
|
$values['owner'] = SerializerRegistry::getInstance()->getSerializer($rsvp->getOwner())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
|
}
|
|
break;
|
|
case 'event': {
|
|
if(!$rsvp->hasEvent()) continue;
|
|
unset($values['event_id']);
|
|
$values['event'] = SerializerRegistry::getInstance()->getSerializer($rsvp->getEvent())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
|
}
|
|
break;
|
|
|
|
case 'answers':{
|
|
$answers = [];
|
|
foreach ($rsvp->getAnswers() as $answer){
|
|
$answers[] = SerializerRegistry::getInstance()->getSerializer($answer)->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
|
}
|
|
$values['answers'] = $answers;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $values;
|
|
}
|
|
|
|
} |