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

Allow to presentation to have more than one single moderator

Change-Id: I89ca267ee3462835aa23aea45bfad36d3d5b34f6
This commit is contained in:
Sebastian Marcet 2019-02-11 14:46:58 -03:00 committed by smarcet
parent ce9c70dd20
commit 812519f220
47 changed files with 966 additions and 635 deletions

View File

@ -13,7 +13,7 @@
**/
use Doctrine\ORM\Event\LifecycleEventArgs;
use Illuminate\Queue\SerializesModels;
use models\summit\PresentationSpeaker;
use models\summit\Speaker;
/**
* Class PresentationSpeakerEntityStateChanged
* @package App\Events
@ -24,7 +24,7 @@ class PresentationSpeakerEntityStateChanged extends Event
/**
* @var PresentationSpeaker
* @var Speaker
*/
protected $speaker;
@ -35,17 +35,17 @@ class PresentationSpeakerEntityStateChanged extends Event
/**
* SummitEventEntityStateChanged constructor.
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @param LifecycleEventArgs $args
*/
public function __construct(PresentationSpeaker $speaker, LifecycleEventArgs $args)
public function __construct(Speaker $speaker, LifecycleEventArgs $args)
{
$this->speaker = $speaker;
$this->args = $args;
}
/**
* @return PresentationSpeaker
* @return Speaker
*/
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("PresentationSpeaker");
$entity_event->setEntityClassName("Speaker");
$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("PresentationSpeaker");
$entity_event->setEntityClassName("Speaker");
$entity_event->setEntityId($event->getPresentationSpeaker()->getId());
$entity_event->setType('UPDATE');

View File

@ -333,6 +333,7 @@ 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();
@ -359,8 +360,7 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
'attendees_expected_learnt' => 'sometimes|string|max:1000',
'attending_media' => 'sometimes|boolean',
'to_record' => 'sometimes|boolean',
'speakers' => 'sometimes|int_array',
'moderator_speaker_id' => 'sometimes|integer',
'speakers' => 'sometimes|speakers_dto_array',
// 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());
return $this->created(SerializerRegistry::getInstance()->getSerializer($event)->serialize($expand));
}
catch (ValidationException $ex1) {
Log::warning($ex1);
@ -414,7 +414,8 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
if (is_null($summit)) return $this->error404();
if(!Request::isJson()) return $this->error400();
$data = Input::json();
$data = Input::json();
$expand = Request::input('expand', '');
$current_member = null;
$member_id = $this->resource_server_context->getCurrentUserExternalId();
@ -444,8 +445,7 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
'attendees_expected_learnt' => 'sometimes|string|max:1000',
'attending_media' => 'sometimes|boolean',
'to_record' => 'sometimes|boolean',
'speakers' => 'sometimes|int_array',
'moderator_speaker_id' => 'sometimes|integer',
'speakers' => 'sometimes|speakers_dto_array',
// 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());
return $this->ok(SerializerRegistry::getInstance()->getSerializer($event)->serialize($expand));
}
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\PresentationSpeaker;
use models\summit\Speaker;
use ModelSerializers\ISerializerTypeSelector;
use ModelSerializers\SerializerRegistry;
use services\model\ISpeakerService;
@ -950,13 +950,13 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
switch ($role) {
case 'creator':
$role = PresentationSpeaker::ROLE_CREATOR;
$role = Speaker::RoleCreator;
break;
case 'speaker':
$role = PresentationSpeaker::ROLE_SPEAKER;
$role = Speaker::RoleSpeaker;
break;
case 'moderator':
$role = PresentationSpeaker::ROLE_MODERATOR;
$role = Speaker::RoleModerator;
break;
}
$presentations = $speaker->getPresentationsBySelectionPlanAndRole($selection_plan, $role);
@ -1009,13 +1009,13 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
switch ($role) {
case 'creator':
$role = PresentationSpeaker::ROLE_CREATOR;
$role = Speaker::RoleCreator;
break;
case 'speaker':
$role = PresentationSpeaker::ROLE_SPEAKER;
$role = Speaker::RoleSpeaker;
break;
case 'moderator':
$role = PresentationSpeaker::ROLE_MODERATOR;
$role = Speaker::RoleModerator;
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->addSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id);
$this->summit_service->addSpeaker2PresentationByRole($current_member_id, $speaker_id, $presentation_id, Speaker::RoleSpeaker);
return $this->updated();
@ -1080,7 +1080,7 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
if (is_null($current_member_id))
return $this->error403();
$this->summit_service->addModerator2Presentation($current_member_id, $speaker_id, $presentation_id);
$this->summit_service->addSpeaker2PresentationByRole($current_member_id, $speaker_id, $presentation_id, Speaker::RoleModerator);
return $this->updated();
@ -1107,7 +1107,7 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
if (is_null($current_member_id))
return $this->error403();
$this->summit_service->removeSpeakerFromPresentation($current_member_id, $speaker_id, $presentation_id);
$this->summit_service->removeSpeakerFromPresentationByRole($current_member_id, $speaker_id, $presentation_id, Speaker::RoleSpeaker);
return $this->deleted();
@ -1134,7 +1134,7 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
if (is_null($current_member_id))
return $this->error403();
$this->summit_service->removeModeratorFromPresentation($current_member_id, $speaker_id, $presentation_id);
$this->summit_service->removeSpeakerFromPresentationByRole($current_member_id, $speaker_id, $presentation_id, Speaker::RoleModerator);
return $this->deleted();
@ -1150,4 +1150,5 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
}
}
}

