Added Presentation Disclaimer Logic

Change-Id: I9ab1c1e982e51c7159cd2c7f44a30c0ca9785810
Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
smarcet 2021-05-28 13:22:06 -03:00
parent e107db8ba2
commit 3e45fdb025
10 changed files with 342 additions and 244 deletions

View File

@ -61,8 +61,13 @@ class SynchPresentationActions implements ShouldQueue
Log::debug(sprintf("SynchPresentationActions::handle event id %s", $this->event_id));
$tx_service->transaction(function() use($repository){
$event = $repository->getById($this->event_id);
if(is_null($event) || !$event instanceof Presentation)
throw new EntityNotFoundException(sprintf("Event %s is not a presentation", $this->event_id));
if(is_null($event))
throw new EntityNotFoundException(sprintf("Event %s ", $this->event_id));
if(!$event instanceof Presentation){
return;
}
$event->getSummit()->synchAllPresentationActions();
});

View File

@ -32,6 +32,8 @@ class PresentationSerializer extends SummitEventSerializer
'Slug' => 'slug:json_string',
'SelectionStatus' => 'selection_status:string',
'WillAllSpeakersAttend' => 'will_all_speakers_attend:json_boolean',
'DisclaimerAcceptedDate' => 'disclaimer_accepted_date:datetime_epoch',
'DisclaimerAccepted' => 'disclaimer_accepted:json_boolean',
];
protected static $allowed_fields = [

View File

@ -130,6 +130,12 @@ class Presentation extends SummitEvent
*/
protected $will_all_speakers_attend;
/**
* @ORM\Column(name="DisclaimerAcceptedDate", type="datetime")
* @var \DateTime
*/
protected $disclaimer_accepted_date;
/**
* @ORM\ManyToOne(targetEntity="PresentationSpeaker", inversedBy="moderated_presentations", fetch="EXTRA_LAZY")
* @ORM\JoinColumn(name="ModeratorID", referencedColumnName="ID", onDelete="SET NULL")
@ -256,6 +262,7 @@ class Presentation extends SummitEvent
$this->to_record = false;
$this->attending_media = false;
$this->will_all_speakers_attend = false;
$this->disclaimer_accepted_date = null;
}
/**
@ -1606,4 +1613,26 @@ class Presentation extends SummitEvent
$answer->clearPresentation();
}
/**
* @return \DateTime
*/
public function getDisclaimerAcceptedDate(): ?\DateTime
{
return $this->disclaimer_accepted_date;
}
/**
* @return bool
*/
public function isDisclaimerAccepted():bool{
return !is_null($this->disclaimer_accepted_date);
}
/**
* @param \DateTime $disclaimer_accepted_date
*/
public function setDisclaimerAcceptedDate(\DateTime $disclaimer_accepted_date): void
{
$this->disclaimer_accepted_date = $disclaimer_accepted_date;
}
}

View File

