Revert "Update API code to work with Presentation Moderators collection (+N)"

This reverts commit 812519f220.

Change-Id: I3c56db1fb8e214da4659a77ed3a76f1020927d36
This commit is contained in:
sebastian marcet 2019-02-21 15:11:06 +00:00 committed by smarcet
parent fcf8de0449
commit 7913ffe703
47 changed files with 675 additions and 958 deletions

View File

@ -13,7 +13,7 @@
**/
use Doctrine\ORM\Event\LifecycleEventArgs;
use Illuminate\Queue\SerializesModels;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
/**
* Class PresentationSpeakerEntityStateChanged
* @package App\Events
@ -24,7 +24,7 @@ class PresentationSpeakerEntityStateChanged extends Event
/**
* @var Speaker
* @var PresentationSpeaker
*/
protected $speaker;
@ -35,17 +35,17 @@ class PresentationSpeakerEntityStateChanged extends Event
/**
* SummitEventEntityStateChanged constructor.
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @param LifecycleEventArgs $args
*/
public function __construct(Speaker $speaker, LifecycleEventArgs $args)
public function __construct(PresentationSpeaker $speaker, LifecycleEventArgs $args)
{
$this->speaker = $speaker;
$this->args = $args;
}
/**
* @return Speaker
* @return PresentationSpeaker
*/
public function getPresentationSpeaker()
{

View File

@ -34,7 +34,7 @@ final class PresentationSpeakerCreatedEntityEventFactory
foreach($event->getPresentationSpeaker()->getRelatedSummits() as $summit) {
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName("Speaker");
$entity_event->setEntityClassName("PresentationSpeaker");
$entity_event->setEntityId($event->getPresentationSpeaker()->getId());
$entity_event->setType('INSERT');

View File

@ -34,7 +34,7 @@ final class PresentationSpeakerUpdatedEntityEventFactory
foreach($event->getPresentationSpeaker()->getRelatedSummits() as $summit) {
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName("Speaker");
$entity_event->setEntityClassName("PresentationSpeaker");
$entity_event->setEntityId($event->getPresentationSpeaker()->getId());
$entity_event->setType('UPDATE');

View File

@ -333,7 +333,6 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
public function addEvent($summit_id)
{
try {
$expand = Request::input('expand', '');
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
if (is_null($summit)) return $this->error404();
if(!Request::isJson()) return $this->error400();
@ -360,7 +359,8 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
'attendees_expected_learnt' => 'sometimes|string|max:1000',
'attending_media' => 'sometimes|boolean',
'to_record' => 'sometimes|boolean',
'speakers' => 'sometimes|speakers_dto_array',
'speakers' => 'sometimes|int_array',
'moderator_speaker_id' => 'sometimes|integer',
// group event
'groups' => 'sometimes|int_array',
];
@ -385,7 +385,7 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
$event = $this->service->addEvent($summit, HTMLCleaner::cleanData($data->all(), $fields));
return $this->created(SerializerRegistry::getInstance()->getSerializer($event)->serialize($expand));
return $this->created(SerializerRegistry::getInstance()->getSerializer($event)->serialize());
}
catch (ValidationException $ex1) {
Log::warning($ex1);
@ -414,8 +414,7 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
if (is_null($summit)) return $this->error404();
if(!Request::isJson()) return $this->error400();
$data = Input::json();
$expand = Request::input('expand', '');
$data = Input::json();
$current_member = null;
$member_id = $this->resource_server_context->getCurrentUserExternalId();
@ -445,7 +444,8 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
'attendees_expected_learnt' => 'sometimes|string|max:1000',
'attending_media' => 'sometimes|boolean',
'to_record' => 'sometimes|boolean',
'speakers' => 'sometimes|speakers_dto_array',
'speakers' => 'sometimes|int_array',
'moderator_speaker_id' => 'sometimes|integer',
// group event
'groups' => 'sometimes|int_array',
'occupancy' => 'sometimes|in:EMPTY,25%,50%,75%,FULL'
@ -471,7 +471,7 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
$event = $this->service->updateEvent($summit, $event_id, HTMLCleaner::cleanData($data->all(), $fields), $current_member);
return $this->ok(SerializerRegistry::getInstance()->getSerializer($event)->serialize($expand));
return $this->ok(SerializerRegistry::getInstance()->getSerializer($event)->serialize());
}
catch (ValidationException $ex1)

View File

@ -27,7 +27,7 @@ use models\summit\IEventFeedbackRepository;
use models\summit\ISpeakerRepository;
use models\summit\ISummitEventRepository;
use models\summit\ISummitRepository;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use ModelSerializers\ISerializerTypeSelector;
use ModelSerializers\SerializerRegistry;
use services\model\ISpeakerService;
@ -950,13 +950,13 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
switch ($role) {
case 'creator':
$role = Speaker::RoleCreator;
$role = PresentationSpeaker::ROLE_CREATOR;
break;
case 'speaker':
$role = Speaker::RoleSpeaker;
$role = PresentationSpeaker::ROLE_SPEAKER;
break;
case 'moderator':
$role = Speaker::RoleModerator;
$role = PresentationSpeaker::ROLE_MODERATOR;
break;
}
$presentations = $speaker->getPresentationsBySelectionPlanAndRole($selection_plan, $role);
@ -1009,13 +1009,13 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
switch ($role) {
case 'creator':
$role = Speaker::RoleCreator;
$role = PresentationSpeaker::ROLE_CREATOR;
break;
case 'speaker':
$role = Speaker::RoleSpeaker;
$role = PresentationSpeaker::ROLE_SPEAKER;
break;
case 'moderator':
$role = Speaker::RoleModerator;
$role = PresentationSpeaker::ROLE_MODERATOR;
break;
}
$presentations = $speaker->getPresentationsBySummitAndRole($summit, $role);
@ -1053,7 +1053,7 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
if (is_null($current_member_id))
return $this->error403();
$this->summit_service->addSpeaker2PresentationByRole($current_member_id, $speaker_id, $presentation_id, Speaker::RoleSpeaker);
$this->summit_service->addSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id);
return $this->updated();
@ -1080,7 +1080,7 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
if (is_null($current_member_id))
return $this->error403();
$this->summit_service->addSpeaker2PresentationByRole($current_member_id, $speaker_id, $presentation_id, Speaker::RoleModerator);
$this->summit_service->addModerator2Presentation($current_member_id, $speaker_id, $presentation_id);
return $this->updated();
@ -1107,7 +1107,7 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
if (is_null($current_member_id))
return $this->error403();
$this->summit_service->removeSpeakerFromPresentationByRole($current_member_id, $speaker_id, $presentation_id, Speaker::RoleSpeaker);
$this->summit_service->removeSpeakerFromPresentation($current_member_id, $speaker_id, $presentation_id);
return $this->deleted();
@ -1134,7 +1134,7 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
if (is_null($current_member_id))
return $this->error403();
$this->summit_service->removeSpeakerFromPresentationByRole($current_member_id, $speaker_id, $presentation_id, Speaker::RoleModerator);
$this->summit_service->removeModeratorFromPresentation($current_member_id, $speaker_id, $presentation_id);
return $this->deleted();
@ -1150,5 +1150,4 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
}
}
}

View File

@ -13,7 +13,7 @@
**/
use models\oauth2\IResourceServerContext;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use models\summit\Summit;
/**
@ -40,7 +40,7 @@ class CheckMeSpeakerStrategy implements ICheckSpeakerStrategy
/**
* @param int $speaker_id
* @param Summit $summit
* @return null|Speaker
* @return null|PresentationSpeaker
*/
public function check($speaker_id, Summit $summit)
{

View File

@ -12,7 +12,7 @@
* limitations under the License.
**/
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use models\summit\Summit;
/**
@ -24,7 +24,7 @@ interface ICheckSpeakerStrategy
/**
* @param mixed $speaker_id
* @param Summit $summit
* @return null|Speaker
* @return null|PresentationSpeaker
*/
public function check($speaker_id, Summit $summit);
}

View File

@ -143,14 +143,12 @@ final class SerializerRegistry
$this->registry['PresentationLink'] = PresentationLinkSerializer::class;
$this->registry['Company'] = CompanySerializer::class;
$this->registry['Speaker'] =
$this->registry['PresentationSpeaker'] =
[
self::SerializerType_Public => SpeakerSerializer::class,
self::SerializerType_Private => AdminSpeakerSerializer::class
self::SerializerType_Public => PresentationSpeakerSerializer::class,
self::SerializerType_Private => AdminPresentationSpeakerSerializer::class
];
$this->registry['PresentationSpeaker'] = PresentationSpeakerSerializer::class;
// RSVP
$this->registry['RSVP'] = RSVPSerializer::class;
$this->registry['RSVPTemplate'] = RSVPTemplateSerializer::class;

View File

