Fixed Serializers
Expand by preffix miss order Change-Id: Ibf333181ce8a6cbaf6e59d9c59e708194b3a87d0 Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
parent
f60602745c
commit
9f2f594fce
Libs/ModelSerializers
app/ModelSerializers
@ -211,7 +211,7 @@ abstract class AbstractSerializer implements IModelSerializer
|
||||
* @param string $prefix
|
||||
* @return string
|
||||
*/
|
||||
protected static function filterExpandByPrefix($expand_str, $prefix ){
|
||||
protected static function filterExpandByPrefix($expand_str, $prefix){
|
||||
|
||||
$expand_to = explode(',', $expand_str);
|
||||
$filtered_expand = array_filter($expand_to, function($element) use($prefix){
|
||||
|
@ -120,16 +120,17 @@ final class OwnMemberSerializer extends AbstractMemberSerializer
|
||||
}
|
||||
|
||||
if (!empty($expand)) {
|
||||
|
||||
foreach (explode(',', $expand) as $relation) {
|
||||
$relation = trim($relation);
|
||||
switch ($relation) {
|
||||
|
||||
case 'attendee': {
|
||||
if (!is_null($attendee))
|
||||
{
|
||||
unset($values['attendee_id']);
|
||||
$values['attendee'] = SerializerRegistry::getInstance()->getSerializer($attendee)->serialize($expand,[],['none']);
|
||||
$values['attendee'] = SerializerRegistry::getInstance()->getSerializer($attendee)->serialize
|
||||
(
|
||||
AbstractSerializer::filterExpandByPrefix($expand, $relation),[],['none']
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -137,7 +138,10 @@ final class OwnMemberSerializer extends AbstractMemberSerializer
|
||||
if (!is_null($speaker))
|
||||
{
|
||||
unset($values['speaker_id']);
|
||||
$values['speaker'] = SerializerRegistry::getInstance()->getSerializer($speaker)->serialize($expand,[],['none']);
|
||||
$values['speaker'] = SerializerRegistry::getInstance()->getSerializer($speaker)->serialize
|
||||
(
|
||||
AbstractSerializer::filterExpandByPrefix($expand, $relation),[],['none']
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -146,7 +150,9 @@ final class OwnMemberSerializer extends AbstractMemberSerializer
|
||||
if(is_null($summit)) break;
|
||||
$feedback = array();
|
||||
foreach ($member->getFeedbackBySummit($summit) as $f) {
|
||||
$feedback[] = SerializerRegistry::getInstance()->getSerializer($f)->serialize();
|
||||
$feedback[] = SerializerRegistry::getInstance()->getSerializer($f)->serialize(
|
||||
AbstractSerializer::filterExpandByPrefix($expand, $relation)
|
||||
);
|
||||
}
|
||||
$values['feedback'] = $feedback;
|
||||
}
|
||||
@ -158,7 +164,7 @@ final class OwnMemberSerializer extends AbstractMemberSerializer
|
||||
foreach ($member->getFavoritesSummitEventsBySummit($summit) as $events){
|
||||
$favorites[] = SerializerRegistry::getInstance()
|
||||
->getSerializer($events)
|
||||
->serialize($expand);
|
||||
->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
$values['favorite_summit_events'] = $favorites;
|
||||
}
|
||||
@ -169,7 +175,7 @@ final class OwnMemberSerializer extends AbstractMemberSerializer
|
||||
foreach ($member->getScheduleBySummit($summit) as $events){
|
||||
$schedule[] = SerializerRegistry::getInstance()
|
||||
->getSerializer($events)
|
||||
->serialize($expand);
|
||||
->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
$values['schedule_summit_events'] = $schedule;
|
||||
}
|
||||
@ -181,7 +187,7 @@ final class OwnMemberSerializer extends AbstractMemberSerializer
|
||||
foreach ($member->getRsvpBySummit($summit) as $rsvp){
|
||||
$rsvps[] = SerializerRegistry::getInstance()
|
||||
->getSerializer($rsvp)
|
||||
->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
$values['rsvp'] = $rsvps;
|
||||
}
|
||||
|
@ -55,13 +55,13 @@ class PushNotificationMessageSerializer extends SilverStripeSerializer
|
||||
case 'owner': {
|
||||
if(!$notification->hasOwner()) continue;
|
||||
unset($values['owner_id']);
|
||||
$values['owner'] = SerializerRegistry::getInstance()->getSerializer($notification->getOwner())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
$values['owner'] = SerializerRegistry::getInstance()->getSerializer($notification->getOwner())->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
break;
|
||||
case 'approved_by': {
|
||||
if(!$notification->hasApprovedBy()) continue;
|
||||
unset($values['approved_by_id']);
|
||||
$values['approved_by'] = SerializerRegistry::getInstance()->getSerializer($notification->getApprovedBy())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
$values['approved_by'] = SerializerRegistry::getInstance()->getSerializer($notification->getApprovedBy())->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -45,12 +45,12 @@ class RSVPAnswerSerializer extends SilverStripeSerializer
|
||||
switch ($relation) {
|
||||
case 'rsvp': {
|
||||
unset($values['rsvp_id']);
|
||||
$values['rsvp_id'] = SerializerRegistry::getInstance()->getSerializer($answer->getRsvp())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
$values['rsvp_id'] = SerializerRegistry::getInstance()->getSerializer($answer->getRsvp())->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
break;
|
||||
case 'question': {
|
||||
unset($values['question_id']);
|
||||
$values['question'] = SerializerRegistry::getInstance()->getSerializer($answer->getQuestion())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
$values['question'] = SerializerRegistry::getInstance()->getSerializer($answer->getQuestion())->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -45,30 +45,29 @@ final class RSVPSerializer extends SilverStripeSerializer
|
||||
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));
|
||||
$values['owner'] = SerializerRegistry::getInstance()->getSerializer($rsvp->getOwner())->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
break;
|
||||
case 'event': {
|
||||
if(!$rsvp->hasEvent()) continue;
|
||||
unset($values['event_id']);
|
||||
$values['event'] = SerializerRegistry::getInstance()->getSerializer($rsvp->getEvent())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
$values['event'] = SerializerRegistry::getInstance()->getSerializer($rsvp->getEvent())->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'answers':{
|
||||
$answers = [];
|
||||
foreach ($rsvp->getAnswers() as $answer){
|
||||
$answers[] = SerializerRegistry::getInstance()->getSerializer($answer)->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
$answers[] = SerializerRegistry::getInstance()->getSerializer($answer)->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
$values['answers'] = $answers;
|
||||
}
|
||||
|
@ -65,20 +65,20 @@ final class SummitPushNotificationSerializer extends PushNotificationMessageSeri
|
||||
case 'event': {
|
||||
if($notification->getChannel() != SummitPushNotificationChannel::Event) continue;
|
||||
unset($values['event_id']);
|
||||
$values['event'] = SerializerRegistry::getInstance()->getSerializer($notification->getSummitEvent())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
$values['event'] = SerializerRegistry::getInstance()->getSerializer($notification->getSummitEvent())->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
break;
|
||||
case 'group': {
|
||||
if($notification->getChannel() != SummitPushNotificationChannel::Group) continue;
|
||||
unset($values['group_id']);
|
||||
$values['group'] = SerializerRegistry::getInstance()->getSerializer($notification->getGroup())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
$values['group'] = SerializerRegistry::getInstance()->getSerializer($notification->getGroup())->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
break;
|
||||
case 'recipients': {
|
||||
if($notification->getChannel() != SummitPushNotificationChannel::Members) continue;
|
||||
$values['recipients'] = [];
|
||||
foreach ($notification->getRecipients() as $recipient)
|
||||
$values['recipients'][] = SerializerRegistry::getInstance()->getSerializer($recipient)->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
$values['recipients'][] = SerializerRegistry::getInstance()->getSerializer($recipient)->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user