public function start()
 {
     $context = HttpContext::getInstance();
     $context->setGet($_GET);
     $context->setPost($_POST);
     $context->setCookies($_COOKIE);
     $context->setSession($_SESSION);
     $context->setMethod(strtolower($_SERVER['REQUEST_METHOD']));
     IdentityManager::createIdentity();
     IdentityManager::updateIdentity();
     OrmManager::update();
     $this->initController();
     $bindingModels = \RedDevil\Core\BindingModelMapper::mapBindingModels($this->controller, $this->route['action']);
     if (!array_key_exists('parameters', $this->route)) {
         $this->route['parameters'] = [];
         $this->route['parameters'] = $bindingModels;
     } else {
         $this->route['parameters'] = array_merge($bindingModels, $this->route['parameters']);
     }
     foreach ($this->annotationFilters as $filter) {
         $filter->onBeforeExecute();
     }
     call_user_func_array([$this->controller, $this->route['action']], $this->route['parameters']);
     foreach ($this->annotationFilters as $filter) {
         $filter->onAfterExecute();
     }
 }
 public function onBeforeExecute()
 {
     $context = HttpContext::getInstance();
     if (!$context->session('userId')) {
         throw new \Exception("Unauthorized", 401);
     }
 }
 public function onBeforeExecute()
 {
     $context = HttpContext::getInstance();
     $currentMethod = $context->getMethod();
     if (!in_array($currentMethod, $this->methods)) {
         throw new \Exception("Method not allowed", 405);
     }
 }
 /**
  * Method('GET')
  * Authorize
  */
 public function all() : View
 {
     $userId = HttpContext::getInstance()->getIdentity()->getUserId();
     $service = new NotificationsService($this->dbContext);
     $result = $service->getAllNotifications($userId);
     $this->processResponse($result);
     return new View('Notifications', 'all', $result->getModel());
 }
 /**
  * @param ChangePasswordInputModel $model
  * @return ServiceResponse
  */
 public function changePassword(ChangePasswordInputModel $model) : ServiceResponse
 {
     $user = $this->dbContext->getUsersRepository()->filterByUsername(' = "' . HttpContext::getInstance()->getIdentity()->getUsername() . '"')->findOne();
     if (!password_verify($model->getCurrentPassword(), $user->getPassword())) {
         return new ServiceResponse(1, 'Wrong current password.');
     }
     $user->setPassword(password_hash($model->getNewPassword(), PASSWORD_DEFAULT));
     $this->dbContext->saveChanges();
     return new ServiceResponse(null, 'Password changed successfully.');
 }
 public function onBeforeExecute()
 {
     $context = HttpContext::getInstance();
     if (!$context->session('userId')) {
         throw new \Exception("Unauthorized", 401);
     }
     if (!$context->getIdentity()->isInRole($this->role)) {
         throw new \Exception("Unauthorized", 401);
     }
 }
 public function onBeforeExecute()
 {
     $context = HttpContext::getInstance();
     if (!$context->isPost()) {
         return;
     }
     if (!$context->session('ValidationToken')) {
         throw new \Exception("Unauthorized", 401);
     }
 }
 /**
  * @param ConferenceInputModel $model
  * @Method('GET', 'POST')
  * @Validatetoken('token')
  * @return View
  */
 public function add(ConferenceInputModel $model)
 {
     if (!$model->isValid()) {
         return new View('conferences', 'add', $model);
     }
     $service = new ConferencesService($this->dbContext);
     if (HttpContext::getInstance()->isPost()) {
         $result = $service->addConference($model);
         if (!$result->hasError()) {
             $this->addInfoMessage($result->getMessage());
             $this->redirect('conferences', 'own');
         } else {
             $this->addErrorMessage($result->getMessage());
             $this->redirect('conferences', 'own');
         }
     } else {
         return new View('conferences', 'add', new ConferenceInputModel());
     }
 }
 /**
  * @param ChangePasswordInputModel $model
  * @Validatetoken('token')
  * @return mixed
  * @throws \Exception
  */
 public function changePassword(ChangePasswordInputModel $model) : View
 {
     if (!HttpContext::getInstance()->getIdentity()->isAuthorised()) {
         throw new \Exception('Unauthorised', 401);
     }
     if (!$model->isValid()) {
         return new View('account', 'changePassword', $model);
     }
     $service = new AccountService($this->dbContext);
     if (HttpContext::getInstance()->isPost()) {
         $result = $service->changepassword($model);
         if (!$result->hasError()) {
             $this->addInfoMessage($result->getMessage());
             $this->redirect('home', 'index');
         } else {
             $this->addErrorMessage($result->getMessage());
             $this->redirect('account', 'register');
         }
     } else {
         return new View('account', 'changePassword', new ChangePasswordInputModel());
     }
 }
 public function getUserVenues() : ServiceResponse
 {
     $userId = HttpContext::getInstance()->getIdentity()->getUserId();
     if ($userId == null) {
         return new ServiceResponse(401, "Unauthorised. Only logged-in users can view their conferences.");
     }
     $venueModels = [];
     $venues = $this->dbContext->getVenuesRepository()->orderByDescending('Title')->filterByOwnerId(" = {$userId}")->findAll();
     foreach ($venues->getVenues() as $venue) {
         $model = new VenueSummaryViewModel($venue);
         $venueModels[] = $model;
         $ownerId = $venue->getOwnerId();
         $owner = $this->dbContext->getUsersRepository()->filterById(" = {$ownerId}")->findOne()->getUsername();
         $model->setOwnerUsername($owner);
     }
     return new ServiceResponse(null, null, $venueModels);
 }
 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);
 }
                     <?php 
 echo $lecture->getStartDate();
 ?>
                     <br/>
                     <strong>End: </strong>
                     <?php 
 echo $lecture->getEndDate();
 ?>
                     <br/>
                     <strong>Participants: </strong>
                     <?php 
 echo $lecture->getParticipantsCount();
 ?>
                     <br/>
                     <?php 
 if ($model->getOwnerId() == HttpContext::getInstance()->getIdentity()->getUserId()) {
     new View("Conferences", "_LectureMenu", $lecture, null);
 }
 ?>
                     <?php 
 if ($lecture->getHallId() !== '') {
     if ($lecture->getIsParticipating() == false && $lecture->getCanParticipate() == true) {
         ActionLink::create()->setAttribute('href', '/lectures/' . $lecture->getId() . '/participate')->setAttribute('class', 'btn btn-success pull-right')->setNewLineAfter(false)->setData('Join')->render();
     } else {
         echo "<a class='btn btn-success pull-right' disabled>Join</a>";
     }
 }
 ?>
                 </div>
             </div>
         </div>
 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);
 }
 /**
  * @param $venueId
  * @ValidateToken('token')
  * @Route('venues/{integer $venueId}/delete/confirm')
  * @return View
  */
 public function confirmDeleteVenue(integer $venueId) : View
 {
     if (HttpContext::getInstance()->isPost()) {
         $this->redirectToUrl('/venues/' . $venueId . '/delete');
     } else {
         return new View('Venues', 'confirmDeleteVenue', $venueId);
     }
 }
        </div>
    </div>
