Added SummitEventWithFile

added a new event type that allows an attachment
(lunch and breacks)

Change-Id: I2f592b0ec52a3938f6c80a2266c7601f9c3cae76
This commit is contained in:
Sebastian Marcet 2017-02-03 12:36:43 -03:00
parent 261c71f361
commit e79867846d
5 changed files with 109 additions and 1 deletions

View File

@ -76,6 +76,7 @@ final class SerializerRegistry
$this->registry['SummitAttendee'] = SummitAttendeeSerializer::class;
$this->registry['SummitAttendeeSchedule'] = SummitAttendeeScheduleSerializer::class;
$this->registry['SummitEntityEvent'] = SummitEntityEventSerializer::class;
$this->registry['SummitEventWithFile'] = SummitEventWithFileSerializer::class;
// locations
$this->registry['SummitVenue'] = SummitVenueSerializer::class;

View File

@ -0,0 +1,38 @@
<?php namespace ModelSerializers;
/**
* Copyright 2017 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 Illuminate\Support\Facades\Config;
use models\summit\SummitEventWithFile;
/**
* Class SummitEventWithFileSerializer
* @package ModelSerializers
*/
final class SummitEventWithFileSerializer extends SummitEventSerializer
{
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array())
{
$event = $this->object;
if (!$event instanceof SummitEventWithFile) return [];
$values = parent::serialize($expand, $fields, $relations, $params);
$values['attachment'] = $event->hasAttachment()? Config::get("server.assets_base_url", 'https://www.openstack.org/') . $event->getAttachment()->getFilename() : null;
return $values;
}
}

View File

@ -52,6 +52,7 @@ final class EntityEventTypeFactory
{
case 'Presentation':
case 'SummitEvent':
case 'SummitEventWithFile':
{
if ($e->getType() === 'UPDATE' || $e->getType() === "INSERT")
return new SummitEventEntityEventInsertOrUpdateType($e, $ctx);

View File

@ -34,7 +34,7 @@ use Cocur\Slugify\Slugify;
* @ORM\Table(name="SummitEvent")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="ClassName", type="string")
* @ORM\DiscriminatorMap({"SummitEvent" = "SummitEvent", "Presentation" = "Presentation", "SummitGroupEvent" = "SummitGroupEvent"})
* @ORM\DiscriminatorMap({"SummitEvent" = "SummitEvent", "Presentation" = "Presentation", "SummitGroupEvent" = "SummitGroupEvent", "SummitEventWithFile" = "SummitEventWithFile"})
* @ORM\Entity(repositoryClass="repositories\summit\DoctrineSummitEventRepository")
* @ORM\HasLifecycleCallbacks
* Class SummitEvent

View File

@ -0,0 +1,68 @@
<?php namespace models\summit;
/**
* Copyright 2017 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 Doctrine\ORM\Mapping AS ORM;
use models\main\File;
/**
* Class SummitEventWithFile
* @ORM\Entity
* @ORM\Table(name="SummitEventWithFile")
* @package models\summit
*/
class SummitEventWithFile extends SummitEvent
{
/**
* @ORM\ManyToOne(targetEntity="models\main\File")
* @ORM\JoinColumn(name="AttachmentID", referencedColumnName="ID")
* @var File
*/
private $attachment;
/**
* @return File
*/
public function getAttachment()
{
return $this->attachment;
}
/**
* @param File $attachment
*/
public function setAttachment($attachment)
{
$this->attachment = $attachment;
}
/**
* @return bool
*/
public function hasAttachment(){
return $this->getAttachmentId() > 0;
}
/**
* @return int
*/
public function getAttachmentId(){
try{
return !is_null($this->attachment)?$this->attachment->getId():0;
}
catch(\Exception $ex){
return 0;
}
}
}