/** * @Authorize * @Route("Conference/{int id}/Delete") */ public function delete() { $id = intval(func_get_args()[0]); $loggedUserId = $this->identity->getUserId(); $service = new LecturesService($this->dbContext); $conference = $this->dbContext->getConferencesRepository()->filterById(" = '{$id}'")->findOne(); if (!$conference->getId()) { $this->addErrorMessage('No such conference!'); $this->redirect('Me', 'Conferences'); } if (!$this->identity->isInRole("Admin")) { if (intval($conference->getOwnerId()) !== $loggedUserId) { $this->addErrorMessage('You are not allowed to edit this conference!'); $this->redirect('Me', 'Conferences'); } } $this->dbContext->getConferenceadminsRepository()->filterByConferenceId(" = '{$id}'")->delete(); $lectures = $this->dbContext->getLecturesRepository()->filterByConferenceId(" = '{$id}'")->findAll()->getLectures(); foreach ($lectures as $l) { $service->delete(intval($l->getId())); } $this->dbContext->getConferencesRepository()->filterById(" = '{$id}'")->delete(); $this->dbContext->saveChanges(); $this->addInfoMessage("Conference deleted!"); $this->redirectToUrl("/Me/Conferences"); }
/** * @Authorize * @Route("Lecture/{int id}/Delete") */ public function delete() { $lectureId = intval(func_get_args()[0]); $loggedUserId = $this->identity->getUserId(); $service = new LecturesService($this->dbContext); $confService = new ConferenceService($this->dbContext); $lecture = $service->getOne($lectureId); if ($lecture == null) { $this->addErrorMessage('No such conference!'); $this->redirect('home'); } $id = intval($lecture->getConferenceId()); $conference = $confService->getOne($id); $conferenceOwner = intval($conference->getOwnerId()); if (!$this->identity->isInRole("Admin")) { if ($conferenceOwner !== $loggedUserId) { $this->addErrorMessage('You cannot edit this conference lectures!'); $this->redirectToUrl('/Me/Conferences'); } } $service->delete($lectureId); $this->addInfoMessage("Lecture deleted!"); $this->redirectToUrl("/Conference/{$id}/Lectures/Manage"); }