public function getConferenceDetails(integer $conferenceId) : ServiceResponse
 {
     $db = DatabaseData::getInstance(DatabaseConfig::DB_INSTANCE);
     $statement = $db->prepare("select count(LectureId) as 'count' from lecturesParticipants where LectureId = ?");
     $conference = $this->dbContext->getConferencesRepository()->filterById(" = {$conferenceId}")->findOne();
     if ($conference->getId() == null) {
         return new ServiceResponse(1, "Conference not found.");
     }
     $venueId = $conference->getVenue_Id();
     $venue = $this->dbContext->getVenuesRepository()->filterById(" = {$venueId}")->findOne()->getTitle();
     $ownerId = $conference->getOwnerId();
     $owner = $this->dbContext->getUsersRepository()->filterById(" = {$ownerId}")->findOne()->getUsername();
     $model = new ConferenceDetailsViewModel($conference);
     $model->setVenueId($venueId);
     $model->setVenue($venue);
     $model->setOwnerUsername($owner);
     $venueStatus = $this->dbContext->getVenueReservationRequestsRepository()->filterByConferenceId(" = {$conferenceId}")->filterByVenueId(" = {$venueId}")->findOne()->getStatus();
     $model->setVenueRequestStatus($venueStatus);
     $lectures = $this->dbContext->getLecturesRepository()->filterByConferenceId(" = {$conferenceId}")->orderBy("StartDate")->findAll(" = {$conferenceId}");
     $lecturesModels = [];
     foreach ($lectures->getLectures() as $lecture) {
         $lectureModel = new LectureViewModel($lecture);
         $hallId = $lectureModel->getHallId() == null ? 0 : $lectureModel->getHallId();
         $hall = $this->dbContext->getHallsRepository()->filterById(" = {$hallId}")->findOne();
         $lectureModel->setHallTitle($hall->getTitle() == null ? "(to be decided)" : $hall->getTitle());
         $speakerId = $lectureModel->getSpeakerId();
         $speaker = $this->dbContext->getUsersRepository()->filterById(" = {$speakerId}")->findOne();
         $lectureModel->setSpeakerUsername($speaker->getUsername());
         $lectureId = $lecture->getId();
         $speakerRequest = $this->dbContext->getSpeakerInvitationsRepository()->filterByLectureId(" = {$lectureId}")->filterBySpeakerId(" = {$speakerId}")->findOne();
         $lectureModel->setSpeakerRequestStatus($speakerRequest->getStatus());
         $lectureId = $lectureModel->getId();
         $statement = $db->prepare("select count(LectureId) as 'count' from lecturesParticipants where LectureId = ?");
         $statement->execute([$lectureId]);
         $participants = $statement->fetch()['count'];
         $lectureModel->setParticipantsCount($participants);
         $participantId = HttpContext::getInstance()->getIdentity()->getUserId();
         if ($participantId == null) {
             $lectureModel->setIsParticipating(false);
             $lectureModel->setCanParticipate(false);
         } else {
             $participantsInLecture = $this->dbContext->getLecturesParticipantsRepository()->filterByLectureId(" = {$lectureId}")->filterByParticipantId(" = {$participantId}")->findOne();
             if ($participantsInLecture->getId() != null) {
                 $lectureModel->setIsParticipating(true);
             } else {
                 $lectureModel->setIsParticipating(false);
             }
             $statement = $db->prepare(self::CHECK_USER_CAN_PARTICIPATE);
             $statement->execute([$participantId, $lecture->getStartDate(), $lecture->getStartDate(), $lecture->getEndDate(), $lecture->getEndDate()]);
             if ($statement->rowCount() > 0) {
                 $lectureModel->setCanParticipate(false);
             } else {
                 $lectureModel->setCanParticipate(true);
             }
         }
         $lecturesModels[] = $lectureModel;
     }
     $model->setLectures($lecturesModels);
     return $model;
 }
 public function getSpeakerSchedule() : ServiceResponse
 {
     $userId = HttpContext::getInstance()->getIdentity()->getUserId();
     if ($userId == null) {
         return new ServiceResponse(401, "Unauthorised. Only logged users can get their speaker's schedule.");
     }
     $todayDate = new \DateTime('now');
     $today = $todayDate->format('Y-m-d H:i:s');
     $lectures = $this->dbContext->getLecturesRepository()->orderBy("StartDate")->filterBySpeaker_Id(" = {$userId}")->filterByStartDate(" >= '{$today}'")->findAll();
     $lecturesModels = [];
     $db = DatabaseData::getInstance(DatabaseConfig::DB_INSTANCE);
     foreach ($lectures->getLectures() as $lecture) {
         $lectureModel = new LectureViewModel($lecture);
         $hallId = $lectureModel->getHallId() == null ? 0 : $lectureModel->getHallId();
         $hall = $this->dbContext->getHallsRepository()->filterById(" = {$hallId}")->findOne();
         $lectureModel->setHallTitle($hall->getTitle() == null ? "(to be decided)" : $hall->getTitle());
         $speakerId = $lectureModel->getSpeakerId();
         $speaker = $this->dbContext->getUsersRepository()->filterById(" = {$speakerId}")->findOne();
         $lectureModel->setSpeakerUsername($speaker->getUsername());
         $lectureId = $lecture->getId();
         $speakerRequest = $this->dbContext->getSpeakerInvitationsRepository()->filterByLectureId(" = {$lectureId}")->filterBySpeakerId(" = {$speakerId}")->findOne();
         $lectureModel->setSpeakerRequestStatus($speakerRequest->getStatus());
         $lectureId = $lectureModel->getId();
         $statement = $db->prepare("select count(LectureId) as 'count' from lecturesParticipants where LectureId = ?");
         $statement->execute([$lectureId]);
         $participants = $statement->fetch()['count'];
         $lectureModel->setParticipantsCount($participants);
         $participantId = HttpContext::getInstance()->getIdentity()->getUserId();
         if ($participantId == null) {
             $lectureModel->setIsParticipating(false);
             $lectureModel->setCanParticipate(false);
         } else {
             $participantsInLecture = $this->dbContext->getLecturesParticipantsRepository()->filterByLectureId(" = {$lectureId}")->filterByParticipantId(" = {$participantId}")->findOne();
             if ($participantsInLecture->getId() != null) {
                 $lectureModel->setIsParticipating(true);
             } else {
                 $lectureModel->setIsParticipating(false);
             }
         }
         $lecturesModels[] = $lectureModel;
     }
     return new ServiceResponse(null, null, $lecturesModels);
 }
 public function addHall(AddHallInputModel $model) : ServiceResponse
 {
     $lectureId = $model->getLectureId();
     $hallId = $model->getHallId();
     $conferenceId = $model->getConferenceId();
     $lecture = $this->dbContext->getLecturesRepository()->filterById(" = {$lectureId}")->findOne();
     if ($lecture->getId() == null) {
         return new ServiceResponse(404, "Lecture not found.");
     }
     $hall = $this->dbContext->getHallsRepository()->filterById(" = {$hallId}")->findOne();
     if ($hall->getId() == null) {
         return new ServiceResponse(404, "Hall not found.");
     }
     $conference = $this->dbContext->getConferencesRepository()->filterById(" = {$conferenceId}")->findOne();
     if (HttpContext::getInstance()->getIdentity()->getUserId() != $conference->getOwnerId()) {
         return new ServiceResponse(401, "Unauthorised. You must be conference owner.");
     }
     $venueId = $conference->getVenue_Id();
     $testHall = $this->dbContext->getHallsRepository()->filterById(" = {$hallId}")->filterByVenueId(" = {$venueId}")->findOne();
     if ($testHall->getId() == null) {
         return new ServiceResponse(409, "No such hall in the conference venue.");
     }
     $otherLecturesInSameHall = $this->dbContext->getLecturesRepository()->filterByHall_Id(" = {$hallId}")->findAll();
     $baseLectureViewModel = new LectureViewModel($lecture);
     foreach ($otherLecturesInSameHall->getLectures() as $currentlecture) {
         if ($currentlecture->getId() == $baseLectureViewModel->getId()) {
             continue;
         }
         $lectureViewModel = new LectureViewModel($currentlecture);
         if ($this->compareTo($baseLectureViewModel, $lectureViewModel) == 0) {
             return new ServiceResponse(1, "The hall is busy at this time. Request is denied.", $conferenceId);
         }
     }
     $lecture = $this->dbContext->getLecturesRepository()->filterById(" = {$lectureId}")->findOne();
     $lecture->setHall_Id($hallId);
     $this->dbContext->saveChanges();
     return new ServiceResponse(null, "Hall added to lecture.", $conferenceId);
 }