コード例 #1
0
 public function inviteSpeaker(SpeakerInvitationInputModel $model) : ServiceResponse
 {
     $lectureId = $model->getLectureId();
     $speakerId = $model->getSpeakerId();
     $conferenceId = $model->getConferenceId();
     $lecture = $this->dbContext->getLecturesRepository()->filterById(" = {$lectureId}")->findOne();
     $speaker = $this->dbContext->getUsersRepository()->filterById(" = {$speakerId}")->findOne();
     if ($lecture->getId() == null) {
         return new ServiceResponse(404, "Lecture not found.");
     }
     if ($speaker->getId() == null) {
         return new ServiceResponse(404, "Speaker not found.");
     }
     $conference = $this->dbContext->getConferencesRepository()->filterById(" = {$conferenceId}")->findOne();
     if ($conference->getId() == null) {
         return new ServiceResponse(404, 'Conference not found.');
     }
     if (HttpContext::getInstance()->getIdentity()->getUserId() != $conference->getOwnerId()) {
         return new ServiceResponse(401, 'Only conference owners can invite speakers.');
     }
     $invitation = $this->dbContext->getSpeakerInvitationsRepository()->filterByLectureId(" = {$lectureId}")->filterBySpeakerId(" = {$speakerId}")->findOne();
     if ($invitation->getId() != null) {
         return new ServiceResponse(409, "Speaker is already invited.");
     }
     $this->dbContext->getSpeakerInvitationsRepository()->filterByLectureId(" = {$lectureId}")->delete();
     $speakerInvitation = new SpeakerInvitation($lectureId, $speakerId, 0);
     $this->dbContext->getSpeakerInvitationsRepository()->add($speakerInvitation);
     $lecture->setSpeaker_Id($speakerId);
     $title = $lecture->getTitle();
     $message = "You received Speaker invitation for the lecture '{$title}'.";
     $notyService = new NotificationsService($this->dbContext);
     $notyService->sendNotification($speakerId, $message);
     $this->dbContext->saveChanges();
     return new ServiceResponse(null, "Invitation sent.");
 }
コード例 #2
0
 /**
  * Method('POST')
  * @Validatetoken('token')
  * @Route('lectures/sendinvitation')
  * @param SpeakerInvitationInputModel $model
  */
 public function sendInvitation(SpeakerInvitationInputModel $model)
 {
     if (!$model->isValid()) {
         $this->redirect('Conferences', 'all');
     }
     $service = new LecturesService($this->dbContext);
     $result = $service->inviteSpeaker($model);
     $this->processResponse($result);
     $this->redirectToUrl('/conferences/details/' . $model->getConferenceId());
 }