@ -551,7 +551,7 @@ class SummitEvent extends SilverstripeBaseModel
}
/**
* @return SummitEventType
* @return SummitEventType|null
*/
public function getType()
{

View File

@ -0,0 +1,147 @@
<?php namespace App\Models\Foundation\Summit\Factories;
/**
* Copyright 2021 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\Foundation\Summit\ExtraQuestions\SummitSelectionPlanExtraQuestionType;
use Illuminate\Support\Facades\Log;
use models\exceptions\ValidationException;
use models\summit\Presentation;
use models\summit\PresentationExtraQuestionAnswer;
use models\summit\PresentationLink;
use models\utils\SilverstripeBaseModel;
/**
* Class PresentationFactory
* @package App\Models\Foundation\Summit\Factories
*/
final class PresentationFactory
{
public static function build(array $payload):Presentation{
return self::populate(new Presentation(), $payload);
}
/**
* @param Presentation $presentation
* @param array $payload
* @param false $only_presentation_data
* @return Presentation
* @throws ValidationException
*/
public static function populate(Presentation $presentation, array $payload, $only_presentation_data = false):Presentation{
if(!$only_presentation_data) {
if (isset($payload['title']))
$presentation->setTitle(html_entity_decode(trim($payload['title'])));
if (isset($payload['description']))
$presentation->setAbstract(html_entity_decode(trim($payload['description'])));
if (isset($payload['social_description']))
$presentation->setSocialSummary(strip_tags(trim($payload['social_description'])));
$event_type = $presentation->getType();
if (isset($payload['level']) && !is_null($event_type) && $event_type->isAllowsLevel())
$presentation->setLevel($payload['level']);
}
if (isset($payload['will_all_speakers_attend']))
$presentation->setWillAllSpeakersAttend(boolval($payload['will_all_speakers_attend']));
if (isset($payload['attendees_expected_learnt']))
$presentation->setAttendeesExpectedLearnt(html_entity_decode($payload['attendees_expected_learnt']));
$presentation->setAttendingMedia(isset($payload['attending_media']) ?
filter_var($payload['attending_media'], FILTER_VALIDATE_BOOLEAN) : 0);
$presentation->setToRecord(isset($data['to_record']) ?
filter_var($data['to_record'], FILTER_VALIDATE_BOOLEAN) : 0);
if (isset($payload['disclaimer_accepted']) && !empty($payload['disclaimer_accepted'])) {
$disclaimer_accepted = boolval($payload['disclaimer_accepted']);
if ($disclaimer_accepted && !$presentation->isDisclaimerAccepted()) {
$presentation->setDisclaimerAcceptedDate
(
new \DateTime('now', new \DateTimeZone('UTC'))
);
}
}
// links
if (isset($payload['links'])) {
$presentation->clearLinks();
if (count($payload['links']) > Presentation::MaxAllowedLinks) {
throw new ValidationException(trans(
'validation_errors.PresentationService.saveOrUpdatePresentation.MaxAllowedLinks',
[
'max_allowed_links' => Presentation::MaxAllowedLinks
]));
}
foreach ($payload['links'] as $link) {
$presentationLink = new PresentationLink();
$presentationLink->setName(trim($link));
$presentationLink->setLink(trim($link));
$presentation->addLink($presentationLink);
}
}
// extra questions
$extra_questions = $payload['extra_questions'] ?? [];
$selection_plan = $presentation->getSelectionPlan();
if (count($extra_questions) && !is_null($selection_plan)) {
// extra questions values
$mandatory_questions = $selection_plan->getMandatoryExtraQuestions();
if (count($extra_questions) < $mandatory_questions->count()) {
throw new ValidationException
(
sprintf
(
"You neglected to fill in all mandatory questions for the presentation %s (%s) .",
count($extra_questions),
$mandatory_questions->count()
)
);
}
$questions = $selection_plan->getExtraQuestions();
if ($questions->count() > 0) {
$presentation->clearExtraQuestionAnswers();
foreach ($questions as $question) {
if (!$question instanceof SummitSelectionPlanExtraQuestionType) continue;
foreach ($extra_questions as $question_answer) {
if (intval($question_answer['question_id']) == $question->getId()) {
$value = trim($question_answer['answer']);
if (empty($value) && $question->isMandatory())
throw new ValidationException(sprintf('Question "%s" is mandatory', $question->getLabel()));
if ($question->allowsValues() && !$question->allowValue($value)) {
Log::warning(sprintf("value %s is not allowed for question %s", $value, $question->getName()));
throw new ValidationException("The answer you provided is invalid");
}
$answer = new PresentationExtraQuestionAnswer();
$answer->setQuestion($question);
$answer->setValue($value);
$presentation->addExtraQuestionAnswer($answer);
break;
}
}
}
}
}
return $presentation;
}
}

View File

@ -1,4 +1,6 @@
<?php namespace models\summit;
use models\exceptions\ValidationException;
/**
* Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
@ -23,7 +25,7 @@ final class SummitEventFactory
* @param Summit $summit
* @return SummitEvent
*/
static public function build(SummitEventType $type, Summit $summit)
static public function build(SummitEventType $type, Summit $summit, array $payload)
{
$event = new SummitEvent();
@ -39,6 +41,63 @@ final class SummitEventFactory
$event->setSummit($summit);
$event->setType($type);
return self::populate($event, $payload);
}
/**
* @param SummitEvent $event
* @param array $payload
* @return SummitEvent
* @throws ValidationException
*/
static public function populate(SummitEvent $event, array $payload):SummitEvent{
if (isset($payload['title']))
$event->setTitle(html_entity_decode(trim($payload['title'])));
if (isset($payload['description']))
$event->setAbstract(html_entity_decode(trim($payload['description'])));
if (isset($payload['social_description']))
$event->setSocialSummary(strip_tags(trim($payload['social_description'])));
$event_type = $event->getType();
if (isset($payload['level']) && !is_null($event_type) && $event_type->isAllowsLevel())
$event->setLevel($payload['level']);
if (isset($payload['rsvp_link']) && isset($payload['rsvp_template_id'])) {
throw new ValidationException
(
"rsvp_link and rsvp_template_id are both set, you need to specify only one."
);
}
if (isset($payload['rsvp_link'])) {
$event->setRSVPLink(html_entity_decode(trim($payload['rsvp_link'])));
}
if (isset($payload['streaming_url'])) {
$event->setStreamingUrl(html_entity_decode(trim($payload['streaming_url'])));
}
if (isset($payload['etherpad_link'])) {
$event->setEtherpadLink(html_entity_decode(trim($payload['etherpad_link'])));
}
if (isset($payload['meeting_url'])) {
$event->setMeetingUrl(html_entity_decode(trim($payload['meeting_url'])));
}
if (isset($payload['head_count']))
$event->setHeadCount(intval($payload['head_count']));
if (isset($payload['occupancy']))
$event->setOccupancy($payload['occupancy']);
$event->setAllowFeedBack(isset($payload['allow_feedback']) ?
filter_var($payload['allow_feedback'], FILTER_VALIDATE_BOOLEAN) :
false);
return $event;
}
}

