
GET /api/v1/summits/{id}/promo-codes/csv expand: new values owner_name,owner_email,sponsor_name columns: new param posible values $allowed_columns = [ "id", "created", "last_edited", "code", "redeemed", "email_sent", "source", "summit_id", "creator_id", "class_name", "type", "speaker_id", "owner_name", "owner_email", "sponsor_name" ]; Change-Id: Ie51041077b277eb73f97df09c817573692aee043
71 lines
2.5 KiB
PHP
71 lines
2.5 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 models\summit\SponsorSummitRegistrationPromoCode;
|
|
|
|
/**
|
|
* Class SponsorSummitRegistrationPromoCodeSerializer
|
|
* @package ModelSerializers
|
|
*/
|
|
final class SponsorSummitRegistrationPromoCodeSerializer
|
|
extends MemberSummitRegistrationPromoCodeSerializer
|
|
{
|
|
protected static $array_mappings = [
|
|
'SponsorId' => 'sponsor_id:json_int',
|
|
];
|
|
|
|
/**
|
|
* @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 = [] )
|
|
{
|
|
if(!count($relations)) $relations = $this->getAllowedRelations();
|
|
|
|
$code = $this->object;
|
|
if(!$code instanceof SponsorSummitRegistrationPromoCode) return [];
|
|
$values = parent::serialize($expand, $fields, $relations, $params);
|
|
$serializer_type = SerializerRegistry::SerializerType_Public;
|
|
|
|
if(isset($params['serializer_type']))
|
|
$serializer_type = $params['serializer_type'];
|
|
|
|
if (!empty($expand)) {
|
|
foreach (explode(',', $expand) as $relation) {
|
|
switch (trim($relation)) {
|
|
case 'sponsor': {
|
|
if($code->hasSponsor()){
|
|
unset($values['sponsor_id']);
|
|
$values['sponsor'] = SerializerRegistry::getInstance()->getSerializer
|
|
(
|
|
$code->getSponsor(),
|
|
$serializer_type
|
|
)->serialize($expand);
|
|
}
|
|
}
|
|
break;
|
|
case 'sponsor_name':{
|
|
$values['sponsor_name'] = $code->getSponsor()->getName();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $values;
|
|
}
|
|
} |