/** * @Authorize * @Route("Me/Schedule") */ public function mySchedule() : View { $loggedUserId = $this->identity->getUserId(); $service = new LecturesService($this->dbContext); $lecturesToVisit = $this->dbContext->getLecturesusersRepository()->filterByUserId(" = '{$loggedUserId}'")->findAll()->getLecturesusers(); $lecturesToVisitView = []; foreach ($lecturesToVisit as $lecture) { $id = intval($lecture->getLectureId()); $lecturesToVisitView[] = $service->getOne($id); } $lecturesToSpeak = $this->dbContext->getLecturesspeakersRepository()->filterBySpeakerId(" = '{$loggedUserId}'")->findAll()->getLecturesspeakers(); $lecturesToSpeakView = []; foreach ($lecturesToSpeak as $lecture) { $id = intval($lecture->getLectureId()); $lecturesToSpeakView[] = $service->getOne($id); } $model = ['toVisit' => $lecturesToVisitView, 'toSpeak' => $lecturesToSpeakView]; return new View('Home', 'mySchedule', $model); }
/** * @Authorize * @Route("Lecture/{int id}/Manage") */ public function edit() : View { $lectureId = intval(func_get_args()[0]); $service = new LecturesService($this->dbContext); $lecture = $service->getOne($lectureId); $conferenceService = new ConferenceService($this->dbContext); $conference = $conferenceService->getOne(intval($lecture->getConferenceId())); $viewBag = []; $loggedUserId = $this->identity->getUserId(); $id = intval($conference->getId()); $conferenceAdmins = $this->dbContext->getConferenceadminsRepository()->filterByConferenceId(" = '{$id}'")->findAll()->getConferenceadmins(); if (!$this->identity->isInRole("Admin")) { if ($loggedUserId !== intval($conference->getOwnerId())) { $unauthorized = true; foreach ($conferenceAdmins as $admin) { if (intval($admin->getUserId()) === $loggedUserId) { $unauthorized = false; $viewBag['isAdmin'] = true; break; } } if ($unauthorized) { $this->addErrorMessage("You are not the owner of this conference!"); $this->redirect('Me', 'Conferences'); } } } $venueId = $lecture->getVenueId(); $halls = $this->dbContext->getHallsRepository()->filterByVenueId(" = '{$venueId}'")->findAll()->getHalls(); $viewBag['halls'] = $halls; if ($this->context->isPost()) { $this->validateToken(); $model = new LectureBindingModel(); if ($model->getErrors()) { foreach ($model->getErrors() as $error) { $this->addErrorMessage($error); } $this->redirectToUrl('/Lecture/' . $lectureId . '/Manage'); } if (strtotime($conference->getStart()) > strtotime($model->getStartDate())) { $this->addErrorMessage('Start of the lecture must be later than start of the conference'); $this->redirectToUrl('/Lecture/' . $lectureId . '/Manage'); } if (strtotime($conference->getEnd()) < strtotime($model->getEndDate())) { $this->addErrorMessage('End of the lecture must be earlier than the end of the conference'); $this->redirectToUrl('/Lecture/' . $lectureId . '/Manage'); } $conferenceId = intval($conference->getId()); $conferenceLectures = $this->dbContext->getLecturesRepository()->filterByConferenceId(" = '{$conferenceId}'")->findAll()->getLectures(); foreach ($conferenceLectures as $confLecture) { if (intval($confLecture->getHallId()) == intval($model->getHallId())) { if (intval($confLecture->getId()) !== intval($lectureId)) { if (strtotime($model->getStartDate()) <= strtotime($confLecture->getStart()) && strtotime($model->getEndDate()) >= strtotime($confLecture->getStart())) { $this->addErrorMessage('The hall is busy during this time span!'); $this->redirectToUrl('/Lecture/' . $lectureId . '/Manage'); } if (strtotime($model->getStartDate()) <= strtotime($confLecture->getEnd()) && strtotime($model->getEndDate()) >= strtotime($confLecture->getEnd())) { $this->addErrorMessage('The hall is busy during this time span!'); $this->redirectToUrl('/Lecture/' . $lectureId . '/Manage'); } if (strtotime($model->getStartDate()) >= strtotime($confLecture->getStart()) && strtotime($model->getEndDate()) <= strtotime($confLecture->getEnd())) { $this->addErrorMessage('The lecture is during other once check the times!'); $this->redirectToUrl('/Lecture/' . $lectureId . '/Manage'); } } } } $lecture = $this->dbContext->getLecturesRepository()->filterById(" = '{$lectureId}'")->findOne(); $lecture->setName($model->getName()); $lecture->setEnd($model->getEndDate()); if ($model->getHallId()) { $lecture->setHallId($model->getHallId()); } $lecture->setStart($model->getStartDate()); $this->dbContext->saveChanges(); $this->redirectToUrl('/Conference/' . $conferenceId . '/Lectures/Manage'); } return new View('lectures', 'edit', $lecture, $viewBag); }