View File

@ -1,74 +0,0 @@
<?php namespace App\Services\Model\Imp;
/**
* Copyright 2021 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\Foundation\Summit\ExtraQuestions\SummitSelectionPlanExtraQuestionType;
use Illuminate\Support\Facades\Log;
use models\exceptions\ValidationException;
use models\summit\Presentation;
use models\summit\PresentationExtraQuestionAnswer;
/**
* Trait PresentationRelationsManagement
* @package App\Services\Model\Imp
*/
trait PresentationRelationsManagement
{
protected function savePresentationExtraQuestions(Presentation $presentation, array $payload):Presentation{
$extra_questions = $payload['extra_questions'] ?? [];
$selection_plan = $presentation->getSelectionPlan();
if (count($extra_questions) && !is_null($selection_plan)) {
// extra questions values
$mandatory_questions = $selection_plan->getMandatoryExtraQuestions();
if (count($extra_questions) < $mandatory_questions->count()) {
throw new ValidationException
(
sprintf
(
"You neglected to fill in all mandatory questions for the presentation %s (%s) .",
count($extra_questions),
$mandatory_questions->count()
)
);
}
$questions = $selection_plan->getExtraQuestions();
if ($questions->count() > 0) {
$presentation->clearExtraQuestionAnswers();
foreach ($questions as $question) {
if (!$question instanceof SummitSelectionPlanExtraQuestionType) continue;
foreach ($extra_questions as $question_answer) {
if (intval($question_answer['question_id']) == $question->getId()) {
$value = trim($question_answer['answer']);
if (empty($value) && $question->isMandatory())
throw new ValidationException(sprintf('Question "%s" is mandatory', $question->getLabel()));
if ($question->allowsValues() && !$question->allowValue($value)) {
Log::warning(sprintf("value %s is not allowed for question %s", $value, $question->getName()));
throw new ValidationException("The answer you provided is invalid");
}
$answer = new PresentationExtraQuestionAnswer();
$answer->setQuestion($question);
$answer->setValue($value);
$presentation->addExtraQuestionAnswer($answer);
break;
}
}
}
}
}
return $presentation;
}
}

