Fixed postEvent and publishEvent
Endpoints Change-Id: I9d9d5ddc9720cf46f94de9a5bcd20abd376bd660
This commit is contained in:
parent
c1bf7f11c8
commit
ddc0a955e2
@ -108,7 +108,7 @@ final class OAuth2SummitApiController extends OAuth2ProtectedController
|
||||
$summits = [];
|
||||
|
||||
foreach($this->repository->getAllOrderedByBeginDate() as $summit){
|
||||
$summits[] = SerializerRegistry::getInstance()->getSerializer($summit)->serialize();
|
||||
$summits[] = SerializerRegistry::getInstance()->getSerializer($summit)->serialize(Input::get('expand',''));
|
||||
}
|
||||
|
||||
$response = new PagingResponse
|
||||
|
46
app/ModelSerializers/PresentationTypeSerializer.php
Normal file
46
app/ModelSerializers/PresentationTypeSerializer.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?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.
|
||||
**/
|
||||
|
||||
/**
|
||||
* Class PresentationEventTypeSerializer
|
||||
* @package ModelSerializers
|
||||
*/
|
||||
class PresentationTypeSerializer extends SummitEventTypeSerializer
|
||||
{
|
||||
protected static $array_mappings = array
|
||||
(
|
||||
'MaxSpeakers' => 'max_speakers:json_int',
|
||||
'MinSpeakers' => 'min_speakers:json_int',
|
||||
'MaxModerators' => 'max_moderators:json_int',
|
||||
'MinModerators' => 'min_moderators:json_int',
|
||||
'UseSpeakers' => 'use_speakers:json_boolean',
|
||||
'AreSpeakersMandatory' => 'are_speakers_mandatory:json_boolean',
|
||||
'UseModerator' => 'use_moderator:json_boolean',
|
||||
'ModeratorMandatory' => 'moderator_mandatory:json_boolean',
|
||||
'ModeratorLabel' => 'moderator_label:json_string',
|
||||
);
|
||||
|
||||
/**
|
||||
* @param null $expand
|
||||
* @param array $fields
|
||||
* @param array $relations
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array() )
|
||||
{
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
return $values;
|
||||
}
|
||||
}
|
@ -81,6 +81,7 @@ final class SerializerRegistry
|
||||
$this->registry['SummitWIFIConnection'] = SummitWIFIConnectionSerializer::class;
|
||||
$this->registry['SummitType'] = SummitTypeSerializer::class;
|
||||
$this->registry['SummitEventType'] = SummitEventTypeSerializer::class;
|
||||
$this->registry['PresentationType'] = PresentationTypeSerializer::class;
|
||||
$this->registry['SummitTicketType'] = SummitTicketTypeSerializer::class;
|
||||
$this->registry['PresentationCategory'] = PresentationCategorySerializer::class;
|
||||
$this->registry['PresentationCategoryGroup'] = PresentationCategoryGroupSerializer::class;
|
||||
|
@ -16,14 +16,17 @@
|
||||
* Class SummitEventTypeSerializer
|
||||
* @package ModelSerializers
|
||||
*/
|
||||
final class SummitEventTypeSerializer extends SilverStripeSerializer
|
||||
class SummitEventTypeSerializer extends SilverStripeSerializer
|
||||
{
|
||||
protected static $array_mappings = array
|
||||
(
|
||||
'Type' => 'name:json_string',
|
||||
'Color' => 'color:json_string',
|
||||
'BlackoutTimes' => 'black_out_times:json_boolean',
|
||||
);
|
||||
protected static $array_mappings = [
|
||||
'Type' => 'name:json_string',
|
||||
'ClassName' => 'class_name:json_string',
|
||||
'Color' => 'color:json_string',
|
||||
'BlackoutTimes' => 'black_out_times:json_boolean',
|
||||
'UseSponsors' => 'use_sponsors:json_boolean',
|
||||
'AreSponsorsMandatory' => 'are_sponsors_mandatory:json_boolean',
|
||||
'AllowsAttachment' => 'allows_attachment:json_boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param null $expand
|
||||
|
@ -119,6 +119,56 @@ final class SummitSerializer extends SilverStripeSerializer
|
||||
$expand = explode(',', $expand);
|
||||
foreach ($expand as $relation) {
|
||||
switch (trim($relation)) {
|
||||
case 'event_types':{
|
||||
$event_types = [];
|
||||
foreach ($summit->getEventTypes() as $event_type) {
|
||||
$event_types[] = SerializerRegistry::getInstance()->getSerializer($event_type)->serialize();
|
||||
}
|
||||
$values['event_types'] = $event_types;
|
||||
}
|
||||
break;
|
||||
case 'tracks':{
|
||||
$presentation_categories = array();
|
||||
foreach ($summit->getPresentationCategories() as $cat) {
|
||||
$presentation_categories[] = SerializerRegistry::getInstance()->getSerializer($cat)->serialize();
|
||||
}
|
||||
$values['tracks'] = $presentation_categories;
|
||||
}
|
||||
break;
|
||||
case 'track_groups':{
|
||||
// track_groups
|
||||
$track_groups = array();
|
||||
foreach ($summit->getCategoryGroups() as $group) {
|
||||
$track_groups[] = SerializerRegistry::getInstance()->getSerializer($group)->serialize();
|
||||
}
|
||||
$values['track_groups'] = $track_groups;
|
||||
}
|
||||
break;
|
||||
case 'sponsors':{
|
||||
$sponsors = array();
|
||||
foreach ($summit->getSponsors() as $company) {
|
||||
$sponsors[] = SerializerRegistry::getInstance()->getSerializer($company)->serialize();
|
||||
}
|
||||
$values['sponsors'] = $sponsors;
|
||||
}
|
||||
break;
|
||||
case 'speakers':{
|
||||
$speakers = array();
|
||||
foreach ($summit->getSpeakers() as $speaker) {
|
||||
$speakers[] =
|
||||
SerializerRegistry::getInstance()->getSerializer($speaker)->serialize
|
||||
(
|
||||
null, [], [],
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'published' => true
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
$values['speakers'] = $speakers;
|
||||
}
|
||||
break;
|
||||
case 'schedule': {
|
||||
$event_types = array();
|
||||
foreach ($summit->getEventTypes() as $event_type) {
|
||||
|
@ -27,4 +27,8 @@ interface ISummitEventType
|
||||
const EveningEvents = 'Evening Events';
|
||||
|
||||
const GroupsEvents = 'Groups Events';
|
||||
|
||||
const Lunch = 'Lunch';
|
||||
|
||||
const Breaks = 'Breaks';
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?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.
|
||||
**/
|
||||
|
||||
interface IPresentationType
|
||||
{
|
||||
const Presentation = 'Presentation';
|
||||
const Keynotes = 'Keynotes';
|
||||
const Panel = 'Panel';
|
||||
const LightingTalks = 'Lightning Talks';
|
||||
const Fishbowl = 'Fishbowl';
|
||||
}
|
@ -0,0 +1,202 @@
|
||||
<?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 models\summit\SummitEventType;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
/**
|
||||
* Class PresentationType
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="PresentationType")
|
||||
* @package models\summit
|
||||
*/
|
||||
class PresentationType extends SummitEventType
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="MaxSpeakers", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
protected $max_speakers;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="MinSpeakers", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
protected $min_speakers;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="MaxModerators", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
protected $max_moderators;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="MinModerators", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
protected $min_moderators;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="UseSpeakers", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $use_speakers;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="AreSpeakersMandatory", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $are_speakers_mandatory;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="UseModerator", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $use_moderator;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="IsModeratorMandatory", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $is_moderator_mandatory;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="ShouldBeAvailableOnCFP", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $should_be_available_on_cfp;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="ModeratorLabel", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $moderator_label;
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsPresentationEventType(Summit $summit, $type){
|
||||
|
||||
try{
|
||||
$sql = <<<SQL
|
||||
SELECT COUNT(DISTINCT(PresentationType.ID))
|
||||
FROM PresentationType
|
||||
INNER JOIN SummitEventType ON SummitEventType.ID = PresentationType.ID
|
||||
WHERE SummitEventType.SummitID = :summit_id
|
||||
AND PresentationType.Type = :type
|
||||
SQL;
|
||||
$stmt = self::prepareRawSQLStatic($sql);
|
||||
$stmt->execute(['summit_id' => $summit->getId(), 'type' => $type]);
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||
return count($res) > 0 ;
|
||||
}
|
||||
catch (\Exception $ex){
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array()
|
||||
*/
|
||||
static public function presentationTypes(){
|
||||
return [IPresentationType::Presentation, IPresentationType::Keynotes, IPresentationType::LightingTalks, IPresentationType::Panel];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxSpeakers()
|
||||
{
|
||||
return $this->max_speakers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMinSpeakers()
|
||||
{
|
||||
return $this->min_speakers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxModerators()
|
||||
{
|
||||
return $this->max_moderators;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMinModerators()
|
||||
{
|
||||
return $this->min_moderators;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isUseSpeakers()
|
||||
{
|
||||
return $this->use_speakers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isAreSpeakersMandatory()
|
||||
{
|
||||
return $this->are_speakers_mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isUseModerator()
|
||||
{
|
||||
return $this->use_moderator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isModeratorMandatory()
|
||||
{
|
||||
return $this->is_moderator_mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isShouldBeAvailableOnCfp()
|
||||
{
|
||||
return $this->should_be_available_on_cfp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getModeratorLabel()
|
||||
{
|
||||
return $this->moderator_label;
|
||||
}
|
||||
|
||||
public function getClassName(){
|
||||
return 'PresentationType';
|
||||
}
|
||||
}
|
@ -11,15 +11,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="SummitEventType")
|
||||
* Class SummitEventType
|
||||
* @package models\summit
|
||||
* @ORM\InheritanceType("JOINED")
|
||||
* @ORM\DiscriminatorColumn(name="ClassName", type="string")
|
||||
* @ORM\DiscriminatorMap({"SummitEventType" = "SummitEventType", "PresentationType" = "PresentationType", "SummitGroupEvent" = "SummitGroupEvent", "SummitEventWithFile" = "SummitEventWithFile"})
|
||||
*/
|
||||
class SummitEventType extends SilverstripeBaseModel
|
||||
{
|
||||
@ -29,39 +29,37 @@ class SummitEventType extends SilverstripeBaseModel
|
||||
* @ORM\Column(name="Type", type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Color", type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $color;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="ClassName", type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $class_name;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isPresentationType(){
|
||||
return $this->class_name === 'PresentationType';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function allowsModerator(){
|
||||
return $this->isPresentationType() && in_array($this->type, ['Panel','Keynotes']);
|
||||
}
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="BlackoutTimes", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
private $blackout_times;
|
||||
protected $blackout_times;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="UseSponsors", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $use_sponsors;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="AreSponsorsMandatory", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $are_sponsors_mandatory;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="AllowsAttachment", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $allows_attachment;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
@ -127,4 +125,41 @@ class SummitEventType extends SilverstripeBaseModel
|
||||
return in_array($type, $private_types);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
static public function IsSummitEventType(Summit $summit, $type){
|
||||
return !PresentationType::IsPresentationEventType($summit, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isUseSponsors()
|
||||
{
|
||||
return $this->use_sponsors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isAreSponsorsMandatory()
|
||||
{
|
||||
return $this->are_sponsors_mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isAllowsAttachment()
|
||||
{
|
||||
return $this->allows_attachment;
|
||||
}
|
||||
|
||||
public function getClassName(){
|
||||
return 'SummitEventType';
|
||||
}
|
||||
|
||||
}
|
@ -21,12 +21,23 @@ namespace models\summit;
|
||||
final class SummitEventFactory
|
||||
{
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param SummitEventType $type
|
||||
* @return SummitEvent
|
||||
*/
|
||||
static public function build(SummitEventType $type)
|
||||
static public function build(Summit $summit, SummitEventType $type)
|
||||
{
|
||||
$event = in_array($type->getType(),[ 'Presentation', 'Keynotes' , 'Panel']) ? new Presentation: new SummitEvent;
|
||||
$event = new SummitEvent();
|
||||
|
||||
if(PresentationType::IsPresentationEventType($summit, $type->getType()))
|
||||
$event = new Presentation();
|
||||
|
||||
if(SummitEventType::isPrivate($type->getType()))
|
||||
$event = new SummitGroupEvent();
|
||||
|
||||
if($type->isAllowsAttachment())
|
||||
$event = new SummitEventWithFile();
|
||||
|
||||
return $event;
|
||||
}
|
||||
}
|
@ -125,6 +125,14 @@ class SilverstripeBaseModel extends BaseEntity
|
||||
return Registry::getManager(self::EntityManager)->getConnection()->prepare($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sql
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function prepareRawSQLStatic($sql){
|
||||
return Registry::getManager(self::EntityManager)->getConnection()->prepare($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EntityManager
|
||||
*/
|
||||
|
@ -41,6 +41,8 @@ use models\summit\ISummitAttendeeRepository;
|
||||
use models\summit\ISummitAttendeeTicketRepository;
|
||||
use models\summit\ISummitEntityEventRepository;
|
||||
use models\summit\ISummitEventRepository;
|
||||
use models\summit\Presentation;
|
||||
use models\summit\PresentationType;
|
||||
use models\summit\Summit;
|
||||
use models\summit\SummitAttendee;
|
||||
use models\summit\SummitAttendeeTicket;
|
||||
@ -63,7 +65,7 @@ final class SummitService implements ISummitService
|
||||
/**
|
||||
* minimun number of minutes that an event must last
|
||||
*/
|
||||
const MIN_EVENT_MINUTES = 15;
|
||||
const MIN_EVENT_MINUTES = 10;
|
||||
/**
|
||||
* @var ITransactionService
|
||||
*/
|
||||
@ -485,6 +487,59 @@ final class SummitService implements ISummitService
|
||||
return $this->saveOrUpdateEvent($summit, $data, $event_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param Summit $summit
|
||||
* @param SummitEvent $event
|
||||
* @return SummitEvent
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function updateEventDates(array $data, Summit $summit, SummitEvent $event){
|
||||
|
||||
if (isset($data['start_date']) && isset($data['end_date'])) {
|
||||
$event->setSummit($summit);
|
||||
$summit_time_zone = $summit->getTimeZone();
|
||||
$start_datetime = intval($data['start_date']);
|
||||
$start_datetime = new \DateTime("@$start_datetime", $summit_time_zone);
|
||||
|
||||
$end_datetime = intval($data['end_date']);
|
||||
$end_datetime = new \DateTime("@$end_datetime", $summit_time_zone);
|
||||
|
||||
$interval_seconds = $end_datetime->getTimestamp() - $start_datetime->getTimestamp();
|
||||
$minutes = $interval_seconds / 60;
|
||||
if ($minutes < self::MIN_EVENT_MINUTES)
|
||||
throw new ValidationException
|
||||
(
|
||||
sprintf
|
||||
(
|
||||
"event should last at lest %s minutes - current duration %s",
|
||||
self::MIN_EVENT_MINUTES,
|
||||
$minutes
|
||||
)
|
||||
);
|
||||
|
||||
// set local time from UTC
|
||||
$event->setStartDate($start_datetime);
|
||||
$event->setEndDate($end_datetime);
|
||||
|
||||
if (!$summit->isEventInsideSummitDuration($event))
|
||||
throw new ValidationException
|
||||
(
|
||||
sprintf
|
||||
(
|
||||
"event start/end (%s - %s) does not match with summit start/end (%s - %s)",
|
||||
$start_datetime->format('Y-m-d H:i:s'),
|
||||
$end_datetime->format('Y-m-d H:i:s'),
|
||||
$summit->getLocalBeginDate()->format('Y-m-d H:i:s'),
|
||||
$summit->getLocalEndDate()->format('Y-m-d H:i:s')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $event;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
@ -493,35 +548,11 @@ final class SummitService implements ISummitService
|
||||
*/
|
||||
private function saveOrUpdateEvent(Summit $summit, array $data, $event_id = null)
|
||||
{
|
||||
$event_repository = $this->event_repository;
|
||||
|
||||
return $this->tx_service->transaction(function () use ($summit, $data, $event_id, $event_repository) {
|
||||
|
||||
$start_datetime = null;
|
||||
$end_datetime = null;
|
||||
|
||||
if (isset($data['start_date']) && isset($data['end_date'])) {
|
||||
$start_datetime = intval($data['start_date']);
|
||||
$start_datetime = new \DateTime("@$start_datetime");
|
||||
|
||||
$end_datetime = intval($data['end_date']);
|
||||
$end_datetime = new \DateTime("@$end_datetime");
|
||||
|
||||
$interval_seconds = $end_datetime->getTimestamp() - $start_datetime->getTimestamp();
|
||||
$minutes = $interval_seconds / 60;
|
||||
if ($minutes < self::MIN_EVENT_MINUTES)
|
||||
throw new ValidationException
|
||||
(
|
||||
sprintf
|
||||
(
|
||||
"event should last at lest %s minutes - current duration %s",
|
||||
self::MIN_EVENT_MINUTES,
|
||||
$minutes
|
||||
)
|
||||
);
|
||||
}
|
||||
return $this->tx_service->transaction(function () use ($summit, $data, $event_id) {
|
||||
|
||||
$event_type = null;
|
||||
|
||||
if (isset($data['type_id'])) {
|
||||
$event_type = $summit->getEventType(intval($data['type_id']));
|
||||
if (is_null($event_type)) {
|
||||
@ -547,9 +578,9 @@ final class SummitService implements ISummitService
|
||||
}
|
||||
|
||||
if (is_null($event_id)) {
|
||||
$event = SummitEventFactory::build($event_type);
|
||||
$event = SummitEventFactory::build($summit, $event_type);
|
||||
} else {
|
||||
$event = $event_repository->getById($event_id);
|
||||
$event = $this->event_repository->getById($event_id);
|
||||
if (is_null($event))
|
||||
throw new ValidationException(sprintf("event id %s does not exists!", $event_id));
|
||||
$event_type = $event->getType();
|
||||
@ -581,7 +612,8 @@ final class SummitService implements ISummitService
|
||||
}
|
||||
|
||||
// is event is new and we dont provide speakers ...
|
||||
if(is_null($event_id) && !is_null($event_type) && $event_type->isPresentationType() && !isset($data['speakers']))
|
||||
if(is_null($event_id) && !is_null($event_type) && $event_type instanceof PresentationType
|
||||
&& $event_type->isAreSpeakersMandatory() && !isset($data['speakers']))
|
||||
throw new ValidationException('speakers data is required for presentations!');
|
||||
|
||||
$event->setSummit($summit);
|
||||
@ -589,25 +621,7 @@ final class SummitService implements ISummitService
|
||||
if (!is_null($location))
|
||||
$event->setLocation($location);
|
||||
|
||||
// check start/end datetime with summit
|
||||
if (!is_null($start_datetime) && !is_null($end_datetime)) {
|
||||
// set local time from UTC
|
||||
$event->setStartDate($start_datetime);
|
||||
$event->setEndDate($end_datetime);
|
||||
|
||||
if (!$summit->isEventInsideSummitDuration($event))
|
||||
throw new ValidationException
|
||||
(
|
||||
sprintf
|
||||
(
|
||||
"event start/end (%s - %s) does not match with summit start/end (%s - %s)",
|
||||
$start_datetime->format('Y-m-d H:i:s'),
|
||||
$end_datetime->format('Y-m-d H:i:s'),
|
||||
$summit->getLocalBeginDate()->format('Y-m-d H:i:s'),
|
||||
$summit->getLocalEndDate()->format('Y-m-d H:i:s')
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->updateEventDates($data, $summit, $event);
|
||||
|
||||
if (isset($data['tags']) && count($data['tags']) > 0) {
|
||||
$event->clearTags();
|
||||
@ -627,7 +641,8 @@ final class SummitService implements ISummitService
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($data['moderator_speaker_id']) && !is_null($event_type) && $event_type->allowsModerator()){
|
||||
if(isset($data['moderator_speaker_id']) && !is_null($event_type)
|
||||
&& $event_type instanceof PresentationType && $event instanceof Presentation){
|
||||
$speaker_id = intval($data['moderator_speaker_id']);
|
||||
if($speaker_id === 0) $event->unsetModerator();
|
||||
else
|
||||
@ -638,7 +653,7 @@ final class SummitService implements ISummitService
|
||||
}
|
||||
}
|
||||
|
||||
$event_repository->add($event);
|
||||
$this->event_repository->add($event);
|
||||
|
||||
return $event;
|
||||
});
|
||||
@ -652,11 +667,10 @@ final class SummitService implements ISummitService
|
||||
*/
|
||||
public function publishEvent(Summit $summit, $event_id, array $data)
|
||||
{
|
||||
$event_repository = $this->event_repository;
|
||||
|
||||
return $this->tx_service->transaction(function () use ($summit, $data, $event_id, $event_repository) {
|
||||
return $this->tx_service->transaction(function () use ($summit, $data, $event_id) {
|
||||
|
||||
$event = $event_repository->getById($event_id);
|
||||
$event = $this->event_repository->getById($event_id);
|
||||
|
||||
if (is_null($event))
|
||||
throw new EntityNotFoundException(sprintf("event id %s does not exists!", $event_id));
|
||||
@ -670,16 +684,11 @@ final class SummitService implements ISummitService
|
||||
if ($event->getSummit()->getIdentifier() !== $summit->getIdentifier())
|
||||
throw new ValidationException(sprintf("event %s does not belongs to summit id %s", $event_id, $summit->getIdentifier()));
|
||||
|
||||
$this->updateEventDates($data, $summit, $event);
|
||||
|
||||
$start_datetime = $event->getStartDate();
|
||||
$end_datetime = $event->getEndDate();
|
||||
|
||||
if (isset($data['start_date']) && isset($data['end_date'])) {
|
||||
$start_datetime = intval($data['start_date']);
|
||||
$start_datetime = new \DateTime("@$start_datetime");
|
||||
$end_datetime = intval($data['end_date']);
|
||||
$end_datetime = new \DateTime("@$end_datetime");
|
||||
}
|
||||
|
||||
if (is_null($start_datetime))
|
||||
throw new ValidationException(sprintf("start_date its not assigned to event id %s!", $event_id));
|
||||
|
||||
@ -690,14 +699,13 @@ final class SummitService implements ISummitService
|
||||
$location = $summit->getLocation(intval($data['location_id']));
|
||||
if (is_null($location))
|
||||
throw new EntityNotFoundException(sprintf("location id %s does not exists!", $data['location_id']));
|
||||
|
||||
$event->setLocation($location);
|
||||
}
|
||||
|
||||
$current_event_location = $event->getLocation();
|
||||
|
||||
// validate blackout times
|
||||
$conflict_events = $event_repository->getPublishedOnSameTimeFrame($event);
|
||||
$conflict_events = $this->event_repository->getPublishedOnSameTimeFrame($event);
|
||||
if (!is_null($conflict_events)) {
|
||||
foreach ($conflict_events as $c_event) {
|
||||
// if the published event is BlackoutTime or if there is a BlackoutTime event in this timeframe
|
||||
@ -748,7 +756,7 @@ final class SummitService implements ISummitService
|
||||
$event->unPublish();
|
||||
$event->publish();
|
||||
|
||||
$event_repository->add($event);
|
||||
$this->event_repository->add($event);
|
||||
return $event;
|
||||
});
|
||||
}
|
||||
@ -760,11 +768,10 @@ final class SummitService implements ISummitService
|
||||
*/
|
||||
public function unPublishEvent(Summit $summit, $event_id)
|
||||
{
|
||||
$event_repository = $this->event_repository;
|
||||
|
||||
return $this->tx_service->transaction(function () use ($summit, $event_id, $event_repository) {
|
||||
return $this->tx_service->transaction(function () use ($summit, $event_id) {
|
||||
|
||||
$event = $event_repository->getById($event_id);
|
||||
$event = $this->event_repository->getById($event_id);
|
||||
|
||||
if (is_null($event))
|
||||
throw new EntityNotFoundException(sprintf("event id %s does not exists!", $event_id));
|
||||
@ -773,8 +780,8 @@ final class SummitService implements ISummitService
|
||||
throw new ValidationException(sprintf("event %s does not belongs to summit id %s", $event_id, $summit->getIdentifier()));
|
||||
|
||||
$event->unPublish();
|
||||
$event_repository->add($event);
|
||||
$event_repository->cleanupAttendeesScheduleForEvent($event_id);
|
||||
$this->event_repository->add($event);
|
||||
$this->event_repository->cleanupAttendeesScheduleForEvent($event_id);
|
||||
return $event;
|
||||
});
|
||||
}
|
||||
@ -786,11 +793,10 @@ final class SummitService implements ISummitService
|
||||
*/
|
||||
public function deleteEvent(Summit $summit, $event_id)
|
||||
{
|
||||
$event_repository = $this->event_repository;
|
||||
|
||||
return $this->tx_service->transaction(function () use ($summit, $event_id, $event_repository) {
|
||||
return $this->tx_service->transaction(function () use ($summit, $event_id) {
|
||||
|
||||
$event = $event_repository->getById($event_id);
|
||||
$event = $this->event_repository->getById($event_id);
|
||||
|
||||
if (is_null($event))
|
||||
throw new EntityNotFoundException(sprintf("event id %s does not exists!", $event_id));
|
||||
@ -798,9 +804,9 @@ final class SummitService implements ISummitService
|
||||
if ($event->getSummit()->getIdentifier() !== $summit->getIdentifier())
|
||||
throw new ValidationException(sprintf("event %s does not belongs to summit id %s", $event_id, $summit->getIdentifier()));
|
||||
|
||||
$event_repository->delete($event);
|
||||
$this->event_repository->delete($event);
|
||||
// clean up summit attendees schedule
|
||||
$event_repository->cleanupAttendeesScheduleForEvent($event_id);
|
||||
$this->event_repository->cleanupAttendeesScheduleForEvent($event_id);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
public function testGetAllSummits()
|
||||
{
|
||||
|
||||
$params = ['expand' => 'type'];
|
||||
$params = ['expand' => 'type,event_types,tracks'];
|
||||
|
||||
$headers = array("HTTP_Authorization" => " Bearer " . $this->access_token);
|
||||
$response = $this->action(
|
||||
@ -109,7 +109,8 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
|
||||
$params = array
|
||||
(
|
||||
'id' => $summit_id
|
||||
'id' => $summit_id,
|
||||
'expand' =>'event_types',
|
||||
);
|
||||
|
||||
$headers = array("HTTP_Authorization" => " Bearer " . $this->access_token);
|
||||
@ -199,7 +200,6 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
$this->assertResponseStatus(200);
|
||||
}
|
||||
|
||||
|
||||
public function testGetCurrentSummit($summit_id = 23)
|
||||
{
|
||||
|
||||
@ -964,11 +964,11 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
$this->assertTrue(!is_null($events));
|
||||
}
|
||||
|
||||
public function testPostEvent($start_date = 1477645200, $end_date = 1477647600)
|
||||
public function testPostEvent($summit_id = 23, $location_id = 0, $type_id = 0, $track_id = 0, $start_date = 1477645200, $end_date = 1477647600)
|
||||
{
|
||||
$params = array
|
||||
(
|
||||
'id' => 7,
|
||||
'id' => $summit_id,
|
||||
);
|
||||
|
||||
$headers = array
|
||||
@ -979,16 +979,20 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
|
||||
$data = array
|
||||
(
|
||||
'title' => 'Neutron: tbd',
|
||||
'description' => 'TBD',
|
||||
'location_id' => 179,
|
||||
'title' => 'Neutron: tbd',
|
||||
'description' => 'TBD',
|
||||
'allow_feedback' => true,
|
||||
'start_date' => $start_date,
|
||||
'end_date' => $end_date,
|
||||
'type_id' => 95,
|
||||
'tags' => ['Neutron']
|
||||
'start_date' => $start_date,
|
||||
'end_date' => $end_date,
|
||||
'type_id' => $type_id,
|
||||
'tags' => ['Neutron'],
|
||||
'track_id' => $track_id
|
||||
);
|
||||
|
||||
if($location_id > 0){
|
||||
$data['location_id'] = $location_id;
|
||||
}
|
||||
|
||||
$response = $this->action
|
||||
(
|
||||
"POST",
|
||||
@ -1004,7 +1008,7 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
$this->assertResponseStatus(201);
|
||||
$content = $response->getContent();
|
||||
$event = json_decode($content);
|
||||
$this->assertTrue($event->getId() > 0);
|
||||
$this->assertTrue($event->id > 0);
|
||||
return $event;
|
||||
}
|
||||
|
||||
@ -1131,15 +1135,17 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
|
||||
}
|
||||
|
||||
public function testPublishEvent($start_date = 1461520800, $end_date = 1461526200)
|
||||
public function testPublishEvent($start_date = 1509789600, $end_date = 1509791400)
|
||||
{
|
||||
$event = $this->testPostEvent($start_date, $end_date);
|
||||
$event = $this->testPostEvent($summit_id = 23,$location_id = 0, $type_id = 124, $track_id = 206, $start_date, $end_date);
|
||||
unset($event->tags);
|
||||
|
||||
$params = array
|
||||
(
|
||||
'id' => 6,
|
||||
'event_id' => $event->getId(),
|
||||
'id' => $summit_id,
|
||||
'event_id' => $event->id,
|
||||
'start_date' => $start_date,
|
||||
'end_date' => $end_date
|
||||
);
|
||||
|
||||
$headers = array
|
||||
|
Loading…
Reference in New Issue
Block a user