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 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;
 }