View File

@ -11,6 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\PresentationMaterialDeleted;
use App\Events\PresentationMaterialUpdated;
use App\Facades\ResourceServerContext;
@ -19,43 +20,34 @@ use App\Http\Utils\FileUploadInfo;
use App\Http\Utils\IFileUploader;
use App\Jobs\Emails\PresentationSubmissions\PresentationCreatorNotificationEmail;
use App\Jobs\Emails\PresentationSubmissions\PresentationSpeakerNotificationEmail;
use App\Models\Foundation\Summit\ExtraQuestions\SummitSelectionPlanExtraQuestionType;
use App\Models\Foundation\Summit\Factories\PresentationFactory;
use App\Models\Foundation\Summit\Factories\PresentationLinkFactory;
use App\Models\Foundation\Summit\Factories\PresentationMediaUploadFactory;
use App\Models\Foundation\Summit\Factories\PresentationSlideFactory;
use App\Models\Foundation\Summit\Factories\PresentationVideoFactory;
use App\Models\Foundation\Summit\SelectionPlan;
use App\Models\Utils\IStorageTypesConstants;
use App\Services\FileSystem\FileNameSanitizer;
use App\Services\Filesystem\FileUploadStrategyFactory;
use App\Services\Model\AbstractService;
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackAnswer;
use App\Services\Model\Imp\PresentationRelationsManagement;
use Illuminate\Support\Facades\Config;
use App\Services\Model\IFolderService;
use Illuminate\Http\Request as LaravelRequest;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use libs\utils\ITransactionService;
use models\exceptions\EntityNotFoundException;
use models\exceptions\ValidationException;
use models\main\IFolderRepository;
use models\main\ITagRepository;
use models\main\Member;
use models\summit\ISpeakerRepository;
use models\summit\ISummitEventRepository;
use models\summit\Presentation;
use models\summit\PresentationExtraQuestionAnswer;
use models\summit\PresentationLink;
use models\summit\PresentationMediaUpload;
use models\summit\PresentationSlide;
use models\summit\PresentationSpeaker;
use models\summit\PresentationType;
use models\summit\PresentationVideo;
use libs\utils\ITransactionService;
use models\summit\Summit;
use Illuminate\Http\Request as LaravelRequest;
use App\Services\Model\IFolderService;
use models\summit\SummitOrderExtraQuestionTypeConstants;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Class PresentationService
@ -413,6 +405,7 @@ final class PresentationService
)
{
return $this->tx_service->transaction(function () use ($summit, $selection_plan, $presentation, $current_speaker, $data) {
$event_type = $summit->getEventType(intval($data['type_id']));
if (is_null($event_type)) {
throw new EntityNotFoundException(
@ -460,77 +453,9 @@ final class PresentationService
]));
}
if (isset($data['title']))
$presentation->setTitle(html_entity_decode(trim($data['title'])));
if (isset($data['description']))
$presentation->setAbstract(html_entity_decode(trim($data['description'])));
if (isset($data['will_all_speakers_attend']))
$presentation->setWillAllSpeakersAttend(boolval($data['will_all_speakers_attend']));
if (isset($data['social_description']))
$presentation->setSocialSummary(strip_tags(trim($data['social_description'])));
if (isset($data['level']) && !is_null($event_type) && $event_type->isAllowsLevel())
$presentation->setLevel($data['level']);
if (isset($data['attendees_expected_learnt']))
$presentation->setAttendeesExpectedLearnt(html_entity_decode($data['attendees_expected_learnt']));
$presentation->setAttendingMedia(isset($data['attending_media']) ?
filter_var($data['attending_media'], FILTER_VALIDATE_BOOLEAN) : 0);
$presentation->setType($event_type);
$presentation->setCategory($track);
// add me as speaker
//$presentation->addSpeaker($current_speaker);
if (isset($data['tags'])) {
$presentation->clearTags();
if (count($data['tags']) > 0) {
if(!$presentation->isCompleted())
$presentation->setProgress(Presentation::PHASE_TAGS);
}
foreach ($data['tags'] as $tag_value) {
$tag = $track->getAllowedTagByVal($tag_value);
if (is_null($tag)) {
throw new ValidationException(
trans(
'validation_errors.PresentationService.saveOrUpdatePresentation.TagNotAllowed',
[
'tag' => $tag_value,
'track_id' => $track->getId()
]
)
);
}
$presentation->addTag($tag);
}
}
if (isset($data['links'])) {
$presentation->clearLinks();
if (count($data['links']) > Presentation::MaxAllowedLinks) {
throw new ValidationException(trans(
'validation_errors.PresentationService.saveOrUpdatePresentation.MaxAllowedLinks',
[
'max_allowed_links' => Presentation::MaxAllowedLinks
]));
}
foreach ($data['links'] as $link) {
$presentationLink = new PresentationLink();
$presentationLink->setName(trim($link));
$presentationLink->setLink(trim($link));
$presentation->addLink($presentationLink);
}
}
return $this->savePresentationExtraQuestions($presentation, $data);
return PresentationFactory::populate($presentation, $data);
});
}

