
'schedule_default_page_url' => 'nullable|string', 'schedule_default_event_detail_url' => 'nullable|string', 'schedule_og_site_name' => 'nullable|string', 'schedule_og_image_url' => 'nullable|string', 'schedule_og_image_secure_url' => 'nullable|string', 'schedule_og_image_width' => 'nullable|integer', 'schedule_og_image_height' => 'nullable|integer', 'schedule_facebook_app_id' => 'nullable|string', 'schedule_ios_app_name' => 'nullable|string', 'schedule_ios_app_store_id' => 'nullable|string', 'schedule_ios_app_custom_schema' => 'nullable|string', 'schedule_android_app_name' => 'nullable|string', 'schedule_android_app_package' => 'nullable|string', 'schedule_android_custom_schema' => 'nullable|string', 'schedule_twitter_app_name' => 'nullable|string', 'schedule_twitter_text' => 'nullable|string', Change-Id: I4d539031b2acd8b59bd46da7640a8f9ef25911c2
304 lines
17 KiB
PHP
304 lines
17 KiB
PHP
<?php namespace ModelSerializers;
|
|
/**
|
|
* Copyright 2016 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 App\Http\Exceptions\HTTP403ForbiddenException;
|
|
use App\Security\SummitScopes;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Libs\ModelSerializers\AbstractSerializer;
|
|
use models\summit\Summit;
|
|
use DateTime;
|
|
/**
|
|
* Class SummitSerializer
|
|
* @package ModelSerializers
|
|
*/
|
|
class SummitSerializer extends SilverStripeSerializer
|
|
{
|
|
protected static $array_mappings = [
|
|
'Name' => 'name:json_string',
|
|
'BeginDate' => 'start_date:datetime_epoch',
|
|
'EndDate' => 'end_date:datetime_epoch',
|
|
'RegistrationBeginDate' => 'registration_begin_date:datetime_epoch',
|
|
'RegistrationEndDate' => 'registration_end_date:datetime_epoch',
|
|
'StartShowingVenuesDate' => 'start_showing_venues_date:datetime_epoch',
|
|
'ScheduleDefaultStartDate' => 'schedule_start_date:datetime_epoch',
|
|
'Active' => 'active:json_boolean',
|
|
'TypeId' => 'type_id:json_int' ,
|
|
'DatesLabel' => 'dates_label:json_string' ,
|
|
'MaxSubmissionAllowedPerUser' => 'max_submission_allowed_per_user:json_int',
|
|
// calculated attributes
|
|
'PresentationVotesCount' => 'presentation_votes_count:json_int' ,
|
|
'PresentationVotersCount' => 'presentation_voters_count:json_int' ,
|
|
'AttendeesCount' => 'attendees_count:json_int',
|
|
'SpeakersCount' => 'speakers_count:json_int',
|
|
'PresentationsSubmittedCount' => 'presentations_submitted_count:json_int',
|
|
'PublishedEventsCount' => 'published_events_count:json_int',
|
|
'SpeakerAnnouncementEmailAcceptedCount' => 'speaker_announcement_email_accepted_count:json_int',
|
|
'SpeakerAnnouncementEmailRejectedCount' => 'speaker_announcement_email_rejected_count:json_int',
|
|
'SpeakerAnnouncementEmailAlternateCount' => 'speaker_announcement_email_alternate_count:json_int',
|
|
'SpeakerAnnouncementEmailAcceptedAlternateCount' => 'speaker_announcement_email_accepted_alternate_count:json_int',
|
|
'SpeakerAnnouncementEmailAcceptedRejectedCount' => 'speaker_announcement_email_accepted_rejected_count:json_int',
|
|
'SpeakerAnnouncementEmailAlternateRejectedCount' => 'speaker_announcement_email_alternate_rejected_count:json_int',
|
|
'TimeZoneId' => 'time_zone_id:json_string',
|
|
'SecondaryRegistrationLink' => 'secondary_registration_link:json_string',
|
|
'SecondaryRegistrationLabel' => 'secondary_registration_label:json_string',
|
|
'RawSlug' => 'slug:json_string',
|
|
// Bookable rooms attributes
|
|
'MeetingRoomBookingStartTime' => 'meeting_room_booking_start_time:datetime_epoch',
|
|
'MeetingRoomBookingEndTime' => 'meeting_room_booking_end_time:datetime_epoch',
|
|
'MeetingRoomBookingSlotLength' => 'meeting_room_booking_slot_length:json_int',
|
|
'MeetingRoomBookingMaxAllowed' => 'meeting_room_booking_max_allowed:json_int',
|
|
'BeginAllowBookingDate' => 'begin_allow_booking_date:datetime_epoch',
|
|
'EndAllowBookingDate' => 'end_allow_booking_date:datetime_epoch',
|
|
'LogoUrl' => 'logo:json_url',
|
|
// schedule app
|
|
'ScheduleDefaultPageUrl' => 'schedule_default_page_url:json_url',
|
|
'ScheduleDefaultEventDetailUrl' => 'schedule_default_event_detail_url:json_url',
|
|
'ScheduleOgSiteName' => 'schedule_og_site_name:json_string',
|
|
'ScheduleOgImageUrl' => 'schedule_og_image_url:json_string',
|
|
'ScheduleOgImageSecureUrl' => 'schedule_og_image_secure_url:json_string',
|
|
'ScheduleOgImageWidth' => 'schedule_og_image_width:json_int',
|
|
'ScheduleOgImageHeight' => 'schedule_og_image_height:json_int',
|
|
'ScheduleFacebookAppId' => 'schedule_facebook_app_id:json_string',
|
|
'ScheduleIosAppName' => 'schedule_ios_app_name:json_string',
|
|
'ScheduleIosAppStoreId' => 'schedule_ios_app_store_id:json_string',
|
|
'ScheduleIosAppCustomSchema' => 'schedule_ios_app_custom_schema:json_string',
|
|
'ScheduleAndroidAppName' => 'schedule_android_app_name:json_string',
|
|
'ScheduleAndroidAppPackage' => 'schedule_android_app_package:json_string',
|
|
'ScheduleAndroidCustomSchema' => 'schedule_android_custom_schema:json_string',
|
|
'ScheduleTwitterAppName' => 'schedule_twitter_app_name:json_string',
|
|
'ScheduleTwitterText' => 'schedule_twitter_text:json_string',
|
|
];
|
|
|
|
protected static $allowed_relations = [
|
|
'ticket_types',
|
|
'locations',
|
|
'wifi_connections',
|
|
'selection_plans',
|
|
'meeting_booking_room_allowed_attributes',
|
|
];
|
|
|
|
/**
|
|
* @param null $expand
|
|
* @param array $fields
|
|
* @param array $relations
|
|
* @param array $params
|
|
* @return array
|
|
* @throws HTTP403ForbiddenException
|
|
*/
|
|
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = [])
|
|
{
|
|
$summit = $this->object;
|
|
if(!$summit instanceof Summit) return [];
|
|
$values = parent::serialize($expand, $fields, $relations, $params);
|
|
if(!count($relations)) $relations = $this->getAllowedRelations();
|
|
|
|
$timezone = $summit->getTimeZone();
|
|
$values['time_zone'] = null;
|
|
|
|
if (!is_null($timezone)) {
|
|
$time_zone_info = $timezone->getLocation();
|
|
$time_zone_info['name'] = $timezone->getName();
|
|
$now = new DateTime($summit->getLocalBeginDate()->format('Y-m-d H:i:s'), $timezone);
|
|
$time_zone_info['offset'] = $timezone->getOffset($now);
|
|
$values['time_zone'] = $time_zone_info;
|
|
}
|
|
// pages info
|
|
$main_page = $summit->getMainPage();
|
|
$schedule_page = $summit->getSchedulePage();
|
|
$values['page_url'] =
|
|
empty($main_page)? null :
|
|
sprintf("%s%s", Config::get("server.assets_base_url", 'https://www.openstack.org/'), $main_page);
|
|
$values['schedule_page_url'] = empty($schedule_page) ? null :
|
|
sprintf("%s%s", Config::get("server.assets_base_url", 'https://www.openstack.org/'), $schedule_page);
|
|
$values['schedule_event_detail_url'] = empty($schedule_page) ? null : sprintf("%s%s/%s", Config::get("server.assets_base_url", 'https://www.openstack.org/'), $schedule_page, 'events/:event_id/:event_title');
|
|
|
|
// tickets
|
|
if(in_array('ticket_types', $relations)) {
|
|
$ticket_types = [];
|
|
foreach ($summit->getTicketTypes() as $ticket) {
|
|
$ticket_types[] = SerializerRegistry::getInstance()->getSerializer($ticket)->serialize(AbstractSerializer::filterExpandByPrefix($expand, 'ticket_types'));
|
|
}
|
|
$values['ticket_types'] = $ticket_types;
|
|
}
|
|
|
|
// meeting_booking_room_allowed_attributes
|
|
if(in_array('meeting_booking_room_allowed_attributes', $relations)) {
|
|
$meeting_booking_room_allowed_attributes = [];
|
|
foreach ($summit->getMeetingBookingRoomAllowedAttributes() as $attr) {
|
|
$meeting_booking_room_allowed_attributes[] = SerializerRegistry::getInstance()->getSerializer($attr)->serialize($expand);
|
|
}
|
|
$values['meeting_booking_room_allowed_attributes'] = $meeting_booking_room_allowed_attributes;
|
|
}
|
|
|
|
// locations
|
|
if(in_array('locations', $relations)) {
|
|
$locations = [];
|
|
foreach ($summit->getLocations() as $location) {
|
|
$locations[] = SerializerRegistry::getInstance()->getSerializer($location)->serialize(
|
|
// is user is already expanding by schedule, its the total expand of the venues
|
|
str_contains('schedule', $expand)?
|
|
'floors,rooms':
|
|
AbstractSerializer::filterExpandByPrefix($expand, 'locations')
|
|
);
|
|
}
|
|
$values['locations'] = $locations;
|
|
}
|
|
|
|
// wifi connections
|
|
if(in_array('wifi_connections', $relations)) {
|
|
$wifi_connections = [];
|
|
foreach ($summit->getWifiConnections() as $wifi_connection) {
|
|
$wifi_connections[] = SerializerRegistry::getInstance()->getSerializer($wifi_connection)->serialize(AbstractSerializer::filterExpandByPrefix($expand, 'wifi_connections'));
|
|
}
|
|
$values['wifi_connections'] = $wifi_connections;
|
|
}
|
|
|
|
// selection plans
|
|
if(in_array('selection_plans', $relations)) {
|
|
$selection_plans = [];
|
|
foreach ($summit->getSelectionPlans() as $selection_plan) {
|
|
$selection_plans[] = SerializerRegistry::getInstance()->getSerializer($selection_plan)->serialize(AbstractSerializer::filterExpandByPrefix($expand, 'selection_plans'));
|
|
}
|
|
$values['selection_plans'] = $selection_plans;
|
|
}
|
|
|
|
if (!empty($expand)) {
|
|
|
|
foreach (explode(',', $expand) as $relation) {
|
|
$relation = trim($relation);
|
|
switch ($relation) {
|
|
case 'event_types':{
|
|
$event_types = [];
|
|
foreach ($summit->getEventTypes() as $event_type) {
|
|
$event_types[] = SerializerRegistry::getInstance()->getSerializer($event_type)->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
|
}
|
|
$values['event_types'] = $event_types;
|
|
}
|
|
break;
|
|
case 'tracks':{
|
|
$presentation_categories = [];
|
|
foreach ($summit->getPresentationCategories() as $cat) {
|
|
$presentation_categories[] = SerializerRegistry::getInstance()->getSerializer($cat)->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
|
}
|
|
$values['tracks'] = $presentation_categories;
|
|
}
|
|
break;
|
|
case 'track_groups':{
|
|
// track_groups
|
|
$track_groups = [];
|
|
foreach ($summit->getCategoryGroups() as $group) {
|
|
$track_groups[] = SerializerRegistry::getInstance()->getSerializer($group)->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
|
}
|
|
$values['track_groups'] = $track_groups;
|
|
}
|
|
break;
|
|
case 'sponsors':{
|
|
$sponsors = [];
|
|
foreach ($summit->getSponsors() as $company) {
|
|
$sponsors[] = SerializerRegistry::getInstance()->getSerializer($company)->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
|
|
}
|
|
$values['sponsors'] = $sponsors;
|
|
}
|
|
break;
|
|
case 'speakers':{
|
|
$speakers = [];
|
|
foreach ($summit->getSpeakers() as $speaker) {
|
|
$speakers[] =
|
|
SerializerRegistry::getInstance()->getSerializer($speaker)->serialize
|
|
(
|
|
AbstractSerializer::filterExpandByPrefix($expand, $relation), [], [],
|
|
[
|
|
'summit_id' => $summit->getId(),
|
|
'published' => true
|
|
]
|
|
);
|
|
|
|
}
|
|
$values['speakers'] = $speakers;
|
|
}
|
|
break;
|
|
case 'schedule': {
|
|
// only could get schedule expanded if summit its available to public or
|
|
// we had proper scopes
|
|
if(!$summit->isAvailableOnApi()) {
|
|
$scopes = $this->resource_server_context->getCurrentScope();
|
|
$current_realm = Config::get('app.url');
|
|
$needed_scope = sprintf(SummitScopes::ReadAllSummitData, $current_realm);
|
|
if (!in_array($needed_scope, $scopes))
|
|
throw new HTTP403ForbiddenException;
|
|
}
|
|
|
|
$event_types = [];
|
|
foreach ($summit->getEventTypes() as $event_type) {
|
|
$event_types[] = SerializerRegistry::getInstance()->getSerializer($event_type)->serialize();
|
|
}
|
|
$values['event_types'] = $event_types;
|
|
|
|
$presentation_categories = [];
|
|
foreach ($summit->getPresentationCategories() as $cat) {
|
|
$presentation_categories[] = SerializerRegistry::getInstance()->getSerializer($cat)->serialize();
|
|
}
|
|
$values['tracks'] = $presentation_categories;
|
|
|
|
// track_groups
|
|
$track_groups = [];
|
|
foreach ($summit->getCategoryGroups() as $group) {
|
|
$track_groups[] = SerializerRegistry::getInstance()->getSerializer($group)->serialize();
|
|
}
|
|
$values['track_groups'] = $track_groups;
|
|
|
|
$schedule = [];
|
|
foreach ($summit->getScheduleEvents() as $event) {
|
|
$schedule[] = SerializerRegistry::getInstance()->getSerializer($event)->serialize();
|
|
}
|
|
$values['schedule'] = $schedule;
|
|
|
|
$sponsors = [];
|
|
foreach ($summit->getSponsors() as $company) {
|
|
$sponsors[] = SerializerRegistry::getInstance()->getSerializer($company)->serialize();
|
|
}
|
|
$values['sponsors'] = $sponsors;
|
|
|
|
$speakers = [];
|
|
foreach ($summit->getSpeakers() as $speaker) {
|
|
$speakers[] =
|
|
SerializerRegistry::getInstance()->getSerializer($speaker)->serialize
|
|
(
|
|
null, [], [],
|
|
[
|
|
'summit_id' => $summit->getId(),
|
|
'published' => true
|
|
]
|
|
);
|
|
|
|
}
|
|
$values['speakers'] = $speakers;
|
|
}
|
|
break;
|
|
case 'type':{
|
|
if(isset($values['type_id']))
|
|
{
|
|
unset($values['type_id']);
|
|
$values['type'] = $summit->hasType() ?
|
|
SerializerRegistry::getInstance()->getSerializer($summit->getType())->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation)) : null;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
$values['timestamp'] = time();
|
|
return $values;
|
|
}
|
|
} |