</div>
<div class="container body-content">
<?php 
include 'messages.php';
?>
<div class="row">
    <div class="col-md-3">
        <ul class="nav nav-pills nav-stacked">
            <li role="presentation" class="disabled"><a href="#"><h4>Menu</h4></a></li>
            <li role="presentation"><a href="/conferences/all">Conferences</a></li>
            <li role="presentation"><a href="/venues/all">Venues</a></li>
            <?php 
if (HttpContext::getInstance()->getIdentity()->isAuthorised()) {
    new View("Users", "_UserMenu", null, null);
}
?>
            <?php 
if (HttpContext::getInstance()->getIdentity()->isInRole('conferenceOwner') || HttpContext::getInstance()->getIdentity()->isInRole('admin')) {
    new View("Conferences", "_ConferenceOwnerMenu", null, null);
}
?>
            <?php 
if (HttpContext::getInstance()->getIdentity()->isInRole('venueOwner') || HttpContext::getInstance()->getIdentity()->isInRole('admin')) {
    new View("Venues", "_VenueOwnerMenu", null, null);
}
?>
        </ul>
    </div>
 /**
  * @param $lectureId
  * @throws \Exception
  * @Method('POST', 'GET')
  * @Route('lectures/{integer $lectureId}/participate')
  */
 public function participate(integer $lectureId)
 {
     $userId = HttpContext::getInstance()->getIdentity()->getUserId();
     $service = new LecturesService($this->dbContext);
     $result = $service->addParticipant($lectureId, $userId);
     $this->processResponse($result);
     $this->redirectToUrl('/conferences/details/' . $result->getModel());
 }
 public function batchBook(BatchBookLectures $lectures) : ServiceResponse
 {
     $lectureService = new LecturesService($this->dbContext);
     $responses = [];
     foreach ($lectures->getLectureIds() as $lectureId) {
         $response = $lectureService->addParticipant($lectureId, HttpContext::getInstance()->getIdentity()->getUserId());
         $responses[] = $response;
     }
     return new ServiceResponse(null, null, $responses);
 }