View File

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

View File

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

View File

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

View File

@ -22,7 +22,6 @@ 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',
@ -35,7 +34,6 @@ class PresentationSerializer extends SummitEventSerializer
protected static $allowed_fields = [
'track_id',
'creator_id',
'moderator_speaker_id',
'selection_plan_id',
'level',
'problem_addressed',
@ -72,9 +70,12 @@ class PresentationSerializer extends SummitEventSerializer
$values = parent::serialize($expand, $fields, $relations, $params);
if(in_array('speakers', $relations)) {
$values['speakers'] = $presentation->getSpeakerIds();
$values['speakers'] = $presentation->getSpeakerIdsAndRole();
}
// todo: legacy should be removed
$values['moderator_speaker_id'] = 0;
if(in_array('slides', $relations))
{
$slides = array();
@ -122,13 +123,13 @@ class PresentationSerializer extends SummitEventSerializer
switch (trim($relation)) {
case 'speakers': {
$speakers = [];
foreach ($presentation->getSpeakers() as $s) {
$speakers[] = SerializerRegistry::getInstance()->getSerializer($s)->serialize();
foreach ($presentation->getSpeakers() as $presentation_speaker) {
$speakers[] = SerializerRegistry::getInstance()->getSerializer($presentation_speaker)->serialize
(
'speaker'
);
}
$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

@ -0,0 +1,61 @@
<?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\PresentationSpeaker;
use models\summit\Speaker;
/**
* Class AdminPresentationSpeakerSerializer
* Class AdminSpeakerSerializer
* @package ModelSerializers
*/
final class AdminPresentationSpeakerSerializer extends PresentationSpeakerSerializer
final class AdminSpeakerSerializer extends SpeakerSerializer
{
protected static $array_mappings = [
'Notes'=> 'notes:json_string'
];
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @return null|string|string[]
*/
protected function getSpeakerEmail(PresentationSpeaker $speaker){
protected function getSpeakerEmail(Speaker $speaker){
return $speaker->getEmail();
}
@ -42,7 +42,7 @@ final class AdminPresentationSpeakerSerializer extends PresentationSpeakerSerial
if(!count($relations)) $relations = $this->getAllowedRelations();
$speaker = $this->object;
if(!$speaker instanceof PresentationSpeaker) return [];
if(!$speaker instanceof Speaker) 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\PresentationSpeaker;
use models\summit\Speaker;
/**
* Class PresentationSpeakerSerializer
* Class SpeakerSerializer
* @package ModelSerializers
*/
class PresentationSpeakerSerializer extends SilverStripeSerializer
class SpeakerSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'FirstName' => 'first_name:json_string',
@ -40,10 +40,10 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
];
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @return null|string|string[]
*/
protected function getSpeakerEmail(PresentationSpeaker $speaker){
protected function getSpeakerEmail(Speaker $speaker){
$email = $speaker->getEmail();
$em = explode("@", $email);
$name = implode(array_slice($em, 0, count($em) - 1), '@');
@ -65,15 +65,16 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
if(!count($relations)) $relations = $this->getAllowedRelations();
$speaker = $this->object;
if(!$speaker instanceof PresentationSpeaker) return [];
if(!$speaker instanceof Speaker) 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->getPresentationIds($summit_id, $published);
$values['moderated_presentations'] = $speaker->getModeratedPresentationIds($summit_id, $published);
$values['presentations'] = $speaker->getPresentationIdsAndRole($summit_id, $published);
// todo: legacy field remove it
$values['moderated_presentations'] = [];
}
$values['pic'] = Config::get("server.assets_base_url", 'https://www.openstack.org/') . 'profile_images/speakers/' . $speaker->getId();
@ -149,16 +150,12 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
switch (trim($relation)) {
case 'presentations': {
$presentations = [];
foreach ($speaker->getPresentations($summit_id, $published) as $p) {
foreach ($speaker->getSpeakerPresentations($summit_id, $published) as $p) {
$presentations[] = SerializerRegistry::getInstance()->getSerializer($p)->serialize();
}
$values['presentations'] = $presentations;
$moderated_presentations = [];
foreach ($speaker->getModeratedPresentations($summit_id, $published) as $p) {
$moderated_presentations[] = SerializerRegistry::getInstance()->getSerializer($p)->serialize();
}
$values['moderated_presentations'] = $presentations;
// todo: legacy field remove it
$values['moderated_presentations'] = [];
}
break;
case 'member': {

View File

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

View File

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

View File

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

View File

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

View File

@ -113,14 +113,6 @@ 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")
@ -142,16 +134,8 @@ class Presentation extends SummitEvent
private $materials;
/**
* @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")
*
* }
* )
* @ORM\OneToMany(targetEntity="PresentationSpeaker", mappedBy="presentation", cascade={"persist"}, orphanRemoval=true)
* @var PresentationSpeaker[]
*/
private $speakers;
@ -267,25 +251,67 @@ class Presentation extends SummitEvent
}
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @param string $role
* @return $this
*/
public function addSpeaker(PresentationSpeaker $speaker){
if($this->speakers->contains($speaker)) return;
$this->speakers->add($speaker);
$speaker->addPresentation($this);
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 clearSpeakers(){
$this->speakers->clear();
/**
* @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;
}
/**
* @return int[]
*/
public function getSpeakerIds()
public function getSpeakerIds(): array
{
return $this->speakers->map(function($entity) {
return $entity->getId();
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()
];
})->toArray();
}
@ -344,19 +370,53 @@ class Presentation extends SummitEvent
}
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @return $this
*/
public function removeSpeaker(PresentationSpeaker $speaker){
if(!$this->speakers->contains($speaker)) return;
$this->speakers->removeElement($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();
}
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @param string $role
* @return bool
*/
public function isSpeaker(PresentationSpeaker $speaker){
return $this->speakers->contains($speaker);
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();
}
/**
@ -406,17 +466,6 @@ 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
@ -430,27 +479,6 @@ 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
*/
@ -714,13 +742,13 @@ class Presentation extends SummitEvent
}
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @return bool
*/
public function canEdit(PresentationSpeaker $speaker){
public function canEdit(Speaker $speaker){
if($this->getCreatorId() == $speaker->getMemberId()) return true;
if($this->getModeratorId() == $speaker->getId()) return true;
if($this->isSpeaker($speaker)) return true;
if($this->isSpeaker($speaker, Speaker::RoleModerator)) return true;
if($this->isSpeaker($speaker, Speaker::RoleSpeaker)) return true;
return false;
}

View File

@ -0,0 +1,120 @@
<?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,6 +156,22 @@ 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
*/
@ -164,6 +180,54 @@ 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="PresentationSpeaker", inversedBy="other_presentation_links")
* @ORM\ManyToOne(targetEntity="Speaker", inversedBy="other_presentation_links")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var PresentationSpeaker
* @var Speaker
*/
private $speaker;
@ -83,7 +83,7 @@ class SpeakerPresentationLink extends SilverstripeBaseModel
}
/**
* @return PresentationSpeaker
* @return Speaker
*/
public function getSpeaker()
{
@ -91,7 +91,7 @@ class SpeakerPresentationLink extends SilverstripeBaseModel
}
/**
* @param PresentationSpeaker $speaker
* @param Speaker $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\PresentationSpeaker;
use models\summit\Speaker;
use models\summit\PresentationSpeakerSummitAssistanceConfirmationRequest;
use models\summit\Summit;
@ -23,11 +23,11 @@ final class PresentationSpeakerSummitAssistanceConfirmationRequestFactory
{
/**
* @param Summit $summit
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @param array $data
* @return PresentationSpeakerSummitAssistanceConfirmationRequest
*/
public static function build(Summit $summit, PresentationSpeaker $speaker, array $data){
public static function build(Summit $summit, Speaker $speaker, array $data){
$request = new PresentationSpeakerSummitAssistanceConfirmationRequest();
$request->setSummit($summit);

View File

@ -1,5 +1,5 @@
<?php namespace models\summit\factories;
use models\summit\PresentationSpeaker;
use models\summit\Speaker;
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, PresentationSpeaker $speaker, $role = PresentationSpeaker::RoleSpeaker)
public static function build(Summit $summit, Speaker $speaker, $role = Speaker::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="PresentationSpeaker", inversedBy="promo_codes")
* @ORM\ManyToOne(targetEntity="Speaker", inversedBy="promo_codes")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var PresentationSpeaker
* @var Speaker
*/
protected $speaker;
@ -53,7 +53,7 @@ class SpeakerSummitRegistrationPromoCode extends SummitRegistrationPromoCode
}
/**
* @return PresentationSpeaker
* @return Speaker
*/
public function getSpeaker()
{
@ -61,7 +61,7 @@ class SpeakerSummitRegistrationPromoCode extends SummitRegistrationPromoCode
}
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
*/
public function setSpeaker($speaker)
{

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -36,10 +36,20 @@ 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',
@ -74,8 +84,7 @@ class AppServiceProvider extends ServiceProvider
'attendees_expected_learnt' => 'sometimes|string|max:100',
'feature_cloud' => 'sometimes|boolean',
'to_record' => 'sometimes|boolean',
'speakers' => 'sometimes|int_array',
'moderator_speaker_id' => 'sometimes|integer',
'speakers' => 'sometimes|speakers_dto_array',
// group event
'groups' => 'sometimes|int_array',
];
@ -115,6 +124,33 @@ 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\PresentationSpeaker::class);
return EntityManager::getRepository(\models\summit\Speaker::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\PresentationSpeaker;
use models\summit\Speaker;
use models\summit\Summit;
use App\Repositories\SilverStripeDoctrineRepository;
use utils\Filter;
@ -77,7 +77,7 @@ FROM (
IFNULL(S.FirstName, M.FirstName) AS FirstName,
IFNULL(S.LastName, M.Surname) AS LastName,
IFNULL(M.Email, R.Email) AS Email
FROM PresentationSpeaker S
FROM Speaker S
LEFT JOIN Member M ON M.ID = S.MemberID
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
WHERE
@ -93,7 +93,7 @@ FROM (
IFNULL(S.FirstName, M.FirstName) AS FirstName,
IFNULL(S.LastName, M.Surname) AS LastName,
IFNULL(M.Email, R.Email) AS Email
FROM PresentationSpeaker S
FROM Speaker S
LEFT JOIN Member M ON M.ID = S.MemberID
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
WHERE
@ -109,7 +109,7 @@ FROM (
IFNULL(S.FirstName, M.FirstName) AS FirstName,
IFNULL(S.LastName, M.Surname) AS LastName,
IFNULL(M.Email, R.Email) AS Email
FROM PresentationSpeaker S
FROM Speaker S
LEFT JOIN Member M ON M.ID = S.MemberID
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
WHERE
@ -157,7 +157,7 @@ FROM (
IFNULL(S.LastName, M.Surname) AS LastName,
IFNULL(M.Email,R.Email) AS Email,
S.PhotoID
FROM PresentationSpeaker S
FROM Speaker S
LEFT JOIN Member M ON M.ID = S.MemberID
LEFT JOIN File F ON F.ID = S.PhotoID
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
@ -190,7 +190,7 @@ FROM (
IFNULL(S.LastName, M.Surname) AS LastName,
IFNULL(M.Email,R.Email) AS Email,
S.PhotoID
FROM PresentationSpeaker S
FROM Speaker S
LEFT JOIN Member M ON M.ID = S.MemberID
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
WHERE
@ -222,7 +222,7 @@ FROM (
IFNULL(S.LastName, M.Surname) AS LastName,
IFNULL(M.Email,R.Email) AS Email,
S.PhotoID
FROM PresentationSpeaker S
FROM Speaker S
LEFT JOIN Member M ON M.ID = S.MemberID
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
WHERE
@ -237,7 +237,7 @@ SUMMIT_SPEAKERS
SQL;
/*$rsm = new ResultSetMapping();
$rsm->addEntityResult(\models\summit\PresentationSpeaker::class, 's');
$rsm->addEntityResult(\models\summit\Speaker::class, 's');
$rsm->addJoinedEntityResult(\models\main\File::class,'p', 's', 'photo');
$rsm->addJoinedEntityResult(\models\main\Member::class,'m', 's', 'member');
@ -253,7 +253,7 @@ SQL;
$rsm->addFieldResult('m', 'MemberID', 'id');*/
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata(\models\summit\PresentationSpeaker::class, 's', ['Title' => 'SpeakerTitle']);
$rsm->addRootEntityFromClassMetadata(\models\summit\Speaker::class, 's', ['Title' => 'SpeakerTitle']);
// build rsm here
$native_query = $this->_em->createNativeQuery($query, $rsm);
@ -314,7 +314,7 @@ FROM (
IFNULL(S.FirstName, M.FirstName) AS FirstName,
IFNULL(S.LastName, M.Surname) AS LastName,
IFNULL(M.Email,R.Email) AS Email
FROM PresentationSpeaker S
FROM Speaker S
LEFT JOIN Member M ON M.ID = S.MemberID
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
)
@ -356,7 +356,7 @@ FROM (
IFNULL(S.LastName, M.Surname) AS LastName,
IFNULL(M.Email,R.Email) AS Email,
S.PhotoID
FROM PresentationSpeaker S
FROM Speaker S
LEFT JOIN Member M ON M.ID = S.MemberID
LEFT JOIN File F ON F.ID = S.PhotoID
LEFT JOIN SpeakerRegistrationRequest R ON R.SpeakerID = S.ID
@ -366,7 +366,7 @@ SUMMIT_SPEAKERS
SQL;
/*$rsm = new ResultSetMapping();
$rsm->addEntityResult(\models\summit\PresentationSpeaker::class, 's');
$rsm->addEntityResult(\models\summit\Speaker::class, 's');
$rsm->addJoinedEntityResult(\models\main\File::class,'p', 's', 'photo');
$rsm->addJoinedEntityResult(\models\main\Member::class,'m', 's', 'member');
@ -382,7 +382,7 @@ SQL;
$rsm->addFieldResult('m', 'MemberID', 'id');*/
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata(\models\summit\PresentationSpeaker::class, 's', ['Title' => 'SpeakerTitle']);
$rsm->addRootEntityFromClassMetadata(\models\summit\Speaker::class, 's', ['Title' => 'SpeakerTitle']);
// build rsm here
$native_query = $this->_em->createNativeQuery($query, $rsm);
@ -402,19 +402,19 @@ SQL;
*/
protected function getBaseEntity()
{
return PresentationSpeaker::class;
return Speaker::class;
}
/**
* @param Member $member
* @return PresentationSpeaker
* @return Speaker
*/
public function getByMember(Member $member)
{
return $this->getEntityManager()
->createQueryBuilder()
->select("s")
->from(PresentationSpeaker::class, "s")
->from(Speaker::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\PresentationSpeaker;
use models\summit\Speaker;
use models\summit\SpeakerSummitRegistrationPromoCode;
use models\summit\Summit;
@ -33,11 +33,11 @@ final class DoctrineSpeakerSummitRegistrationPromoCodeRepository
}
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @param Summit $summit
* @return SpeakerSummitRegistrationPromoCode
*/
public function getBySpeakerAndSummit(PresentationSpeaker $speaker, Summit $summit)
public function getBySpeakerAndSummit(Speaker $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\PresentationSpeaker;
use models\summit\Speaker;
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 PresentationSpeaker
* @return Speaker
* @throws ValidationException
*/
public function addSpeakerBySummit(Summit $summit, array $data);
/**
* @param array $data
* @return PresentationSpeaker
* @return Speaker
* @throws ValidationException
*/
public function addSpeaker(array $data);
@ -44,28 +44,28 @@ interface ISpeakerService
/**
* @param Summit $summit
* @param array $data
* @param PresentationSpeaker $speaker
* @return PresentationSpeaker
* @param Speaker $speaker
* @return Speaker
* @throws ValidationException
*/
public function updateSpeakerBySummit(Summit $summit, PresentationSpeaker $speaker, array $data);
public function updateSpeakerBySummit(Summit $summit, Speaker $speaker, array $data);
/**
* @param array $data
* @param PresentationSpeaker $speaker
* @return PresentationSpeaker
* @param Speaker $speaker
* @return Speaker
* @throws ValidationException
*/
public function updateSpeaker(PresentationSpeaker $speaker, array $data);
public function updateSpeaker(Speaker $speaker, array $data);
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @param Summit $summit
* @param string $reg_code
* @return SpeakerSummitRegistrationPromoCode
* @throws ValidationException
*/
public function registerSummitPromoCodeByValue(PresentationSpeaker $speaker, Summit $summit, $reg_code);
public function registerSummitPromoCodeByValue(Speaker $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 PresentationSpeaker $speaker_from
* @param PresentationSpeaker $speaker_to
* @param Speaker $speaker_from
* @param Speaker $speaker_to
* @param array $data
* @return void
*/
public function merge(PresentationSpeaker $speaker_from, PresentationSpeaker $speaker_to, array $data);
public function merge(Speaker $speaker_from, Speaker $speaker_to, array $data);
/**
* @param int $speaker_id

View File

@ -227,40 +227,23 @@ interface ISummitService
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @param string $role
* @throws EntityNotFoundException
* @throws ValidationException
* @return void
*/
public function addSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id);
public function addSpeaker2PresentationByRole(int $current_member_id, int $speaker_id, int $presentation_id, string $role);
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @param string $role
* @throws EntityNotFoundException
* @throws ValidationException
* @return void
*/
public function addModerator2Presentation($current_member_id, $speaker_id, $presentation_id);
public function removeSpeakerFromPresentationByRole(int $current_member_id, int $speaker_id, int $presentation_id, string $role);
/**
* @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\PresentationSpeaker;
use models\summit\Speaker;
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, PresentationSpeaker::ROLE_CREATOR)) +
count($current_speaker->getPresentationsBySelectionPlanAndRole($current_selection_plan, PresentationSpeaker::ROLE_MODERATOR)) +
count($current_speaker->getPresentationsBySelectionPlanAndRole($current_selection_plan, PresentationSpeaker::ROLE_SPEAKER));
$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));
if ($count >= $limit)
throw new ValidationException(trans(
@ -266,7 +266,6 @@ final class PresentationService
$data
);
return $presentation;
});
@ -334,7 +333,7 @@ final class PresentationService
* @param Summit $summit
* @param SelectionPlan $selection_plan
* @param Presentation $presentation
* @param PresentationSpeaker $current_speaker
* @param Speaker $current_speaker
* @param array $data
* @return Presentation
* @throws \Exception
@ -342,7 +341,7 @@ final class PresentationService
private function saveOrUpdatePresentation(Summit $summit,
SelectionPlan $selection_plan,
Presentation $presentation,
PresentationSpeaker $current_speaker,
Speaker $current_speaker,
array $data
)
{
@ -410,7 +409,7 @@ final class PresentationService
$presentation->setType($event_type);
$presentation->setCategory($track);
// add me as speaker
$presentation->addSpeaker($current_speaker);
$presentation->addSpeakerByRole($current_speaker, Speaker::RoleSpeaker);
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\PresentationSpeaker;
use models\summit\Speaker;
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 PresentationSpeaker
* @return Speaker
*/
public function addSpeaker(array $data)
{
return $this->tx_service->transaction(function () use ($data) {
$speaker = new PresentationSpeaker();
$speaker = new Speaker();
$speaker->setCreatedFromApi(true);
$member_id = 0;
@ -222,7 +222,7 @@ final class SpeakerService
* @param Summit $summit
* @param array $data
* @throws ValidationException
* @return PresentationSpeaker
* @return Speaker
*/
public function addSpeakerBySummit(Summit $summit, array $data)
{
@ -247,11 +247,11 @@ final class SpeakerService
/**
* @param array $data
* @param PresentationSpeaker $speaker
* @return PresentationSpeaker
* @param Speaker $speaker
* @return Speaker
* @throws ValidationException
*/
public function updateSpeaker(PresentationSpeaker $speaker, array $data)
public function updateSpeaker(Speaker $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 PresentationSpeaker $speaker
* @return PresentationSpeaker
* @param Speaker $speaker
* @return Speaker
* @throws ValidationException
* @throws EntityNotFoundException
*/
public function updateSpeakerBySummit(Summit $summit, PresentationSpeaker $speaker, array $data)
public function updateSpeakerBySummit(Summit $summit, Speaker $speaker, array $data)
{
return $this->tx_service->transaction(function () use ($summit, $speaker, $data) {
@ -314,12 +314,12 @@ final class SpeakerService
}
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @param string $email
* @return SpeakerRegistrationRequest
* @throws ValidationException
*/
private function registerSpeaker(PresentationSpeaker $speaker, $email)
private function registerSpeaker(Speaker $speaker, $email)
{
if ($this->speaker_registration_request_repository->existByEmail($email))
@ -337,13 +337,13 @@ final class SpeakerService
}
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @param Summit $summit
* @param string $reg_code
* @return SpeakerSummitRegistrationPromoCode
* @throws ValidationException
*/
public function registerSummitPromoCodeByValue(PresentationSpeaker $speaker, Summit $summit, $reg_code)
public function registerSummitPromoCodeByValue(Speaker $speaker, Summit $summit, $reg_code)
{
return $this->tx_service->transaction(function () use ($speaker, $summit, $reg_code) {
@ -393,11 +393,11 @@ final class SpeakerService
}
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @param array $data
* @return PresentationSpeaker
* @return Speaker
*/
private function updateSpeakerMainData(PresentationSpeaker $speaker, array $data)
private function updateSpeakerMainData(Speaker $speaker, array $data)
{
if (isset($data['title']))
$speaker->setTitle(trim($data['title']));
@ -442,11 +442,11 @@ final class SpeakerService
}
/**
* @param PresentationSpeaker $speaker
* @param Speaker $speaker
* @param array $data
* @return PresentationSpeaker
* @return Speaker
*/
private function updateSpeakerRelations(PresentationSpeaker $speaker, array $data)
private function updateSpeakerRelations(Speaker $speaker, array $data)
{
// other_presentation_links
@ -579,12 +579,13 @@ final class SpeakerService
}
/**
* @param PresentationSpeaker $speaker_from
* @param PresentationSpeaker $speaker_to
* @param Speaker $speaker_from
* @param Speaker $speaker_to
* @param array $data
* @return void
* @return mixed|void
* @throws \Exception
*/
public function merge(PresentationSpeaker $speaker_from, PresentationSpeaker $speaker_to, array $data)
public function merge(Speaker $speaker_from, Speaker $speaker_to, array $data)
{
return $this->tx_service->transaction(function () use ($speaker_from, $speaker_to, $data) {
@ -886,7 +887,7 @@ final class SpeakerService
$speaker = $speaker_assistance->getSpeaker();
$role = $speaker->isModeratorFor($summit) ?
PresentationSpeaker::RoleModerator : PresentationSpeaker::RoleSpeaker;
Speaker::RoleModerator : Speaker::RoleSpeaker;
/*
if($speaker->announcementEmailAlreadySent($summit))

View File

@ -53,6 +53,7 @@ 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;
@ -856,42 +857,38 @@ final class SummitService extends AbstractService implements ISummitService
$event->setToRecord(isset($data['to_record'])?
filter_var($data['to_record'], FILTER_VALIDATE_BOOLEAN): 0);
// speakers
// speakers by role
foreach (Speaker::$AvailableRoles as $availableRole){
if($event_type instanceof PresentationType && $event_type->shouldUseRole($availableRole)) {
if($event_type instanceof PresentationType && $event_type->isUseSpeakers()) {
$speakers = isset($data['speakers']) ?
$data['speakers'] : [];
$speakers = isset($data['speakers']) ? $data['speakers'] : [];
$speakers = array_filter($speakers, function ($person) use ($availableRole) {
return ($person['role'] == $availableRole);
});
if ($event_type->isAreSpeakersMandatory() && count($speakers) == 0) {
throw new ValidationException('speakers are mandatory!');
}
$speakerCount = count($speakers);
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 ($event_type->isRoleMandatory($availableRole) && $speakerCount == 0) {
throw new ValidationException(sprintf('%s are mandatory!', $availableRole));
}
}
}
// moderator
if($speakerCount < $event_type->getMinByRole($availableRole)){
throw new ValidationException(sprintf('%s min qty is %s!', $availableRole, $event_type->getMinByRole($availableRole)));
}
if($event_type instanceof PresentationType && $event_type->isUseModerator()) {
$moderator_id = isset($data['moderator_speaker_id']) ? intval($data['moderator_speaker_id']) : 0;
if($speakerCount > $event_type->getMaxByRole($availableRole)){
throw new ValidationException(sprintf('%s max qty is %s!', $availableRole, $event_type->getMaxByRole($availableRole)));
}
if ($event_type->isModeratorMandatory() && $moderator_id == 0) {
throw new ValidationException('moderator_speaker_id is mandatory!');
}
if ($speakerCount > 0 && $event instanceof Presentation) {
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);
$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);
}
}
}
}
@ -985,9 +982,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_speaker) {
foreach ($c_event->getSpeakers() as $c_speaker) {
if (intval($c_speaker->getId()) === intval($current_speaker->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())) {
throw new ValidationException
(
sprintf
@ -995,7 +992,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_speaker->getFullName(),
$current_presentation_speaker->getSpeaker()->getFullName(),
$c_event->getLocationName()
)
);
@ -1660,13 +1657,14 @@ final class SummitService extends AbstractService implements ISummitService
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @param string $role
* @throws EntityNotFoundException
* @throws ValidationException
* @return void
*/
public function addSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id)
public function addSpeaker2PresentationByRole(int $current_member_id, int $speaker_id, int $presentation_id, string $role)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id, $role) {
$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));
@ -1688,6 +1686,18 @@ 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));
@ -1695,7 +1705,8 @@ final class SummitService extends AbstractService implements ISummitService
if($presentation->getProgress() == Presentation::PHASE_TAGS)
$presentation->setProgress(Presentation::PHASE_SPEAKERS);
$presentation->addSpeaker($speaker);
$presentation->addSpeakerByRole($speaker, $role);
});
}
@ -1703,13 +1714,14 @@ final class SummitService extends AbstractService implements ISummitService
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @param string $role
* @throws EntityNotFoundException
* @throws ValidationException
* @return void
*/
public function removeSpeakerFromPresentation($current_member_id, $speaker_id, $presentation_id)
public function removeSpeakerFromPresentationByRole(int $current_member_id, int $speaker_id, int $presentation_id, string $role)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id, $role) {
$current_member = $this->member_repository->getById($current_member_id);
if(is_null($current_member))
@ -1743,91 +1755,4 @@ 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.submitPresentation.eventTypeNotFound' => 'event type :type_id not found.',
'PresentationService.saveOrUpdatePresentation.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\PresentationSpeaker::class);
$repo = EntityManager::getRepository(\models\summit\Speaker::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\PresentationSpeaker::class);
$repo1 = EntityManager::getRepository(\models\summit\Speaker::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\PresentationSpeaker::class);
$repo1 = EntityManager::getRepository(\models\summit\Speaker::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\PresentationSpeaker::class);
$repo1 = EntityManager::getRepository(\models\summit\Speaker::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 = 25){
public function testSubmitPresentation($summit_id = 26){
$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' => 182,
'track_id' => 262,
'type_id' => 184,
'track_id' => 294,
'attending_media' => true,
'links' => ['https://www.google.com'],
'tags' => ['Upstream Development']
@ -61,10 +61,36 @@ 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 = 25){
public function testDeletePresentation($summit_id = 26){
$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 testGetSummit($summit_id = 25)
public function testGetSummitExpandSchedule($summit_id = 25)
{
$params = [
@ -119,6 +119,51 @@ 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,44 +213,60 @@ final class OAuth2SummitEventsApiTest extends ProtectedApiTest
$this->assertResponseStatus(412);
}
public function testPostPresentation($start_date = 1461510000, $end_date = 1461513600)
public function testPostPresentation($summit_id = 26)
{
$params = array
(
'id' => 7,
);
$params =
[
'id' => $summit_id,
'expand' => 'speakers'
];
$headers = [
$headers = array
(
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
);
];
$data = array
(
'title' => 'test presentation BCN',
'description' => 'test presentation BCN',
$title = str_random(16).'_presentation';
$data = [
'title' => $title,
'description' => 'test description',
'allow_feedback' => true,
'type_id' => 86,
'tags' => ['tag#1', 'tag#2'],
'speakers' => [1, 2, 3],
);
'tags' => ['tag#1', 'tag#2'],
'type_id' => 184,
'track_id' => 294,
'speakers' => [
[
'id'=> 1,
'role' => 'Moderator'
],
[
'id'=> 2,
'role' => 'Moderator'
],
[
'id'=> 3,
'role' => 'Speaker'
],
],
];
$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