View File

@ -12,10 +12,6 @@
* limitations under the License.
**/
use App\Facades\ResourceServerContext;
use App\Models\Foundation\Summit\ExtraQuestions\SummitSelectionPlanExtraQuestionType;
use App\Services\Model\Imp\PresentationRelationsManagement;
use League\Csv\Reader;
use App\Events\MyFavoritesAdd;
use App\Events\MyFavoritesRemove;
use App\Events\MyScheduleAdd;
@ -24,10 +20,12 @@ use App\Events\RSVPCreated;
use App\Events\RSVPUpdated;
use App\Events\SummitDeleted;
use App\Events\SummitUpdated;
use App\Facades\ResourceServerContext;
use App\Http\Utils\IFileUploader;
use App\Jobs\Emails\PresentationSubmissions\ImportEventSpeakerEmail;
use App\Jobs\Emails\Schedule\ShareEventEmail;
use App\Jobs\ProcessEventDataImport;
use App\Models\Foundation\Summit\Factories\PresentationFactory;
use App\Models\Foundation\Summit\Factories\SummitEventFeedbackFactory;
use App\Models\Foundation\Summit\Factories\SummitFactory;
use App\Models\Foundation\Summit\Factories\SummitRSVPFactory;
@ -38,21 +36,27 @@ use App\Services\Model\AbstractService;
use App\Services\Model\IFolderService;
use App\Services\Model\IMemberService;
use CalDAVClient\Facade\Utils\ICalTimeZoneBuilder;
use DateInterval;
use DateTime;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Exception;
use GuzzleHttp\Exception\ClientException;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use League\Csv\Reader;
use libs\utils\ITransactionService;
use models\exceptions\EntityNotFoundException;
use models\exceptions\ValidationException;
use Models\foundation\summit\EntityEvents\EntityEventTypeFactory;
use Models\foundation\summit\EntityEvents\SummitEntityEventProcessContext;
use models\main\File;
use models\main\ICompanyRepository;
use models\main\IGroupRepository;
use models\main\IMemberRepository;
use models\main\ITagRepository;
use Models\foundation\summit\EntityEvents\EntityEventTypeFactory;
use Models\foundation\summit\EntityEvents\SummitEntityEventProcessContext;
use models\main\Member;
use models\main\PersonalCalendarShareInfo;
use models\main\Tag;
@ -69,7 +73,6 @@ use models\summit\ISummitEntityEventRepository;
use models\summit\ISummitEventRepository;
use models\summit\ISummitRepository;
use models\summit\Presentation;
use models\summit\PresentationExtraQuestionAnswer;
use models\summit\PresentationSpeaker;
use models\summit\PresentationType;
use models\summit\RSVP;
@ -86,19 +89,13 @@ use models\summit\SummitEventWithFile;
use models\summit\SummitGeoLocatedLocation;
use models\summit\SummitGroupEvent;
use models\summit\SummitScheduleEmptySpot;
use models\utils\SilverstripeBaseModel;
use services\apis\IEventbriteAPI;
use libs\utils\ITransactionService;
use Exception;
use DateTime;
use Illuminate\Support\Facades\Log;
use utils\Filter;
use utils\FilterElement;
use utils\FilterParser;
use utils\Order;
use utils\OrderElement;
use utils\PagingInfo;
use DateInterval;
/**
* Class SummitService
@ -771,45 +768,25 @@ final class SummitService extends AbstractService implements ISummitService
}
if (is_null($event_id) && is_null($event_type)) {
// is event is new one and we dont provide an event type ...
throw new ValidationException('type_id is mandatory!');
}
// new event
if (is_null($event)) {
$event = SummitEventFactory::build($event_type, $summit);
$event = SummitEventFactory::build($event_type, $summit, $data);
$event->setCreatedBy($current_member);
}
else{
$event->setSummit($summit);
if (!is_null($event_type))
$event->setType($event_type);
SummitEventFactory::populate($event, $data);
}
$event->setUpdatedBy($current_member);
// main data
if (isset($data['title']))
$event->setTitle(html_entity_decode(trim($data['title'])));
if (isset($data['level']) && !is_null($event_type) && $event_type->isAllowsLevel())
$event->setLevel($data['level']);
if (isset($data['description']))
$event->setAbstract(html_entity_decode(trim($data['description'])));
if (isset($data['rsvp_link']) && isset($data['rsvp_template_id'])) {
throw new ValidationException("rsvp_link and rsvp_template_id are both set, you need to especify only one");
}
if (isset($data['rsvp_link'])) {
$event->setRSVPLink(html_entity_decode(trim($data['rsvp_link'])));
}
if (isset($data['streaming_url'])) {
$event->setStreamingUrl(html_entity_decode(trim($data['streaming_url'])));
}
if (isset($data['etherpad_link'])) {
$event->setEtherpadLink(html_entity_decode(trim($data['etherpad_link'])));
}
if (isset($data['meeting_url'])) {
$event->setMeetingUrl(html_entity_decode(trim($data['meeting_url'])));
}
if (isset($data['rsvp_template_id'])) {
$rsvp_template = $summit->getRSVPTemplateById(intval($data['rsvp_template_id']));
@ -826,32 +803,10 @@ final class SummitService extends AbstractService implements ISummitService
$event->setRSVPMaxUserWaitListNumber(intval($data['rsvp_max_user_wait_list_number']));
}
if (isset($data['head_count']))
$event->setHeadCount(intval($data['head_count']));
if (isset($data['social_description']))
$event->setSocialSummary(strip_tags(trim($data['social_description'])));
if (isset($data['occupancy']))
$event->setOccupancy($data['occupancy']);
$event->setAllowFeedBack(isset($data['allow_feedback']) ?
filter_var($data['allow_feedback'], FILTER_VALIDATE_BOOLEAN) :
false);
if (!is_null($event_type))
$event->setType($event_type);
if (is_null($event_id) && is_null($event_type)) {
// is event is new one and we dont provide an event type ...
throw new ValidationException('type_id is mandatory!');
}
if (!is_null($track)) {
$event->setCategory($track);
}
$event->setSummit($summit);
if (!is_null($location))
$event->setLocation($location);
@ -919,7 +874,6 @@ final class SummitService extends AbstractService implements ISummitService
}
}
use PresentationRelationsManagement;
/**
* @param SummitEvent $event
* @param SummitEventType $event_type
@ -931,21 +885,11 @@ final class SummitService extends AbstractService implements ISummitService
{
if (!$event instanceof Presentation) return;
// main data
if (isset($data['attendees_expected_learnt']))
$event->setAttendeesExpectedLearnt(html_entity_decode($data['attendees_expected_learnt']));
$event->setAttendingMedia(isset($data['attending_media']) ?
filter_var($data['attending_media'], FILTER_VALIDATE_BOOLEAN) : 0);
// if we are creating the presentation from admin, then
// we should mark it as received and complete
$event->setStatus(Presentation::STATUS_RECEIVED);
$event->setProgress(Presentation::PHASE_COMPLETE);
$event->setToRecord(isset($data['to_record']) ?
filter_var($data['to_record'], FILTER_VALIDATE_BOOLEAN) : 0);
// speakers
if ($event_type instanceof PresentationType && $event_type->isUseSpeakers()) {
@ -953,7 +897,7 @@ final class SummitService extends AbstractService implements ISummitService
$speakers = $data['speakers'] ?? [];
if ($event_type->isAreSpeakersMandatory() && count($speakers) == 0) {
throw new ValidationException('speakers are mandatory!');
throw new ValidationException('Speakers are mandatory.');
}
if($shouldClearSpeakers){
@ -964,7 +908,8 @@ final class SummitService extends AbstractService implements ISummitService
$event->clearSpeakers();
foreach ($speakers as $speaker_id) {
$speaker = $this->speaker_repository->getById(intval($speaker_id));
if (is_null($speaker) || !$speaker instanceof PresentationSpeaker) throw new EntityNotFoundException(sprintf('speaker id %s', $speaker_id));
if (is_null($speaker) || !$speaker instanceof PresentationSpeaker)
throw new EntityNotFoundException(sprintf('Speaker id %s.', $speaker_id));
$event->addSpeaker($speaker);
}
}
@ -976,7 +921,7 @@ final class SummitService extends AbstractService implements ISummitService
$moderator_id = isset($data['moderator_speaker_id']) ? intval($data['moderator_speaker_id']) : 0;
if ($event_type->isModeratorMandatory() && $moderator_id == 0) {
throw new ValidationException('moderator_speaker_id is mandatory!');
throw new ValidationException('moderator_speaker_id is mandatory.');
}
if ($moderator_id > 0) {
@ -999,14 +944,23 @@ final class SummitService extends AbstractService implements ISummitService
if (!is_null($selection_plan)) {
$track = $event->getCategory();
if (!$selection_plan->hasTrack($track)) {
throw new ValidationException(sprintf("Track %s (%s) does not belongs to Selection Plan %s (%s)", $track->getTitle(), $track->getId(), $selection_plan->getName(), $selection_plan->getId()));
throw new ValidationException
(
sprintf
(
"Track %s (%s) does not belongs to Selection Plan %s (%s).",
$track->getTitle(),
$track->getId(),
$selection_plan->getName(),
$selection_plan->getId()
)
);
}
$event->setSelectionPlan($selection_plan);
}
}
$this->savePresentationExtraQuestions($event, $data);
PresentationFactory::populate($event, $data, true);
}
/**

View File

@ -0,0 +1,51 @@
<?php namespace Database\Migrations\Model;
/**
* Copyright 2021 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema as Schema;
use LaravelDoctrine\Migrations\Schema\Builder;
use LaravelDoctrine\Migrations\Schema\Table;
/**
* Class Version20210528150223
* @package Database\Migrations\Model
*/
class Version20210528150223 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema):void
{
$builder = new Builder($schema);
if ($builder->hasTable("Presentation") && !$builder->hasColumn("Presentation", "DisclaimerAcceptedDate")) {
$builder->table("Presentation", function (Table $table) {
$table->timestamp('DisclaimerAcceptedDate')->setNotnull(false);
});
}
}
/**
* @param Schema $schema
*/
public function down(Schema $schema):void
{
$builder = new Builder($schema);
if ($builder->hasTable("Presentation") && $builder->hasColumn("Presentation", "DisclaimerAcceptedDate")) {
$builder->table("Presentation", function (Table $table) {
$table->dropColumn('DisclaimerAcceptedDate');
});
}
}
}