@ -22,6 +22,7 @@ class PresentationSerializer extends SummitEventSerializer
'Level' => 'level',
'CreatorId' => 'creator_id:json_int',
'ModeratorId' => 'moderator_speaker_id:json_int',
'SelectionPlanId' => 'selection_plan_id:json_int',
'ProblemAddressed' => 'problem_addressed:json_string',
'AttendeesExpectedLearnt' => 'attendees_expected_learnt:json_string',
@ -34,6 +35,7 @@ class PresentationSerializer extends SummitEventSerializer
protected static $allowed_fields = [
'track_id',
'creator_id',
'moderator_speaker_id',
'selection_plan_id',
'level',
'problem_addressed',
@ -70,12 +72,9 @@ class PresentationSerializer extends SummitEventSerializer
$values = parent::serialize($expand, $fields, $relations, $params);
if(in_array('speakers', $relations)) {
$values['speakers'] = $presentation->getSpeakerIdsAndRole();
$values['speakers'] = $presentation->getSpeakerIds();
}
// todo: legacy should be removed
$values['moderator_speaker_id'] = 0;
if(in_array('slides', $relations))
{
$slides = array();
@ -123,13 +122,13 @@ class PresentationSerializer extends SummitEventSerializer
switch (trim($relation)) {
case 'speakers': {
$speakers = [];
foreach ($presentation->getSpeakers() as $presentation_speaker) {
$speakers[] = SerializerRegistry::getInstance()->getSerializer($presentation_speaker)->serialize
(
'speaker'
);
foreach ($presentation->getSpeakers() as $s) {
$speakers[] = SerializerRegistry::getInstance()->getSerializer($s)->serialize();
}
$values['speakers'] = $speakers;
if(isset($values['moderator_speaker_id']) && intval($values['moderator_speaker_id']) > 0 ){
$values['moderator'] = SerializerRegistry::getInstance()->getSerializer($presentation->getModerator())->serialize();
}
}
case 'creator':{
if($presentation->getCreatorId() > 0) {

View File

@ -1,61 +0,0 @@
<?php namespace ModelSerializers;
/**
* Copyright 2019 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 Libs\ModelSerializers\AbstractSerializer;
use models\summit\PresentationSpeaker;
/**
* Class PresentationSpeakerSerializer
* @package App\ModelSerializers\Summit\Presentation
*/
class PresentationSpeakerSerializer extends AbstractSerializer
{
protected static $array_mappings = [
'Role' => 'role:json_string',
'PresentationId' => 'id:json_int'
];
protected static $allowed_relations = [
];
/**
* @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();
$presentationSpeaker = $this->object;
if (!$presentationSpeaker instanceof PresentationSpeaker) return [];
$values = parent::serialize($expand, $fields, $relations, $params);
if (!empty($expand)) {
$expand = explode(',', $expand);
foreach ($expand as $relation) {
switch (trim($relation)) {
case 'speaker':{
unset($values['id']);
$values = array_merge($values, SerializerRegistry::getInstance()->getSerializer($presentationSpeaker->getSpeaker())->serialize());
}
break;
}
}
}
return $values;
}
}

View File

@ -11,22 +11,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
/**
* Class AdminSpeakerSerializer
* Class AdminPresentationSpeakerSerializer
* @package ModelSerializers
*/
final class AdminSpeakerSerializer extends SpeakerSerializer
final class AdminPresentationSpeakerSerializer extends PresentationSpeakerSerializer
{
protected static $array_mappings = [
'Notes'=> 'notes:json_string'
];
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @return null|string|string[]
*/
protected function getSpeakerEmail(Speaker $speaker){
protected function getSpeakerEmail(PresentationSpeaker $speaker){
return $speaker->getEmail();
}
@ -42,7 +42,7 @@ final class AdminSpeakerSerializer extends SpeakerSerializer
if(!count($relations)) $relations = $this->getAllowedRelations();
$speaker = $this->object;
if(!$speaker instanceof Speaker) return [];
if(!$speaker instanceof PresentationSpeaker) return [];
$values = parent::serialize($expand, $fields, $relations, $params);
$summit = isset($params['summit'])? $params['summit']:null;

View File

@ -12,13 +12,13 @@
* limitations under the License.
**/
use Illuminate\Support\Facades\Config;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
/**
* Class SpeakerSerializer
* Class PresentationSpeakerSerializer
* @package ModelSerializers
*/
class SpeakerSerializer extends SilverStripeSerializer
class PresentationSpeakerSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'FirstName' => 'first_name:json_string',
@ -40,10 +40,10 @@ class SpeakerSerializer extends SilverStripeSerializer
];
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @return null|string|string[]
*/
protected function getSpeakerEmail(Speaker $speaker){
protected function getSpeakerEmail(PresentationSpeaker $speaker){
$email = $speaker->getEmail();
$em = explode("@", $email);
$name = implode(array_slice($em, 0, count($em) - 1), '@');
@ -65,16 +65,15 @@ class SpeakerSerializer extends SilverStripeSerializer
if(!count($relations)) $relations = $this->getAllowedRelations();
$speaker = $this->object;
if(!$speaker instanceof Speaker) return [];
if(!$speaker instanceof PresentationSpeaker) return [];
$values = parent::serialize($expand, $fields, $relations, $params);
$values['email'] = $this->getSpeakerEmail($speaker);
$summit_id = isset($params['summit_id'])? intval($params['summit_id']):null;
$published = isset($params['published'])? intval($params['published']):true;
if(!is_null($summit_id)) {
$values['presentations'] = $speaker->getPresentationIdsAndRole($summit_id, $published);
// todo: legacy field remove it
$values['moderated_presentations'] = [];
$values['presentations'] = $speaker->getPresentationIds($summit_id, $published);
$values['moderated_presentations'] = $speaker->getModeratedPresentationIds($summit_id, $published);
}
$values['pic'] = Config::get("server.assets_base_url", 'https://www.openstack.org/') . 'profile_images/speakers/' . $speaker->getId();
@ -150,12 +149,16 @@ class SpeakerSerializer extends SilverStripeSerializer
switch (trim($relation)) {
case 'presentations': {
$presentations = [];
foreach ($speaker->getSpeakerPresentations($summit_id, $published) as $p) {
foreach ($speaker->getPresentations($summit_id, $published) as $p) {
$presentations[] = SerializerRegistry::getInstance()->getSerializer($p)->serialize();
}
$values['presentations'] = $presentations;
// todo: legacy field remove it
$values['moderated_presentations'] = [];
$moderated_presentations = [];
foreach ($speaker->getModeratedPresentations($summit_id, $published) as $p) {
$moderated_presentations[] = SerializerRegistry::getInstance()->getSerializer($p)->serialize();
}
$values['moderated_presentations'] = $presentations;
}
break;
case 'member': {

View File

@ -1,4 +1,5 @@
<?php namespace ModelSerializers;
/**
* Copyright 2016 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
@ -133,8 +134,8 @@ class SummitSerializer extends SilverStripeSerializer
}
if (!empty($expand)) {
$relations = explode(',', $expand);
foreach ($relations as $relation) {
$expand = explode(',', $expand);
foreach ($expand as $relation) {
switch (trim($relation)) {
case 'event_types':{
$event_types = [];
@ -190,9 +191,9 @@ class SummitSerializer extends SilverStripeSerializer
// 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.scope_base_realm');
$needed_scope = sprintf(SummitScopes::ReadAllSummitData, $current_realm);
$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;
}
@ -218,7 +219,7 @@ class SummitSerializer extends SilverStripeSerializer
$schedule = [];
foreach ($summit->getScheduleEvents() as $event) {
$schedule[] = SerializerRegistry::getInstance()->getSerializer($event)->serialize($expand);
$schedule[] = SerializerRegistry::getInstance()->getSerializer($event)->serialize();
}
$values['schedule'] = $schedule;

View File

@ -12,7 +12,7 @@
* limitations under the License.
**/
use Doctrine\ORM\Mapping AS ORM;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
/**
* @ORM\Entity
* @ORM\Table(name="SpeakerCreationEmailCreationRequest")
@ -22,9 +22,9 @@ use models\summit\Speaker;
class SpeakerCreationEmailCreationRequest extends EmailCreationRequest
{
/**
* @ORM\ManyToOne(targetEntity="models\summit\Speaker")
* @ORM\ManyToOne(targetEntity="models\summit\PresentationSpeaker")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var Speaker
* @var PresentationSpeaker
*/
protected $speaker;
@ -35,7 +35,7 @@ class SpeakerCreationEmailCreationRequest extends EmailCreationRequest
}
/**
* @return Speaker
* @return PresentationSpeaker
*/
public function getSpeaker()
{
@ -43,7 +43,7 @@ class SpeakerCreationEmailCreationRequest extends EmailCreationRequest
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
*/
public function setSpeaker($speaker)
{

View File

@ -12,7 +12,7 @@
* limitations under the License.
**/
use Doctrine\ORM\Mapping AS ORM;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use models\summit\SpeakerAnnouncementSummitEmail;
use models\summit\SummitOwned;
use models\summit\SummitRegistrationPromoCode;
@ -41,9 +41,9 @@ class SpeakerSelectionAnnouncementEmailCreationRequest
protected $speaker_role;
/**
* @ORM\ManyToOne(targetEntity="models\summit\Speaker")
* @ORM\ManyToOne(targetEntity="models\summit\PresentationSpeaker")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var Speaker
* @var PresentationSpeaker
*/
protected $speaker;
@ -87,7 +87,7 @@ class SpeakerSelectionAnnouncementEmailCreationRequest
}
/**
* @return Speaker
* @return PresentationSpeaker
*/
public function getSpeaker()
{
@ -95,7 +95,7 @@ class SpeakerSelectionAnnouncementEmailCreationRequest
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
*/
public function setSpeaker($speaker)
{

View File

@ -100,7 +100,7 @@ final class EntityEventTypeFactory
return new SummitLocationEntityEventType($e, $ctx);
}
break;
case 'Speaker':
case 'PresentationSpeaker':
{
return new PresentationSpeakerEntityEventType($e, $ctx);
}

View File

@ -113,6 +113,14 @@ class Presentation extends SummitEvent
*/
protected $attending_media;
/**
* @ORM\ManyToOne(targetEntity="PresentationSpeaker", inversedBy="moderated_presentations")
* @ORM\JoinColumn(name="ModeratorID", referencedColumnName="ID", onDelete="SET NULL")
* @var PresentationSpeaker
*/
private $moderator;
/**
* @ORM\ManyToOne(targetEntity="models\main\Member")
* @ORM\JoinColumn(name="CreatorID", referencedColumnName="ID", onDelete="SET NULL")
@ -134,8 +142,16 @@ class Presentation extends SummitEvent
private $materials;
/**
* @ORM\OneToMany(targetEntity="PresentationSpeaker", mappedBy="presentation", cascade={"persist"}, orphanRemoval=true)
* @var PresentationSpeaker[]
* @ORM\ManyToMany(targetEntity="models\summit\PresentationSpeaker", inversedBy="presentations")
* @ORM\JoinTable(name="Presentation_Speakers",
* joinColumns={
* @ORM\JoinColumn(name="PresentationID", referencedColumnName="ID", onDelete="CASCADE")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="PresentationSpeakerID", referencedColumnName="ID", onDelete="CASCADE")
*
* }
* )
*/
private $speakers;
@ -251,67 +267,25 @@ class Presentation extends SummitEvent
}
/**
* @param Speaker $speaker
* @param string $role
* @return $this
* @param PresentationSpeaker $speaker
*/
public function addSpeakerByRole(Speaker $speaker, string $role){
if($this->isSpeaker($speaker, $role)) return $this;
$presentationSpeaker = new PresentationSpeaker;
$presentationSpeaker->setPresentation($this);
$presentationSpeaker->setSpeaker($speaker);
$presentationSpeaker->setRole($role);
$this->speakers->add($presentationSpeaker);
return $this;
public function addSpeaker(PresentationSpeaker $speaker){
if($this->speakers->contains($speaker)) return;
$this->speakers->add($speaker);
$speaker->addPresentation($this);
}
/**
* @param PresentationSpeaker $presentationSpeaker
* @return $this
*/
public function addPresentationSpeaker(PresentationSpeaker $presentationSpeaker){
if($this->speakers->contains($presentationSpeaker)) return $this;
$this->speakers->add($presentationSpeaker);
return $this;
}
/**
* @param string $role
* @return $this
*/
public function clearSpeakersByRole(string $role){
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('role', $role));
$speakersByRole = $this->speakers->matching($criteria);
foreach($speakersByRole as $speaker){
$this->speakers->removeElement($speaker);
}
return $this;
public function clearSpeakers(){
$this->speakers->clear();
}
/**
* @return int[]
*/
public function getSpeakerIds(): array
public function getSpeakerIds()
{
return $this->speakers->map(function(PresentationSpeaker $entity) {
return $entity->getSpeaker()->getId();
})->toArray();
}
/**
* @return array
*/
public function getSpeakerIdsAndRole(): array
{
return $this->speakers->map(function(PresentationSpeaker $entity) {
return
[
'id' => $entity->getSpeaker()->getId() ,
'role' => $entity->getRole()
];
return $this->speakers->map(function($entity) {
return $entity->getId();
})->toArray();
}
@ -370,53 +344,19 @@ class Presentation extends SummitEvent
}
/**
* @param Speaker $speaker
* @return $this
* @param PresentationSpeaker $speaker
*/
public function removeSpeaker(Speaker $speaker){
if(!$this->isSpeaker($speaker)) return $this;
$presentation_speaker = $this->getPresentationSpeakerByRole
(
$speaker, Speaker::RoleSpeaker
);
if(is_null($presentation_speaker)) return $this;
$this->speakers->removeElement($presentation_speaker);
return $this;
}
/**
* @param Speaker $speaker
* @param string $role
* @return PresentationSpeaker
*/
public function getPresentationSpeakerByRole(Speaker $speaker, string $role):PresentationSpeaker {
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('speaker', $speaker));
$criteria->andWhere(Criteria::expr()->eq('role', $role));
return $this->speakers->matching($criteria)->first();
public function removeSpeaker(PresentationSpeaker $speaker){
if(!$this->speakers->contains($speaker)) return;
$this->speakers->removeElement($speaker);
}
/**
* @param Speaker $speaker
* @param string $role
* @param PresentationSpeaker $speaker
* @return bool
*/
public function isSpeaker(Speaker $speaker, string $role = Speaker::RoleSpeaker){
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('speaker', $speaker));
$criteria->andWhere(Criteria::expr()->eq('role', $role));
return $this->speakers->matching($criteria)->count() > 0;
}
/**
* @param string $role
* @return int
*/
public function getSpeakerCountByRole(string $role = Speaker::RoleSpeaker):int {
$criteria = Criteria::create();
$criteria->andWhere(Criteria::expr()->eq('role', $role));
return $this->speakers->matching($criteria)->count();
public function isSpeaker(PresentationSpeaker $speaker){
return $this->speakers->contains($speaker);
}
/**
@ -466,6 +406,17 @@ class Presentation extends SummitEvent
$link->setPresentation($this);
}
/**
* @return int
*/
public function getModeratorId(){
try {
return !is_null($this->moderator)? $this->moderator->getId():0;
}
catch(\Exception $ex){
return 0;
}
}
/**
* @return int
@ -479,6 +430,27 @@ class Presentation extends SummitEvent
}
}
/**
* @return PresentationSpeaker
*/
public function getModerator()
{
return $this->moderator;
}
/**
* @param PresentationSpeaker $moderator
*/
public function setModerator(PresentationSpeaker $moderator)
{
$this->moderator = $moderator;
}
public function unsetModerator(){
$this->moderator = null;
}
/**
* @return string
*/
@ -742,13 +714,13 @@ class Presentation extends SummitEvent
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @return bool
*/
public function canEdit(Speaker $speaker){
public function canEdit(PresentationSpeaker $speaker){
if($this->getCreatorId() == $speaker->getMemberId()) return true;
if($this->isSpeaker($speaker, Speaker::RoleModerator)) return true;
if($this->isSpeaker($speaker, Speaker::RoleSpeaker)) return true;
if($this->getModeratorId() == $speaker->getId()) return true;
if($this->isSpeaker($speaker)) return true;
return false;
}

View File

@ -1,120 +0,0 @@
<?php namespace models\summit;
/**
* Copyright 2019 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\Models\Utils\BaseEntity;
use models\summit\Presentation;
use models\summit\Speaker;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity
* @ORM\Table(name="Presentation_Speakers")
* Class PresentationSpeaker
* @package models\summit
*/
class PresentationSpeaker extends BaseEntity
{
/**
* @ORM\ManyToOne(targetEntity="Speaker", inversedBy="presentations")
* @ORM\JoinColumn(name="PresentationSpeakerID", referencedColumnName="ID", onDelete="CASCADE")
* @var Speaker
*/
private $speaker;
/**
* @ORM\ManyToOne(targetEntity="Presentation", inversedBy="speakers")
* @ORM\JoinColumn(name="PresentationID", referencedColumnName="ID", onDelete="CASCADE")
* @var Presentation
*/
private $presentation;
/**
* @ORM\Column(name="Role", type="string")
* @var string
*/
private $role;
/**
* @return Speaker
*/
public function getSpeaker()
{
return $this->speaker;
}
/**
* @param Speaker $speaker
* @return $this
*/
public function setSpeaker(Speaker $speaker)
{
$this->speaker = $speaker;
return $this;
}
/**
* @return Presentation
*/
public function getPresentation()
{
return $this->presentation;
}
/**
* @return int
*/
public function getPresentationId()
{
try {
return !is_null($this->presentation) ? $this->presentation->getId() : 0;
} catch (\Exception $ex) {
return 0;
}
}
/**
* @return int
*/
public function getSpeakerId(){
try {
return !is_null($this->speaker) ? $this->speaker->getId() : 0;
} catch (\Exception $ex) {
return 0;
}
}
/**
* @param Presentation $presentation
* @return $this
*/
public function setPresentation(Presentation $presentation)
{
$this->presentation = $presentation;
return $this;
}
/**
* @return string
*/
public function getRole()
{
return $this->role;
}
/**
* @param string $role
*/
public function setRole(string $role)
{
$this->role = $role;
}
}

View File

@ -156,22 +156,6 @@ SQL;
return $this->use_speakers;
}
/**
* @param string $role
* @return bool
*/
public function shouldUseRole(string $role){
switch ($role){
case Speaker::RoleSpeaker:
return $this->use_speakers;
break;
case Speaker::RoleModerator:
return $this->use_moderator;
break;
}
return false;
}
/**
* @return bool
*/
@ -180,54 +164,6 @@ SQL;
return $this->are_speakers_mandatory;
}
/**
* @param string $role
* @return bool
*/
public function isRoleMandatory(string $role){
switch ($role){
case Speaker::RoleSpeaker:
return $this->are_speakers_mandatory;
break;
case Speaker::RoleModerator:
return $this->is_moderator_mandatory;
break;
}
return false;
}
/**
* @param string $role
* @return int
*/
public function getMinByRole(string $role){
switch ($role){
case Speaker::RoleSpeaker:
return $this->min_speakers;
break;
case Speaker::RoleModerator:
return $this->min_moderators;
break;
}
return 0;
}
/**
* @param string $role
* @return int
*/
public function getMaxByRole(string $role){
switch ($role){
case Speaker::RoleSpeaker:
return $this->max_speakers;
break;
case Speaker::RoleModerator:
return $this->max_moderators;
break;
}
return 0;
}
/**
* @return bool
*/

View File

@ -32,9 +32,9 @@ class SpeakerPresentationLink extends SilverstripeBaseModel
private $title;
/**
* @ORM\ManyToOne(targetEntity="Speaker", inversedBy="other_presentation_links")
* @ORM\ManyToOne(targetEntity="PresentationSpeaker", inversedBy="other_presentation_links")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var Speaker
* @var PresentationSpeaker
*/
private $speaker;
@ -83,7 +83,7 @@ class SpeakerPresentationLink extends SilverstripeBaseModel
}
/**
* @return Speaker
* @return PresentationSpeaker
*/
public function getSpeaker()
{
@ -91,7 +91,7 @@ class SpeakerPresentationLink extends SilverstripeBaseModel
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
*/
public function setSpeaker($speaker)
{

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use models\summit\PresentationSpeakerSummitAssistanceConfirmationRequest;
use models\summit\Summit;
@ -23,11 +23,11 @@ final class PresentationSpeakerSummitAssistanceConfirmationRequestFactory
{
/**
* @param Summit $summit
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @param array $data
* @return PresentationSpeakerSummitAssistanceConfirmationRequest
*/
public static function build(Summit $summit, Speaker $speaker, array $data){
public static function build(Summit $summit, PresentationSpeaker $speaker, array $data){
$request = new PresentationSpeakerSummitAssistanceConfirmationRequest();
$request->setSummit($summit);

View File

@ -1,5 +1,5 @@
<?php namespace models\summit\factories;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use models\summit\SpeakerAnnouncementSummitEmail;
use models\summit\Summit;
@ -19,7 +19,7 @@ use models\summit\Summit;
final class SpeakerSelectionAnnouncementEmailTypeFactory
{
public static function build(Summit $summit, Speaker $speaker, $role = Speaker::RoleSpeaker)
public static function build(Summit $summit, PresentationSpeaker $speaker, $role = PresentationSpeaker::RoleSpeaker)
{
$has_published = $speaker->hasPublishedRegularPresentations($summit, $role, true, $summit->getExcludedCategoriesForAcceptedPresentations()) ||
$speaker->hasPublishedLightningPresentations($summit, $role, true, $summit->getExcludedCategoriesForAcceptedPresentations());

View File

@ -30,9 +30,9 @@ class SpeakerSummitRegistrationPromoCode extends SummitRegistrationPromoCode
protected $type;
/**
* @ORM\ManyToOne(targetEntity="Speaker", inversedBy="promo_codes")
* @ORM\ManyToOne(targetEntity="PresentationSpeaker", inversedBy="promo_codes")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var Speaker
* @var PresentationSpeaker
*/
protected $speaker;
@ -53,7 +53,7 @@ class SpeakerSummitRegistrationPromoCode extends SummitRegistrationPromoCode
}
/**
* @return Speaker
* @return PresentationSpeaker
*/
public function getSpeaker()
{
@ -61,7 +61,7 @@ class SpeakerSummitRegistrationPromoCode extends SummitRegistrationPromoCode
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
*/
public function setSpeaker($speaker)
{

View File

@ -37,7 +37,7 @@ interface ISpeakerRepository extends IBaseRepository
/**
* @param Member $member
* @return Speaker
* @return PresentationSpeaker
*/
public function getByMember(Member $member);
}

View File

@ -20,11 +20,11 @@ interface ISpeakerSummitRegistrationPromoCodeRepository
extends IBaseRepository
{
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @param Summit $summit
* @return SpeakerSummitRegistrationPromoCode
*/
public function getBySpeakerAndSummit(Speaker $speaker, Summit $summit);
public function getBySpeakerAndSummit(PresentationSpeaker $speaker, Summit $summit);
/**
* @param string $code

View File

@ -31,10 +31,10 @@ use Doctrine\Common\Collections\Criteria;
* @ORM\Table(name="PresentationSpeaker")
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineSpeakerRepository")
* @ORM\HasLifecycleCallbacks
* Class Speaker
* Class PresentationSpeaker
* @package models\summit
*/
class Speaker extends SilverstripeBaseModel
class PresentationSpeaker extends SilverstripeBaseModel
{
const AnnouncementEmailAccepted = 'ACCEPTED';
@ -43,14 +43,9 @@ class Speaker extends SilverstripeBaseModel
const AnnouncementEmailAcceptedAlternate = 'ACCEPTED_ALTERNATE';
const AnnouncementEmailAcceptedRejected = 'ACCEPTED_REJECTED';
const AnnouncementEmailAlternateRejected = 'ALTERNATE_REJECTED';
const RoleSpeaker = 'Speaker';
const RoleModerator = 'Moderator';
const RoleCreator = 'Creator';
const RoleSpeaker = 'SPEAKER';
const RoleModerator = 'MODERATOR';
public static $AvailableRoles = [
self::RoleSpeaker,
self::RoleModerator,
];
/**
* @ORM\Column(name="FirstName", type="string")
*/
@ -141,11 +136,17 @@ class Speaker extends SilverstripeBaseModel
private $promo_codes;
/**
* @ORM\OneToMany(targetEntity="PresentationSpeaker", mappedBy="speaker", cascade={"persist"}, orphanRemoval=true)
* @var PresentationSpeaker[]
* @ORM\ManyToMany(targetEntity="models\summit\Presentation", mappedBy="speakers")
* @var Presentation[]
*/
private $presentations;
/**
* @ORM\OneToMany(targetEntity="Presentation", mappedBy="moderator", cascade={"persist"})
* @var Presentation[]
*/
private $moderated_presentations;
/**
* @ORM\ManyToOne(targetEntity="models\main\File", cascade={"persist"})
* @ORM\JoinColumn(name="PhotoID", referencedColumnName="ID")
@ -319,6 +320,7 @@ class Speaker extends SilverstripeBaseModel
$this->funded_travel = false;
$this->org_has_cloud = false;
$this->presentations = new ArrayCollection;
$this->moderated_presentations = new ArrayCollection;
$this->summit_assistances = new ArrayCollection;
$this->promo_codes = new ArrayCollection;
$this->areas_of_expertise = new ArrayCollection;
@ -334,11 +336,7 @@ class Speaker extends SilverstripeBaseModel
* @param Presentation $presentation
*/
public function addPresentation(Presentation $presentation){
$presentationSpeaker = new PresentationSpeaker();
$presentationSpeaker->setRole(Speaker::RoleSpeaker);
$presentationSpeaker->setPresentation($presentation);
$presentationSpeaker->setSpeaker($this);
$this->presentations->add($presentationSpeaker);
$this->presentations->add($presentation);
}
public function clearPresentations(){
@ -388,18 +386,23 @@ class Speaker extends SilverstripeBaseModel
/**
* @param null|int $summit_id
* @param bool|true $published_ones
* @return PresentationSpeaker[]
* @return Presentation[]
*/
public function presentations($summit_id, $published_ones = true)
{
return $this->presentations
->filter(function(PresentationSpeaker $presentationSpeaker) use($published_ones, $summit_id){
$res = $published_ones? $presentationSpeaker->getPresentation()->isPublished(): true;
$res &= is_null($summit_id)? true : $presentationSpeaker->getPresentation()->getSummit()->getId() == $summit_id;
->filter(function($p) use($published_ones, $summit_id){
$res = $published_ones? $p->isPublished(): true;
$res &= is_null($summit_id)? true : $p->getSummit()->getId() == $summit_id;
return $res;
});
});
}
const ROLE_SPEAKER = 'ROLE_SPEAKER';
const ROLE_CREATOR = 'ROLE_CREATOR';
const ROLE_MODERATOR ='ROLE_MODERATOR';
/**
* @param SelectionPlan $selectionPlan
* @param string $role
@ -407,26 +410,21 @@ class Speaker extends SilverstripeBaseModel
*/
public function getPresentationsBySelectionPlanAndRole(SelectionPlan $selectionPlan, $role){
if($role == self::RoleSpeaker){
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('role', self::RoleSpeaker));
$res = $this->presentations->matching($criteria)->filter(
function(PresentationSpeaker $presentationSpeaker) use($selectionPlan) {
$presentation = $presentationSpeaker->getPresentation();
if($presentation->getSelectionPlanId() != $selectionPlan->getId()) return false;
if($presentation->getCreatorId() == $this->getMemberId()) return false;
return true;
}
);
if($role == self::ROLE_SPEAKER){
$res = $this->presentations->filter(function(Presentation $presentation) use($selectionPlan){
if($presentation->getSelectionPlanId() != $selectionPlan->getId()) return false;
if($presentation->getSummit()->getId() != $selectionPlan->getSummitId()) return false;
if($presentation->getModeratorId() == $this->getId()) return false;
if($presentation->getCreatorId() == $this->getMemberId()) return false;
});
return $res->toArray();
}
if($role == self::RoleCreator){
if($role == self::ROLE_CREATOR){
return $selectionPlan->getSummit()->getCreatedPresentations($this, $selectionPlan);
}
if($role == self::RoleModerator){
if($role == self::ROLE_MODERATOR){
return $selectionPlan->getSummit()->getModeratedPresentationsBy($this, $selectionPlan);
}
@ -440,25 +438,20 @@ class Speaker extends SilverstripeBaseModel
*/
public function getPresentationsBySummitAndRole(Summit $summit, $role){
if($role == self::RoleSpeaker){
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('role', self::RoleSpeaker));
$res = $this->presentations->matching($criteria)->filter(
function(PresentationSpeaker $presentationSpeaker) use($summit) {
$presentation = $presentationSpeaker->getPresentation();
if($presentation->getSummit()->getId() != $summit->getId()) return false;
if($presentation->getCreatorId() == $this->getMemberId()) return false;
return true;
}
);
if($role == self::ROLE_SPEAKER){
$res = $this->presentations->filter(function(Presentation $presentation) use($summit){
if($presentation->getSummit()->getId() != $summit->getId()) return false;
if($presentation->getModeratorId() == $this->getId()) return false;
if($presentation->getCreatorId() == $this->getMemberId()) return false;
});
return $res->toArray();
}
if($role == self::RoleCreator){
if($role == self::ROLE_CREATOR){
return $summit->getCreatedPresentations($this);
}
if($role == self::RoleModerator){
if($role == self::ROLE_MODERATOR){
return $summit->getModeratedPresentationsBy($this);
}
@ -475,7 +468,7 @@ class Speaker extends SilverstripeBaseModel
public function hasPublishedRegularPresentations
(
Summit $summit,
$role = Speaker::RoleSpeaker,
$role = PresentationSpeaker::RoleSpeaker,
$include_sub_roles = false,
array $excluded_tracks = []
)
@ -494,7 +487,7 @@ class Speaker extends SilverstripeBaseModel
public function getPublishedRegularPresentations
(
Summit $summit,
$role = Speaker::RoleSpeaker,
$role = PresentationSpeaker::RoleSpeaker,
$include_sub_roles = false,
array $excluded_tracks = []
)
@ -508,11 +501,11 @@ class Speaker extends SilverstripeBaseModel
$excluded_tracks
);
if($include_sub_roles && $role == Speaker::RoleModerator){
if($include_sub_roles && $role == PresentationSpeaker::RoleModerator){
$presentations = $this->getPublishedPresentationsByType
(
$summit,
Speaker::RoleSpeaker,
PresentationSpeaker::RoleSpeaker,
[IPresentationType::Keynotes, IPresentationType::Panel, IPresentationType::Presentation],
true,
$excluded_tracks
@ -536,7 +529,7 @@ class Speaker extends SilverstripeBaseModel
public function hasPublishedLightningPresentations
(
Summit $summit,
$role = Speaker::RoleSpeaker,
$role = PresentationSpeaker::RoleSpeaker,
$include_sub_roles = false,
array $excluded_tracks = []
)
@ -560,15 +553,15 @@ class Speaker extends SilverstripeBaseModel
public function getPublishedLightningPresentations
(
Summit $summit,
$role = Speaker::RoleSpeaker,
$role = PresentationSpeaker::RoleSpeaker,
$include_sub_roles = false,
array $excluded_tracks = []
)
{
$list = $this->getPublishedPresentationsByType($summit, $role, [IPresentationType::LightingTalks], true , $excluded_tracks);
if($include_sub_roles && $role == Speaker::RoleModerator){
$presentations = $this->getPublishedPresentationsByType($summit, Speaker::RoleSpeaker, [IPresentationType::LightingTalks], true, $excluded_tracks) ;
if($include_sub_roles && $role == PresentationSpeaker::RoleModerator){
$presentations = $this->getPublishedPresentationsByType($summit, PresentationSpeaker::RoleSpeaker, [IPresentationType::LightingTalks], true, $excluded_tracks) ;
if($presentations) {
foreach ($presentations as $speaker_presentation) {
$list[] = $speaker_presentation;
@ -590,7 +583,7 @@ class Speaker extends SilverstripeBaseModel
public function hasAlternatePresentations
(
Summit $summit,
$role = Speaker::RoleSpeaker,
$role = PresentationSpeaker::RoleSpeaker,
$include_sub_roles = false,
array $excluded_tracks = [],
$published_ones = false
@ -610,7 +603,7 @@ class Speaker extends SilverstripeBaseModel
public function getAlternatePresentations
(
Summit $summit,
$role = Speaker::RoleSpeaker,
$role = PresentationSpeaker::RoleSpeaker,
$include_sub_roles = false,
array $excluded_tracks = [],
$published_ones = false
@ -623,18 +616,26 @@ class Speaker extends SilverstripeBaseModel
$exclude_category_dql = ' AND p.category NOT IN (:exclude_tracks)';
}
$query = $this->createQuery("SELECT p from models\summit\Presentation p
if($role == PresentationSpeaker::RoleSpeaker) {
$query = $this->createQuery("SELECT p from models\summit\Presentation p
JOIN p.summit s
JOIN p.speakers sp
WHERE s.id = :summit_id
AND p.published = :published
AND sp.role = :role
AND sp.speaker.id = :speaker_id".$exclude_category_dql);
AND sp.id = :speaker_id".$exclude_category_dql);
}
else{
$query = $this->createQuery("SELECT p from models\summit\Presentation p
JOIN p.summit s
JOIN p.moderator m
WHERE s.id = :summit_id
AND p.published = :published
AND m.id = :speaker_id".$exclude_category_dql);
}
$query
->setParameter('summit_id', $summit->getId())
->setParameter('speaker_id', $this->id)
->setParameter('role', $role)
->setParameter('published', $published_ones ? 1 : 0);
if(count($excluded_tracks) > 0){
@ -650,8 +651,8 @@ class Speaker extends SilverstripeBaseModel
}
// if role is moderator, add also the ones that belongs to role speaker ( if $include_sub_roles is true)
if($include_sub_roles && $role == Speaker::RoleModerator){
$presentations = $this->getAlternatePresentations($summit,Speaker::RoleSpeaker, $include_sub_roles, $excluded_tracks);
if($include_sub_roles && $role == PresentationSpeaker::RoleModerator){
$presentations = $this->getAlternatePresentations($summit,PresentationSpeaker::RoleSpeaker, $include_sub_roles, $excluded_tracks);
if($presentations) {
foreach ($presentations as $speaker_presentation)
$alternate_presentations[] = $speaker_presentation;
@ -671,7 +672,7 @@ class Speaker extends SilverstripeBaseModel
public function hasRejectedPresentations
(
Summit $summit,
$role = Speaker::RoleSpeaker,
$role = PresentationSpeaker::RoleSpeaker,
$include_sub_roles = false,
array $excluded_tracks = []
)
@ -689,13 +690,13 @@ class Speaker extends SilverstripeBaseModel
public function getRejectedPresentations
(
Summit $summit,
$role = Speaker::RoleSpeaker,
$role = PresentationSpeaker::RoleSpeaker,
$include_sub_roles = false,
array $excluded_tracks = []
){
$list = $this->getUnacceptedPresentations($summit, $role, true, $excluded_tracks);
if($include_sub_roles && $role == Speaker::RoleModerator){
$presentations = $this->getUnacceptedPresentations($summit, Speaker::RoleSpeaker, true, $excluded_tracks);
if($include_sub_roles && $role == PresentationSpeaker::RoleModerator){
$presentations = $this->getUnacceptedPresentations($summit, PresentationSpeaker::RoleSpeaker, true, $excluded_tracks);
if($presentations) {
foreach ($presentations as $speaker_presentation) {
$list[] = $speaker_presentation;
@ -715,7 +716,7 @@ class Speaker extends SilverstripeBaseModel
public function getUnacceptedPresentations
(
Summit $summit,
$role = Speaker::RoleSpeaker,
$role = PresentationSpeaker::RoleSpeaker,
$exclude_privates_tracks = true,
array $excluded_tracks = []
)
@ -746,17 +747,25 @@ class Speaker extends SilverstripeBaseModel
$exclude_category_dql = ' AND p.category NOT IN (:exclude_tracks)';
}
$query = $this->createQuery("SELECT p from models\summit\Presentation p
if($role == PresentationSpeaker::RoleSpeaker) {
$query = $this->createQuery("SELECT p from models\summit\Presentation p
JOIN p.summit s
JOIN p.speakers sp
WHERE s.id = :summit_id
AND p.published = 0
AND sp.role = :role
AND sp.speaker.id = :speaker_id".$exclude_category_dql);
AND sp.id = :speaker_id".$exclude_category_dql);
}
else{
$query = $this->createQuery("SELECT p from models\summit\Presentation p
JOIN p.summit s
JOIN p.moderator m
WHERE s.id = :summit_id
AND p.published = 0
AND m.id = :speaker_id".$exclude_category_dql);
}
$query
->setParameter('summit_id', $summit->getId())
->setParameter('role', $role)
->setParameter('speaker_id', $this->id);
if(count($excluded_tracks) > 0){
@ -785,7 +794,7 @@ class Speaker extends SilverstripeBaseModel
public function getPublishedPresentationsByType
(
Summit $summit,
$role = Speaker::RoleSpeaker,
$role = PresentationSpeaker::RoleSpeaker,
array $types_slugs = [IPresentationType::Keynotes, IPresentationType::Panel, IPresentationType::Presentation, IPresentationType::LightingTalks],
$exclude_privates_tracks = true,
array $excluded_tracks = []
@ -827,18 +836,26 @@ class Speaker extends SilverstripeBaseModel
$exclude_category_dql = ' and p.category NOT IN (:exclude_tracks)';
}
$query = $this->createQuery("SELECT p from models\summit\Presentation p
if($role == PresentationSpeaker::RoleSpeaker) {
$query = $this->createQuery("SELECT p from models\summit\Presentation p
JOIN p.summit s
JOIN p.speakers sp
WHERE s.id = :summit_id
and sp.speaker.id = :speaker_id
and sp.role = :role
and sp.id = :speaker_id
and p.published = 1 and p.type IN (:types)".$exclude_category_dql);
}
else{
$query = $this->createQuery("SELECT p from models\summit\Presentation p
JOIN p.summit s
JOIN p.moderator m
WHERE s.id = :summit_id
and m.id = :speaker_id
and p.published = 1 and p.type IN (:types)".$exclude_category_dql);
}
$query
->setParameter('summit_id', $summit->getId())
->setParameter('types', $types)
->setParameter('role', $role)
->setParameter('speaker_id', $this->id);
if(count($excluded_tracks) > 0){
@ -852,18 +869,17 @@ class Speaker extends SilverstripeBaseModel
/**
* @param null|int $summit_id
* @param bool|true $published_ones
* @return PresentationSpeaker[]
* @return Presentation[]
*/
public function moderated_presentations($summit_id, $published_ones = true)
{
return $this->presentations->filter(
function(PresentationSpeaker $presentationSpeaker) use($published_ones, $summit_id){
$res = $published_ones? $presentationSpeaker->getPresentation()->isPublished(): true;
$res &= is_null($summit_id)? true : $presentationSpeaker->getPresentation()->getSummit()->getId() == $summit_id;
$res &= $presentationSpeaker->getRole() == Speaker::RoleModerator;
return $this->moderated_presentations
->filter(function($p) use($published_ones, $summit_id){
$res = $published_ones? $p->isPublished(): true;
$res &= is_null($summit_id)? true : $p->getSummit()->getId() == $summit_id;
return $res;
}
);
});
}
/**
@ -882,8 +898,19 @@ class Speaker extends SilverstripeBaseModel
*/
public function getPresentationIds($summit_id, $published_ones = true)
{
return $this->presentations($summit_id, $published_ones)->map(function(PresentationSpeaker $presentationSpeaker) {
return $presentationSpeaker->getPresentation()->getId();
return $this->presentations($summit_id, $published_ones)->map(function($entity) {
return $entity->getId();
})->toArray();
}
/**
* @param bool|true $published_ones
* @return array
*/
public function getAllPresentationIds($published_ones = true)
{
return $this->presentations(null, $published_ones)->map(function($entity) {
return $entity->getId();
})->toArray();
}
@ -892,58 +919,21 @@ class Speaker extends SilverstripeBaseModel
* @param bool|true $published_ones
* @return array
*/
public function getPresentationIdsAndRole($summit_id, $published_ones = true)
public function getPresentations($summit_id, $published_ones = true)
{
return $this->presentations($summit_id, $published_ones)->map(function(PresentationSpeaker $presentationSpeaker) {
return [
'id' => $presentationSpeaker->getPresentation()->getId(),
'role' => $presentationSpeaker->getRole()
];
return $this->presentations($summit_id, $published_ones)->map(function($entity) {
return $entity;
})->toArray();
}
/**
* @param bool|true $published_ones
* @return int[]
* @return array
*/
public function getAllPresentationIds($published_ones = true): array
public function getAllPresentations($published_ones = true)
{
return $this->presentations(null, $published_ones)->map(function(PresentationSpeaker $presentationSpeaker) {
return $presentationSpeaker->getPresentation()->getId();
})->toArray();
}
/**
* @param null $summit_id
* @param bool|true $published_ones
* @return Presentation[]
*/
public function getPresentations($summit_id, $published_ones = true) : array
{
return $this->presentations($summit_id, $published_ones)->map(function(PresentationSpeaker $presentationSpeaker) {
return $presentationSpeaker->getPresentation();
})->toArray();
}
/**
* @param null $summit_id
* @param bool|true $published_ones
* @return Presentation[]
*/
public function getSpeakerPresentations($summit_id, $published_ones = true) : array
{
return $this->presentations($summit_id, $published_ones);
}
/**
* @param bool|true $published_ones
* @return Presentation[]
*/
public function getAllPresentations($published_ones = true):array
{
return $this->presentations(null, $published_ones)->map(function(PresentationSpeaker $presentationSpeaker) {
return $presentationSpeaker->getPresentation();
return $this->presentations(null, $published_ones)->map(function($entity) {
return $entity;
})->toArray();
}
@ -951,46 +941,46 @@ class Speaker extends SilverstripeBaseModel
/**
* @param null $summit_id
* @param bool|true $published_ones
* @return int[]
* @return array
*/
public function getModeratedPresentationIds($summit_id, $published_ones = true):array
public function getModeratedPresentationIds($summit_id, $published_ones = true)
{
return $this->moderated_presentations($summit_id, $published_ones)->map(function(PresentationSpeaker $ps) {
return $ps->getPresentation()->getId();
return $this->moderated_presentations($summit_id, $published_ones)->map(function($entity) {
return $entity->getId();
})->toArray();
}
/**
* @param bool|true $published_ones
* @return int[]
* @return array
*/
public function getAllModeratedPresentationIds($published_ones = true)
{
return $this->moderated_presentations(null, $published_ones)->map(function(PresentationSpeaker $ps) {
return $ps->getPresentation()->getId();
return $this->moderated_presentations(null, $published_ones)->map(function($entity) {
return $entity->getId();
})->toArray();
}
/**
* @param null $summit_id
* @param bool|true $published_ones
* @return Presentation[]
* @return array
*/
public function getModeratedPresentations($summit_id, $published_ones = true)
{
return $this->moderated_presentations($summit_id, $published_ones)->map(function(PresentationSpeaker $ps) {
return $ps->getPresentation();
return $this->moderated_presentations($summit_id, $published_ones)->map(function($entity) {
return $entity;
})->toArray();
}
/**
* @param bool|true $published_ones
* @return Presentation[]
* @return array
*/
public function getAllModeratedPresentations($published_ones = true): array
public function getAllModeratedPresentations($published_ones = true)
{
return $this->moderated_presentations(null, $published_ones)->map(function(PresentationSpeaker $ps) {
return $ps->getPresentation();
return $this->moderated_presentations(null, $published_ones)->map(function($entity) {
return $entity;
})->toArray();
}
@ -1266,7 +1256,7 @@ SQL;
(
[
'id' => $this->id,
'class_name' => "Speaker",
'class_name' => "PresentationSpeaker",
'summits' => $this->getRelatedSummits(),
]
);
@ -1544,11 +1534,8 @@ SQL;
* @param Presentation $presentation
*/
public function addModeratedPresentation(Presentation $presentation){
$presentationSpeaker = new PresentationSpeaker();
$presentationSpeaker->setRole(Speaker::RoleModerator);
$presentationSpeaker->setPresentation($presentation);
$presentationSpeaker->setSpeaker($this);
$this->presentations->add($presentationSpeaker);
$this->moderated_presentations->add($presentation);
$presentation->setModerator($this);
}
/**
@ -1557,9 +1544,8 @@ SQL;
*/
public function isModeratorFor(Summit $summit){
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('presentation.summit', $summit));
$criteria->where(Criteria::expr()->eq('role', self::RoleModerator));
return $this->presentations->matching($criteria)->count() > 0;
$criteria->where(Criteria::expr()->eq('summit', $summit));
return $this->moderated_presentations->matching($criteria)->count() > 0;
}
/**

View File

@ -59,9 +59,9 @@ class PresentationSpeakerSummitAssistanceConfirmationRequest extends Silverstrip
private $confirmation_date;
/**
* @ORM\ManyToOne(targetEntity="Speaker", inversedBy="summit_assistances")
* @ORM\ManyToOne(targetEntity="PresentationSpeaker", inversedBy="summit_assistances")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var Speaker
* @var PresentationSpeaker
*/
private $speaker;
@ -137,7 +137,7 @@ class PresentationSpeakerSummitAssistanceConfirmationRequest extends Silverstrip
}
/**
* @return Speaker
* @return PresentationSpeaker
*/
public function getSpeaker()
{
@ -145,7 +145,7 @@ class PresentationSpeakerSummitAssistanceConfirmationRequest extends Silverstrip
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
*/
public function setSpeaker($speaker)
{

View File

@ -12,7 +12,7 @@
* limitations under the License.
**/
use Doctrine\ORM\Mapping AS ORM;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use models\summit\SummitOwned;
use models\utils\SilverstripeBaseModel;
use DateTime;
@ -51,9 +51,9 @@ class SpeakerAnnouncementSummitEmail extends SilverstripeBaseModel
Use SummitOwned;
/**
* @ORM\ManyToOne(targetEntity="models\summit\Speaker", inversedBy="announcement_summit_emails")
* @ORM\ManyToOne(targetEntity="models\summit\PresentationSpeaker", inversedBy="announcement_summit_emails")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var Speaker
* @var PresentationSpeaker
*/
protected $speaker;
@ -90,7 +90,7 @@ class SpeakerAnnouncementSummitEmail extends SilverstripeBaseModel
}
/**
* @return Speaker
* @return PresentationSpeaker
*/
public function getSpeaker()
{
@ -98,7 +98,7 @@ class SpeakerAnnouncementSummitEmail extends SilverstripeBaseModel
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
*/
public function setSpeaker($speaker)
{

View File

@ -37,9 +37,9 @@ class SpeakerExpertise extends SilverstripeBaseModel
}
/**
* @ORM\ManyToOne(targetEntity="Speaker", inversedBy="areas_of_expertise")
* @ORM\ManyToOne(targetEntity="PresentationSpeaker", inversedBy="areas_of_expertise")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var Speaker
* @var PresentationSpeaker
*/
private $speaker;
@ -60,7 +60,7 @@ class SpeakerExpertise extends SilverstripeBaseModel
}
/**
* @return Speaker
* @return PresentationSpeaker
*/
public function getSpeaker()
{
@ -68,7 +68,7 @@ class SpeakerExpertise extends SilverstripeBaseModel
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
*/
public function setSpeaker($speaker)
{

View File

@ -44,9 +44,9 @@ class SpeakerRegistrationRequest extends SilverstripeBaseModel
private $confirmation_date;
/**
* @ORM\ManyToOne(targetEntity="Speaker")
* @ORM\ManyToOne(targetEntity="PresentationSpeaker")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var Speaker
* @var PresentationSpeaker
*/
private $speaker;
@ -117,7 +117,7 @@ class SpeakerRegistrationRequest extends SilverstripeBaseModel
}
/**
* @return Speaker
* @return PresentationSpeaker
*/
public function getSpeaker()
{
@ -125,7 +125,7 @@ class SpeakerRegistrationRequest extends SilverstripeBaseModel
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
*/
public function setSpeaker($speaker)
{

View File

@ -28,9 +28,9 @@ class SpeakerTravelPreference extends SilverstripeBaseModel
private $country;
/**
* @ORM\ManyToOne(targetEntity="Speaker", inversedBy="travel_preferences")
* @ORM\ManyToOne(targetEntity="PresentationSpeaker", inversedBy="travel_preferences")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var Speaker
* @var PresentationSpeaker
*/
private $speaker;
@ -82,7 +82,7 @@ class SpeakerTravelPreference extends SilverstripeBaseModel
}
/**
* @return Speaker
* @return PresentationSpeaker
*/
public function getSpeaker()
{
@ -90,7 +90,7 @@ class SpeakerTravelPreference extends SilverstripeBaseModel
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
*/
public function setSpeaker($speaker)
{

View File

@ -852,58 +852,56 @@ class Summit extends SilverstripeBaseModel
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @param SelectionPlan|null $selectionPlan
* @return array
*/
public function getModeratedPresentationsBy(Speaker $speaker, SelectionPlan $selectionPlan = null){
public function getModeratedPresentationsBy(PresentationSpeaker $speaker, SelectionPlan $selectionPlan = null){
$selection_plan_cond = "";
if(!is_null($selectionPlan)){
$selection_plan_cond = " and sp = :selection_plan";
$selection_plan_cond = " and sp.id = :selection_plan_id";
}
$query = $this->createQuery("SELECT p from models\summit\Presentation p
JOIN p.summit s
JOIN p.speakers spk
JOIN p.moderator m
JOIN p.selection_plan sp
WHERE s = :summit and spk.speaker = :speaker and spk.role = :role".$selection_plan_cond);
WHERE s.id = :summit_id and m.id = :moderator_id".$selection_plan_cond);
$query = $query
->setParameter('summit', $this)
->setParameter('role', Speaker::RoleModerator)
->setParameter('speaker', $speaker);
->setParameter('summit_id', $this->getIdentifier())
->setParameter('moderator_id', $speaker->getIdentifier());
if(!is_null($selectionPlan)){
$query = $query->setParameter('selection_plan', $selectionPlan);
$query = $query->setParameter('selection_plan_id', $selectionPlan->getIdentifier());
}
return $query->getResult();
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @param SelectionPlan|null $selectionPlan
* @return array
*/
public function getCreatedPresentations(Speaker $speaker, SelectionPlan $selectionPlan = null){
public function getCreatedPresentations(PresentationSpeaker $speaker, SelectionPlan $selectionPlan = null){
$selection_plan_cond = "";
if(!is_null($selectionPlan)){
$selection_plan_cond = " and sp = :selection_plan";
$selection_plan_cond = " and sp.id = :selection_plan_id";
}
$query = $this->createQuery("SELECT p from models\summit\Presentation p
JOIN p.summit s
JOIN p.creator c
JOIN p.selection_plan sp
WHERE s = :summit and c = :creator".$selection_plan_cond);
WHERE s.id = :summit_id and c.id = :creator_id".$selection_plan_cond);
$query = $query
->setParameter('summit', $this)
->setParameter('creator', $speaker->getMember());
->setParameter('summit_id', $this->getIdentifier())
->setParameter('creator_id', $speaker->getMemberId());
if(!is_null($selectionPlan)){
$query = $query->setParameter('selection_plan', $selectionPlan);
$query = $query->setParameter('selection_plan_id', $selectionPlan->getIdentifier());
}
return $query->getResult();
@ -1109,16 +1107,14 @@ class Summit extends SilverstripeBaseModel
private function buildModeratorsQuery($filter_published_events = true)
{
$query = $this->createQueryBuilder()
->select('distinct spk')
->from('models\summit\Speaker', 'spk')
->join('spk.presentations', 'ps')
->join('ps.presentation', 'p')
->select('distinct ps')
->from('models\summit\PresentationSpeaker', 'ps')
->join('ps.moderated_presentations', 'p')
->join('p.summit', 's')
->where("s.id = :summit_id")
->andWhere("ps.role =:role");
->where("s.id = :summit_id");
if ($filter_published_events)
$query = $query->andWhere("p.published = 1");
return $query->setParameter('summit_id', $this->getId())->setParameter("role", Speaker::RoleModerator);
return $query->setParameter('summit_id', $this->getId());
}
/**
@ -1128,17 +1124,15 @@ class Summit extends SilverstripeBaseModel
private function buildSpeakersQuery($filter_published_events = true)
{
$query = $this->createQueryBuilder()
->select('distinct spk')
->from('models\summit\Speaker', 'spk')
->join('spk.presentations', 'ps')
->join('ps.presentation', 'o')
->select('distinct ps')
->from('models\summit\PresentationSpeaker', 'ps')
->join('ps.presentations', 'p')
->join('p.summit', 's')
->where("s.id = :summit_id")
->andWhere("ps.role =:role");;
->where("s.id = :summit_id");
if ($filter_published_events)
$query = $query->andWhere("p.published = 1");
return $query->setParameter('summit_id', $this->getId())->setParameter("role", Speaker::RoleModerator);
return $query->setParameter('summit_id', $this->getId());
}
/**
@ -1147,38 +1141,43 @@ class Summit extends SilverstripeBaseModel
private function buildSpeakerSummitAttendanceQuery()
{
return $this->createQueryBuilder()
->select('distinct spk')
->from('models\summit\Speaker', 'spk')
->join('spk.summit_assistances', 'a')
->select('distinct ps')
->from('models\summit\PresentationSpeaker', 'ps')
->join('ps.summit_assistances', 'a')
->join('a.summit', 's')
->where("s.id = :summit_id")
->setParameter('summit_id', $this->getId());
}
/**
* @return Speaker[]
* @return PresentationSpeaker[]
*/
public function getSpeakers()
{
// mix of all roles but once time
$query = $this->createQueryBuilder()
->select('distinct spk')
->from('models\summit\Speaker', 'spk')
->join('spk.presentations', 'sp')
->join('sp.presentation', 'p')
->join('p.summit', 's')
->where("s.id = :summit_id")
->andWhere("p.published = 1");
// moderators
$moderators = $this->buildModeratorsQuery()->getQuery()->getResult();
// get moderators ids to exclude from speakers
$moderators_ids = array();
foreach ($moderators as $m) {
$moderators_ids[] = $m->getId();
}
$query->setParameter('summit_id', $this->getId());
// speakers
$sbuilder = $this->buildSpeakersQuery();
return $query->getQuery()->getResult();
if (count($moderators_ids) > 0) {
$moderators_ids = implode(', ', $moderators_ids);
$sbuilder = $sbuilder->andWhere("ps.id not in ({$moderators_ids})");
}
$speakers = $sbuilder->getQuery()->getResult();
return array_merge($speakers, $moderators);
}
/**
* @param Member $member
* @return Speaker|null
* @return PresentationSpeaker|null
*/
public function getSpeakerByMember(Member $member)
{
@ -1188,14 +1187,14 @@ class Summit extends SilverstripeBaseModel
/**`
* @param int $member_id
* @param bool $filter_published_events
* @return Speaker|null
* @return PresentationSpeaker|null
*/
public function getSpeakerByMemberId($member_id, $filter_published_events = true)
{
// moderators
$moderator = $this->buildModeratorsQuery($filter_published_events)
->join('spk.member', 'm')
->andWhere('m.id = :member_id')
->join('ps.member', 'mb')
->andWhere('mb.id = :member_id')
->setParameter('member_id', $member_id)
->getQuery()->getOneOrNullResult();
@ -1203,8 +1202,8 @@ class Summit extends SilverstripeBaseModel
// speakers
$speaker = $this->buildSpeakersQuery($filter_published_events)
->join('spk.member', 'm')
->andWhere('m.id = :member_id')
->join('ps.member', 'mb')
->andWhere('mb.id = :member_id')
->setParameter('member_id', $member_id)
->getQuery()->getOneOrNullResult();
@ -1212,7 +1211,7 @@ class Summit extends SilverstripeBaseModel
// assistance
$speaker = $this->buildSpeakerSummitAttendanceQuery()
->join('spk.member', 'm')
->join('ps.member', 'mb')
->andWhere('mb.id = :member_id')
->setParameter('member_id', $member_id)
->getQuery()->getOneOrNullResult();
@ -1225,13 +1224,13 @@ class Summit extends SilverstripeBaseModel
/**
* @param int $speaker_id
* @param bool $filter_published_events
* @return Speaker|null
* @return PresentationSpeaker|null
*/
public function getSpeaker($speaker_id, $filter_published_events = true)
{
// moderators
$moderator = $this->buildModeratorsQuery($filter_published_events)
->andWhere('spk.id = :speaker_id')
->andWhere('ps.id = :speaker_id')
->setParameter('speaker_id', $speaker_id)
->getQuery()->getOneOrNullResult();
@ -1239,7 +1238,7 @@ class Summit extends SilverstripeBaseModel
// speakers
$speaker = $this->buildSpeakersQuery($filter_published_events)
->andWhere('spk.id = :speaker_id')
->andWhere('ps.id = :speaker_id')
->setParameter('speaker_id', $speaker_id)
->getQuery()->getOneOrNullResult();
@ -1247,7 +1246,7 @@ class Summit extends SilverstripeBaseModel
// attendance
$speaker = $this->buildSpeakerSummitAttendanceQuery()
->andWhere('spk.id = :speaker_id')
->andWhere('ps.id = :speaker_id')
->setParameter('speaker_id', $speaker_id)
->getQuery()->getOneOrNullResult();
@ -1457,19 +1456,7 @@ SQL;
*/
public function getSpeakersCount()
{
$query = $this->createQueryBuilder()
->select('count (distinct spk)')
->from('models\summit\Speaker', 'spk')
->join('spk.presentations', 'sp')
->join('sp.presentation', 'p')
->join('p.summit', 's')
->where("s.id = :summit_id")
->andWhere("p.published = 1");
$query->setParameter('summit_id', $this->getId());
$res = $query->getQuery()->getSingleResult();
return intval($res[1]);
return count($this->getSpeakers());
}
/**

View File

@ -36,20 +36,10 @@ class AppServiceProvider extends ServiceProvider
'feature_cloud',
'to_record',
'speakers',
'moderator_speaker_id',
'groups'
];
static $speaker_dto_fields = [
'id',
'role'
];
static $speaker_dto_validation_rules = [
// speaker dto rules
'id' => 'required|integer',
'role' => 'sometimes|string|in:Moderator,Speaker',
];
static $event_dto_fields_publish = [
'id',
'start_date',
@ -84,7 +74,8 @@ class AppServiceProvider extends ServiceProvider
'attendees_expected_learnt' => 'sometimes|string|max:100',
'feature_cloud' => 'sometimes|boolean',
'to_record' => 'sometimes|boolean',
'speakers' => 'sometimes|speakers_dto_array',
'speakers' => 'sometimes|int_array',
'moderator_speaker_id' => 'sometimes|integer',
// group event
'groups' => 'sometimes|int_array',
];
@ -124,33 +115,6 @@ class AppServiceProvider extends ServiceProvider
return true;
});
Validator::extend('speakers_dto_array', function($attribute, $value, $parameters, $validator)
{
$validator->addReplacer('speakers_dto_array', function($message, $attribute, $rule, $parameters) use ($validator) {
return sprintf
(
"%s should be an array of speaker data {id : int, role: string [Moderator|Speaker]}",
$attribute);
});
if(!is_array($value)) return false;
foreach($value as $element)
{
if(!is_array($element)) return false;
foreach($element as $key => $element_val){
if(!in_array($key, self::$speaker_dto_fields)) return false;
}
// Creates a Validator instance and validates the data.
$validation = Validator::make($element, self::$speaker_dto_validation_rules);
if($validation->fails()) return false;
}
return true;
});
Validator::extend('event_dto_array', function($attribute, $value, $parameters, $validator)
{
$validator->addReplacer('event_dto_array', function($message, $attribute, $rule, $parameters) use ($validator) {

View File

@ -99,7 +99,7 @@ final class RepositoriesProvider extends ServiceProvider
App::singleton(
'models\summit\ISpeakerRepository',
function(){
return EntityManager::getRepository(\models\summit\Speaker::class);
return EntityManager::getRepository(\models\summit\PresentationSpeaker::class);
});
App::singleton(

View File

@ -15,7 +15,7 @@ use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use models\main\Member;
use models\summit\ISpeakerRepository;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use models\summit\Summit;
use App\Repositories\SilverStripeDoctrineRepository;
use utils\Filter;
@ -98,6 +98,22 @@ FROM (
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
WHERE
EXISTS
(
SELECT E.ID FROM SummitEvent E
INNER JOIN Presentation P ON E.ID = P.ID
INNER JOIN Presentation_Speakers PS ON PS.PresentationID = P.ID
WHERE E.SummitID = {$summit->getId()} AND P.ModeratorID = S.ID
)
UNION
SELECT S.ID,
IFNULL(S.FirstName, M.FirstName) AS FirstName,
IFNULL(S.LastName, M.Surname) AS LastName,
IFNULL(M.Email, R.Email) AS Email
FROM PresentationSpeaker S
LEFT JOIN Member M ON M.ID = S.MemberID
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
WHERE
EXISTS
(
SELECT A.ID FROM PresentationSpeakerSummitAssistanceConfirmationRequest A
WHERE A.SummitID = {$summit->getId()} AND A.SpeakerID = S.ID
@ -177,6 +193,38 @@ FROM (
FROM PresentationSpeaker S
LEFT JOIN Member M ON M.ID = S.MemberID
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
WHERE
EXISTS
(
SELECT E.ID FROM SummitEvent E
INNER JOIN Presentation P ON E.ID = P.ID
INNER JOIN Presentation_Speakers PS ON PS.PresentationID = P.ID
WHERE E.SummitID = {$summit->getId()} AND P.ModeratorID = S.ID
)
UNION
SELECT
S.ID,
S.ClassName,
S.Created,
S.LastEdited,
S.Title AS SpeakerTitle,
S.Bio,
S.IRCHandle,
S.AvailableForBureau,
S.FundedTravel,
S.Country,
S.MemberID,
S.WillingToTravel,
S.WillingToPresentVideo,
S.Notes,
S.TwitterName,
IFNULL(S.FirstName, M.FirstName) AS FirstName,
IFNULL(S.LastName, M.Surname) AS LastName,
IFNULL(M.Email,R.Email) AS Email,
S.PhotoID
FROM PresentationSpeaker S
LEFT JOIN Member M ON M.ID = S.MemberID
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
WHERE
EXISTS
(
@ -189,7 +237,7 @@ SUMMIT_SPEAKERS
SQL;
/*$rsm = new ResultSetMapping();
$rsm->addEntityResult(\models\summit\Speaker::class, 's');
$rsm->addEntityResult(\models\summit\PresentationSpeaker::class, 's');
$rsm->addJoinedEntityResult(\models\main\File::class,'p', 's', 'photo');
$rsm->addJoinedEntityResult(\models\main\Member::class,'m', 's', 'member');
@ -205,7 +253,7 @@ SQL;
$rsm->addFieldResult('m', 'MemberID', 'id');*/
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata(\models\summit\Speaker::class, 's', ['Title' => 'SpeakerTitle']);
$rsm->addRootEntityFromClassMetadata(\models\summit\PresentationSpeaker::class, 's', ['Title' => 'SpeakerTitle']);
// build rsm here
$native_query = $this->_em->createNativeQuery($query, $rsm);
@ -318,7 +366,7 @@ SUMMIT_SPEAKERS
SQL;
/*$rsm = new ResultSetMapping();
$rsm->addEntityResult(\models\summit\Speaker::class, 's');
$rsm->addEntityResult(\models\summit\PresentationSpeaker::class, 's');
$rsm->addJoinedEntityResult(\models\main\File::class,'p', 's', 'photo');
$rsm->addJoinedEntityResult(\models\main\Member::class,'m', 's', 'member');
@ -334,7 +382,7 @@ SQL;
$rsm->addFieldResult('m', 'MemberID', 'id');*/
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata(\models\summit\Speaker::class, 's', ['Title' => 'SpeakerTitle']);
$rsm->addRootEntityFromClassMetadata(\models\summit\PresentationSpeaker::class, 's', ['Title' => 'SpeakerTitle']);
// build rsm here
$native_query = $this->_em->createNativeQuery($query, $rsm);
@ -354,19 +402,19 @@ SQL;
*/
protected function getBaseEntity()
{
return Speaker::class;
return PresentationSpeaker::class;
}
/**
* @param Member $member
* @return Speaker
* @return PresentationSpeaker
*/
public function getByMember(Member $member)
{
return $this->getEntityManager()
->createQueryBuilder()
->select("s")
->from(Speaker::class, "s")
->from(PresentationSpeaker::class, "s")
->where("s.member = :member")
->setParameter("member", $member)
->setMaxResults(1)

View File

@ -12,7 +12,7 @@
* limitations under the License.
**/
use models\summit\ISpeakerSummitRegistrationPromoCodeRepository;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use models\summit\SpeakerSummitRegistrationPromoCode;
use models\summit\Summit;
@ -33,11 +33,11 @@ final class DoctrineSpeakerSummitRegistrationPromoCodeRepository
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @param Summit $summit
* @return SpeakerSummitRegistrationPromoCode
*/
public function getBySpeakerAndSummit(Speaker $speaker, Summit $summit)
public function getBySpeakerAndSummit(PresentationSpeaker $speaker, Summit $summit)
{
if($speaker->getId() == 0) return null;
return $this->getEntityManager()

View File

@ -15,7 +15,7 @@ use models\exceptions\EntityNotFoundException;
use models\exceptions\ValidationException;
use models\main\EmailCreationRequest;
use models\main\File;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use models\summit\PresentationSpeakerSummitAssistanceConfirmationRequest;
use models\summit\SpeakerSummitRegistrationPromoCode;
use models\summit\Summit;
@ -29,14 +29,14 @@ interface ISpeakerService
/**
* @param Summit $summit
* @param array $data
* @return Speaker
* @return PresentationSpeaker
* @throws ValidationException
*/
public function addSpeakerBySummit(Summit $summit, array $data);
/**
* @param array $data
* @return Speaker
* @return PresentationSpeaker
* @throws ValidationException
*/
public function addSpeaker(array $data);
@ -44,28 +44,28 @@ interface ISpeakerService
/**
* @param Summit $summit
* @param array $data
* @param Speaker $speaker
* @return Speaker
* @param PresentationSpeaker $speaker
* @return PresentationSpeaker
* @throws ValidationException
*/
public function updateSpeakerBySummit(Summit $summit, Speaker $speaker, array $data);
public function updateSpeakerBySummit(Summit $summit, PresentationSpeaker $speaker, array $data);
/**
* @param array $data
* @param Speaker $speaker
* @return Speaker
* @param PresentationSpeaker $speaker
* @return PresentationSpeaker
* @throws ValidationException
*/
public function updateSpeaker(Speaker $speaker, array $data);
public function updateSpeaker(PresentationSpeaker $speaker, array $data);
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @param Summit $summit
* @param string $reg_code
* @return SpeakerSummitRegistrationPromoCode
* @throws ValidationException
*/
public function registerSummitPromoCodeByValue(Speaker $speaker, Summit $summit, $reg_code);
public function registerSummitPromoCodeByValue(PresentationSpeaker $speaker, Summit $summit, $reg_code);
/**
* @param int $speaker_id
@ -78,12 +78,12 @@ interface ISpeakerService
public function addSpeakerPhoto($speaker_id, UploadedFile $file, $max_file_size = 10485760);
/**
* @param Speaker $speaker_from
* @param Speaker $speaker_to
* @param PresentationSpeaker $speaker_from
* @param PresentationSpeaker $speaker_to
* @param array $data
* @return void
*/
public function merge(Speaker $speaker_from, Speaker $speaker_to, array $data);
public function merge(PresentationSpeaker $speaker_from, PresentationSpeaker $speaker_to, array $data);
/**
* @param int $speaker_id

View File

@ -227,23 +227,40 @@ interface ISummitService
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @param string $role
* @throws EntityNotFoundException
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function addSpeaker2PresentationByRole(int $current_member_id, int $speaker_id, int $presentation_id, string $role);
public function addSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id);
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @param string $role
* @throws EntityNotFoundException
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeakerFromPresentationByRole(int $current_member_id, int $speaker_id, int $presentation_id, string $role);
public function addModerator2Presentation($current_member_id, $speaker_id, $presentation_id);
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeakerFromPresentation($current_member_id, $speaker_id, $presentation_id);
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function removeModeratorFromPresentation($current_member_id, $speaker_id, $presentation_id);
}

View File

@ -27,7 +27,7 @@ use models\summit\ISpeakerRepository;
use models\summit\ISummitEventRepository;
use models\summit\Presentation;
use models\summit\PresentationLink;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use models\summit\PresentationType;
use models\summit\PresentationVideo;
use libs\utils\ITransactionService;
@ -240,9 +240,9 @@ final class PresentationService
// check qty
$limit = $this->getSubmissionLimitFor($summit);
$count = count($current_speaker->getPresentationsBySelectionPlanAndRole($current_selection_plan, Speaker::RoleCreator)) +
count($current_speaker->getPresentationsBySelectionPlanAndRole($current_selection_plan, Speaker::RoleModerator)) +
count($current_speaker->getPresentationsBySelectionPlanAndRole($current_selection_plan, Speaker::RoleSpeaker));
$count = count($current_speaker->getPresentationsBySelectionPlanAndRole($current_selection_plan, PresentationSpeaker::ROLE_CREATOR)) +
count($current_speaker->getPresentationsBySelectionPlanAndRole($current_selection_plan, PresentationSpeaker::ROLE_MODERATOR)) +
count($current_speaker->getPresentationsBySelectionPlanAndRole($current_selection_plan, PresentationSpeaker::ROLE_SPEAKER));
if ($count >= $limit)
throw new ValidationException(trans(
@ -266,6 +266,7 @@ final class PresentationService
$data
);
return $presentation;
});
@ -333,7 +334,7 @@ final class PresentationService
* @param Summit $summit
* @param SelectionPlan $selection_plan
* @param Presentation $presentation
* @param Speaker $current_speaker
* @param PresentationSpeaker $current_speaker
* @param array $data
* @return Presentation
* @throws \Exception
@ -341,7 +342,7 @@ final class PresentationService
private function saveOrUpdatePresentation(Summit $summit,
SelectionPlan $selection_plan,
Presentation $presentation,
Speaker $current_speaker,
PresentationSpeaker $current_speaker,
array $data
)
{
@ -409,7 +410,7 @@ final class PresentationService
$presentation->setType($event_type);
$presentation->setCategory($track);
// add me as speaker
$presentation->addSpeakerByRole($current_speaker, Speaker::RoleSpeaker);
$presentation->addSpeaker($current_speaker);
if (isset($data['tags'])) {
$presentation->clearTags();

View File

@ -35,7 +35,7 @@ use models\summit\factories\SpeakerSelectionAnnouncementEmailTypeFactory;
use models\summit\ISpeakerRegistrationRequestRepository;
use models\summit\ISpeakerRepository;
use models\summit\ISpeakerSummitRegistrationPromoCodeRepository;
use models\summit\Speaker;
use models\summit\PresentationSpeaker;
use models\summit\PresentationSpeakerSummitAssistanceConfirmationRequest;
use models\summit\SpeakerExpertise;
use models\summit\SpeakerOrganizationalRole;
@ -149,14 +149,14 @@ final class SpeakerService
/**
* @param array $data
* @throws ValidationException
* @return Speaker
* @return PresentationSpeaker
*/
public function addSpeaker(array $data)
{
return $this->tx_service->transaction(function () use ($data) {
$speaker = new Speaker();
$speaker = new PresentationSpeaker();
$speaker->setCreatedFromApi(true);
$member_id = 0;
@ -222,7 +222,7 @@ final class SpeakerService
* @param Summit $summit
* @param array $data
* @throws ValidationException
* @return Speaker
* @return PresentationSpeaker
*/
public function addSpeakerBySummit(Summit $summit, array $data)
{
@ -247,11 +247,11 @@ final class SpeakerService
/**
* @param array $data
* @param Speaker $speaker
* @return Speaker
* @param PresentationSpeaker $speaker
* @return PresentationSpeaker
* @throws ValidationException
*/
public function updateSpeaker(Speaker $speaker, array $data)
public function updateSpeaker(PresentationSpeaker $speaker, array $data)
{
return $this->tx_service->transaction(function () use ($speaker, $data) {
$member_id = isset($data['member_id']) ? intval($data['member_id']) : null;
@ -283,12 +283,12 @@ final class SpeakerService
/**
* @param Summit $summit
* @param array $data
* @param Speaker $speaker
* @return Speaker
* @param PresentationSpeaker $speaker
* @return PresentationSpeaker
* @throws ValidationException
* @throws EntityNotFoundException
*/
public function updateSpeakerBySummit(Summit $summit, Speaker $speaker, array $data)
public function updateSpeakerBySummit(Summit $summit, PresentationSpeaker $speaker, array $data)
{
return $this->tx_service->transaction(function () use ($summit, $speaker, $data) {
@ -314,12 +314,12 @@ final class SpeakerService
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @param string $email
* @return SpeakerRegistrationRequest
* @throws ValidationException
*/
private function registerSpeaker(Speaker $speaker, $email)
private function registerSpeaker(PresentationSpeaker $speaker, $email)
{
if ($this->speaker_registration_request_repository->existByEmail($email))
@ -337,13 +337,13 @@ final class SpeakerService
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @param Summit $summit
* @param string $reg_code
* @return SpeakerSummitRegistrationPromoCode
* @throws ValidationException
*/
public function registerSummitPromoCodeByValue(Speaker $speaker, Summit $summit, $reg_code)
public function registerSummitPromoCodeByValue(PresentationSpeaker $speaker, Summit $summit, $reg_code)
{
return $this->tx_service->transaction(function () use ($speaker, $summit, $reg_code) {
@ -393,11 +393,11 @@ final class SpeakerService
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @param array $data
* @return Speaker
* @return PresentationSpeaker
*/
private function updateSpeakerMainData(Speaker $speaker, array $data)
private function updateSpeakerMainData(PresentationSpeaker $speaker, array $data)
{
if (isset($data['title']))
$speaker->setTitle(trim($data['title']));
@ -442,11 +442,11 @@ final class SpeakerService
}
/**
* @param Speaker $speaker
* @param PresentationSpeaker $speaker
* @param array $data
* @return Speaker
* @return PresentationSpeaker
*/
private function updateSpeakerRelations(Speaker $speaker, array $data)
private function updateSpeakerRelations(PresentationSpeaker $speaker, array $data)
{
// other_presentation_links
@ -579,13 +579,12 @@ final class SpeakerService
}
/**
* @param Speaker $speaker_from
* @param Speaker $speaker_to
* @param PresentationSpeaker $speaker_from
* @param PresentationSpeaker $speaker_to
* @param array $data
* @return mixed|void
* @throws \Exception
* @return void
*/
public function merge(Speaker $speaker_from, Speaker $speaker_to, array $data)
public function merge(PresentationSpeaker $speaker_from, PresentationSpeaker $speaker_to, array $data)
{
return $this->tx_service->transaction(function () use ($speaker_from, $speaker_to, $data) {
@ -887,7 +886,7 @@ final class SpeakerService
$speaker = $speaker_assistance->getSpeaker();
$role = $speaker->isModeratorFor($summit) ?
Speaker::RoleModerator : Speaker::RoleSpeaker;
PresentationSpeaker::RoleModerator : PresentationSpeaker::RoleSpeaker;
/*
if($speaker->announcementEmailAlreadySent($summit))

View File

@ -53,7 +53,6 @@ use models\summit\ISummitEventRepository;
use models\summit\ISummitRepository;
use models\summit\Presentation;
use models\summit\PresentationType;
use models\summit\Speaker;
use models\summit\Summit;
use models\summit\SummitAttendee;
use models\summit\SummitAttendeeTicket;
@ -857,38 +856,42 @@ final class SummitService extends AbstractService implements ISummitService
$event->setToRecord(isset($data['to_record'])?
filter_var($data['to_record'], FILTER_VALIDATE_BOOLEAN): 0);
// speakers by role
foreach (Speaker::$AvailableRoles as $availableRole){
if($event_type instanceof PresentationType && $event_type->shouldUseRole($availableRole)) {
// speakers
$speakers = isset($data['speakers']) ? $data['speakers'] : [];
$speakers = array_filter($speakers, function ($person) use ($availableRole) {
return ($person['role'] == $availableRole);
});
if($event_type instanceof PresentationType && $event_type->isUseSpeakers()) {
$speakers = isset($data['speakers']) ?
$data['speakers'] : [];
$speakerCount = count($speakers);
if ($event_type->isAreSpeakersMandatory() && count($speakers) == 0) {
throw new ValidationException('speakers are mandatory!');
}
if ($event_type->isRoleMandatory($availableRole) && $speakerCount == 0) {
throw new ValidationException(sprintf('%s are mandatory!', $availableRole));
if (count($speakers) > 0 && $event instanceof Presentation) {
$event->clearSpeakers();
foreach ($speakers as $speaker_id) {
$speaker = $this->speaker_repository->getById(intval($speaker_id));
if (is_null($speaker)) throw new EntityNotFoundException(sprintf('speaker id %s', $speaker_id));
$event->addSpeaker($speaker);
}
}
}
if($speakerCount < $event_type->getMinByRole($availableRole)){
throw new ValidationException(sprintf('%s min qty is %s!', $availableRole, $event_type->getMinByRole($availableRole)));
}
// moderator
if($speakerCount > $event_type->getMaxByRole($availableRole)){
throw new ValidationException(sprintf('%s max qty is %s!', $availableRole, $event_type->getMaxByRole($availableRole)));
}
if($event_type instanceof PresentationType && $event_type->isUseModerator()) {
$moderator_id = isset($data['moderator_speaker_id']) ? intval($data['moderator_speaker_id']) : 0;
if ($speakerCount > 0 && $event instanceof Presentation) {
if ($event_type->isModeratorMandatory() && $moderator_id == 0) {
throw new ValidationException('moderator_speaker_id is mandatory!');
}
$event->clearSpeakersByRole($availableRole);
foreach ($speakers as $speaker_dto) {
$speaker = $this->speaker_repository->getById(intval($speaker_dto['id']));
if (is_null($speaker)) throw new EntityNotFoundException(sprintf('speaker id %s', $speaker_dto['id']));
$event->addSpeakerByRole($speaker, $availableRole);
}
if ($moderator_id > 0) {
$speaker_id = intval($data['moderator_speaker_id']);
if ($speaker_id === 0) $event->unsetModerator();
else {
$moderator = $this->speaker_repository->getById($speaker_id);
if (is_null($moderator)) throw new EntityNotFoundException(sprintf('speaker id %s', $speaker_id));
$event->setModerator($moderator);
}
}
}
@ -982,9 +985,9 @@ final class SummitService extends AbstractService implements ISummitService
// check speakers collisions
if ($event instanceof Presentation && $c_event instanceof Presentation && $event->getId() != $c_event->getId()) {
foreach ($event->getSpeakers() as $current_presentation_speaker) {
foreach ($c_event->getSpeakers() as $c_presentation_speaker) {
if (intval($c_presentation_speaker->getSpeaker()->getId()) === intval($current_presentation_speaker->getSpeaker()->getId())) {
foreach ($event->getSpeakers() as $current_speaker) {
foreach ($c_event->getSpeakers() as $c_speaker) {
if (intval($c_speaker->getId()) === intval($current_speaker->getId())) {
throw new ValidationException
(
sprintf
@ -992,7 +995,7 @@ final class SummitService extends AbstractService implements ISummitService
"You can't publish Event %s (%s) on this timeframe, speaker %s its presention in room %s at this time.",
$event->getTitle(),
$event->getId(),
$current_presentation_speaker->getSpeaker()->getFullName(),
$current_speaker->getFullName(),
$c_event->getLocationName()
)
);
@ -1657,14 +1660,13 @@ final class SummitService extends AbstractService implements ISummitService
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @param string $role
* @throws EntityNotFoundException
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function addSpeaker2PresentationByRole(int $current_member_id, int $speaker_id, int $presentation_id, string $role)
public function addSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id, $role) {
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
$current_member = $this->member_repository->getById($current_member_id);
if(is_null($current_member))
throw new EntityNotFoundException(sprintf("member %s not found", $current_member_id));
@ -1686,18 +1688,6 @@ final class SummitService extends AbstractService implements ISummitService
$presentation_id
));
$presentationType = $presentation->getType();
if(!$presentationType instanceof PresentationType){
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
}
$maxByRole = $presentationType->getMaxByRole($role);
$countByRole = $presentation->getSpeakerCountByRole($role);
if($countByRole + 1 > $maxByRole){
throw new ValidationException(sprintf("%s max qty is %s.", $role, $maxByRole));
}
$speaker = $this->speaker_repository->getById(intval($speaker_id));
if (is_null($speaker))
throw new EntityNotFoundException(sprintf('speaker %s not found', $speaker_id));
@ -1705,8 +1695,7 @@ final class SummitService extends AbstractService implements ISummitService
if($presentation->getProgress() == Presentation::PHASE_TAGS)
$presentation->setProgress(Presentation::PHASE_SPEAKERS);
$presentation->addSpeakerByRole($speaker, $role);
$presentation->addSpeaker($speaker);
});
}
@ -1714,14 +1703,13 @@ final class SummitService extends AbstractService implements ISummitService
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @param string $role
* @throws EntityNotFoundException
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeakerFromPresentationByRole(int $current_member_id, int $speaker_id, int $presentation_id, string $role)
public function removeSpeakerFromPresentation($current_member_id, $speaker_id, $presentation_id)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id, $role) {
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
$current_member = $this->member_repository->getById($current_member_id);
if(is_null($current_member))
@ -1755,4 +1743,91 @@ final class SummitService extends AbstractService implements ISummitService
});
}
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function addModerator2Presentation($current_member_id, $speaker_id, $presentation_id)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
$current_member = $this->member_repository->getById($current_member_id);
if(is_null($current_member))
throw new EntityNotFoundException(sprintf("member %s not found", $current_member_id));
$current_speaker = $this->speaker_repository->getByMember($current_member);
if(is_null($current_speaker))
throw new EntityNotFoundException(sprintf("member %s does not has a speaker profile", $current_member_id));
$presentation = $this->event_repository->getById($presentation_id);
if(is_null($presentation))
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation instanceof Presentation)
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation->canEdit($current_speaker))
throw new ValidationException(sprintf("member %s can not edit presentation %s",
$current_member_id,
$presentation_id
));
$speaker = $this->speaker_repository->getById(intval($speaker_id));
if (is_null($speaker))
throw new EntityNotFoundException(sprintf('speaker %s not found', $speaker_id));
if($presentation->getProgress() == Presentation::PHASE_TAGS)
$presentation->setProgress(Presentation::PHASE_SPEAKERS);
$presentation->setModerator($speaker);
});
}
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function removeModeratorFromPresentation($current_member_id, $speaker_id, $presentation_id)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
$current_member = $this->member_repository->getById($current_member_id);
if(is_null($current_member))
throw new EntityNotFoundException(sprintf("member %s not found", $current_member_id));
$current_speaker = $this->speaker_repository->getByMember($current_member);
if(is_null($current_speaker))
throw new EntityNotFoundException(sprintf("member %s does not has a speaker profile", $current_member_id));
$presentation = $this->event_repository->getById($presentation_id);
if(is_null($presentation))
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation instanceof Presentation)
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation->canEdit($current_speaker))
throw new ValidationException(sprintf("member %s can not edit presentation %s",
$current_member_id,
$presentation_id
));
$speaker = $this->speaker_repository->getById(intval($speaker_id));
if (is_null($speaker))
throw new EntityNotFoundException(sprintf('speaker %s not found', $speaker_id));
if($presentation->getProgress() == Presentation::PHASE_TAGS)
$presentation->setProgress(Presentation::PHASE_SPEAKERS);
$presentation->unsetModerator();
});
}
}

View File

@ -85,7 +85,7 @@ return [
'SummitSelectionPlanService.deleteTrackGroupToSelectionPlan.TrackGroupNotFound' => 'track group :track_group_id not found on summit :summit_id',
// Presentations
'PresentationService.saveOrUpdatePresentation.trackNotFound' => 'track :track_id not found.',
'PresentationService.saveOrUpdatePresentation.eventTypeNotFound' => 'event type :type_id not found.',
'PresentationService.submitPresentation.eventTypeNotFound' => 'event type :type_id not found.',
'PresentationService.saveOrUpdatePresentation.trackQuestionNotFound' => 'extra question :question_id not found.',
'PresentationService.updatePresentationSubmission.PresentationNotFound' => 'presentation :presentation_id not found',
// track tag groups

View File

@ -148,7 +148,7 @@ final class DoctrineTest extends TestCase
$summit = $repo->getById(6);
$speakers = $summit->getSpeakers();
$sponsors = $summit->getSponsors();
$repo = EntityManager::getRepository(\models\summit\Speaker::class);
$repo = EntityManager::getRepository(\models\summit\PresentationSpeaker::class);
$speakers = $repo->getSpeakersBySummit($summit, new PagingInfo(1,10))->getItems();
$this->assertTrue(count($speakers) > 0);
$speaker = $speakers[0];
@ -157,7 +157,7 @@ final class DoctrineTest extends TestCase
}
public function testGetSpeakerPublishedRegularPresentations($speaker_id = 1759){
$repo1 = EntityManager::getRepository(\models\summit\Speaker::class);
$repo1 = EntityManager::getRepository(\models\summit\PresentationSpeaker::class);
$repo2 = EntityManager::getRepository(\models\summit\Summit::class);
$summit = $repo2->getById(23);
$speaker = $repo1->getById($speaker_id);
@ -170,7 +170,7 @@ final class DoctrineTest extends TestCase
}
public function testGetSpeakerAlternatePresentations($speaker_id = 70){
$repo1 = EntityManager::getRepository(\models\summit\Speaker::class);
$repo1 = EntityManager::getRepository(\models\summit\PresentationSpeaker::class);
$repo2 = EntityManager::getRepository(\models\summit\Summit::class);
$summit = $repo2->getById(23);
$speaker = $repo1->getById($speaker_id);
@ -183,7 +183,7 @@ final class DoctrineTest extends TestCase
}
public function testGetSpeakerRejectedPresentations($speaker_id = 70){
$repo1 = EntityManager::getRepository(\models\summit\Speaker::class);
$repo1 = EntityManager::getRepository(\models\summit\PresentationSpeaker::class);
$repo2 = EntityManager::getRepository(\models\summit\Summit::class);
$summit = $repo2->getById(23);
$speaker = $repo1->getById($speaker_id);

View File

@ -18,7 +18,7 @@ class OAuth2PresentationSubmissionTest extends ProtectedApiTest
* @param int $summit_id
* @return mixed
*/
public function testSubmitPresentation($summit_id = 26){
public function testSubmitPresentation($summit_id = 25){
$params = [
'id' => $summit_id,
];
@ -30,8 +30,8 @@ class OAuth2PresentationSubmissionTest extends ProtectedApiTest
'social_description' => 'this is a social description',
'level' => 'N/A',
'attendees_expected_learnt' => 'super duper',
'type_id' => 184,
'track_id' => 294,
'type_id' => 182,
'track_id' => 262,
'attending_media' => true,
'links' => ['https://www.google.com'],
'tags' => ['Upstream Development']
@ -61,36 +61,10 @@ class OAuth2PresentationSubmissionTest extends ProtectedApiTest
return $presentation;
}
public function testAddSpeaker2Presentation($summit_id = 26){
$new_presentation = $this->testSubmitPresentation($summit_id);
$params = [
'id' => $summit_id,
'presentation_id' => $new_presentation->id,
'speaker_id' => 1
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"PUT",
"OAuth2SummitSpeakersApiController@addSpeakerToMyPresentation",
$params,
[],
[],
[],
$headers,
''
);
}
/**
* @param int $summit_id
*/
public function testDeletePresentation($summit_id = 26){
public function testDeletePresentation($summit_id = 25){
$new_presentation = $this->testSubmitPresentation($summit_id);
$params = [
'id' => $summit_id,

View File

@ -74,7 +74,7 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
$this->assertResponseStatus(200);
}
public function testGetSummitExpandSchedule($summit_id = 25)
public function testGetSummit($summit_id = 25)
{
$params = [
@ -119,51 +119,6 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
$this->assertResponseStatus(200);
}
public function testGetSummitExpandSpeakers($summit_id = 25)
{
$params = [
'expand' => 'speakers',
'id' => $summit_id
];
$headers = array("HTTP_Authorization" => " Bearer " . $this->access_token);
$start = time();
$response = $this->action(
"GET",
"OAuth2SummitApiController@getSummit",
$params,
array(),
array(),
array(),
$headers
);
$end = time();
$delta = $end - $start;
echo "execution call " . $delta . " seconds ...";
$content = $response->getContent();
$summit = json_decode($content);
$this->assertTrue(!is_null($summit));
$this->assertResponseStatus(200);
$response = $this->action(
"GET",
"OAuth2SummitApiController@getSummit",
$params,
array(),
array(),
array(),
$headers
);
$content = $response->getContent();
$summit = json_decode($content);
$this->assertTrue(!is_null($summit));
$this->assertTrue(count($summit->schedule) > 0);
$this->assertResponseStatus(200);
}
public function testAddSummitAlreadyExistsName(){
$params = [
];

View File

@ -213,60 +213,44 @@ final class OAuth2SummitEventsApiTest extends ProtectedApiTest
$this->assertResponseStatus(412);
}
public function testPostPresentation($summit_id = 26)
public function testPostPresentation($start_date = 1461510000, $end_date = 1461513600)
{
$params =
[
'id' => $summit_id,
'expand' => 'speakers'
];
$headers = [
$params = array
(
'id' => 7,
);
$headers = array
(
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
);
$title = str_random(16).'_presentation';
$data = [
'title' => $title,
'description' => 'test description',
$data = array
(
'title' => 'test presentation BCN',
'description' => 'test presentation BCN',
'allow_feedback' => true,
'tags' => ['tag#1', 'tag#2'],
'type_id' => 184,
'track_id' => 294,
'speakers' => [
[
'id'=> 1,
'role' => 'Moderator'
],
[
'id'=> 2,
'role' => 'Moderator'
],
[
'id'=> 3,
'role' => 'Speaker'
],
],
];
'type_id' => 86,
'tags' => ['tag#1', 'tag#2'],
'speakers' => [1, 2, 3],
);
$response = $this->action
(
"POST",
"OAuth2SummitEventsApiController@addEvent",
$params,
[],
[],
[],
array(),
array(),
array(),
$headers,
json_encode($data)
);
$content = $response->getContent();
$this->assertResponseStatus(201);
$content = $response->getContent();
$presentation = json_decode($content);
$this->assertTrue($presentation->getId() > 0);

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash
php composer.phar dump-autoload --optimize;
php artisan doctrine:generate:proxies
php artisan doctrine:clear:metadata:cache
php artisan doctrine:clear:query:cache
php artisan doctrine:clear:result:cache
php artisan doctrine:generate:proxies -v
php artisan route:clear
php artisan route:cache