denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::DELETE, $document); $form = $this->createForm(FormType::class); $form->add('submit', SubmitType::class, ['label' => 'Delete']); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->managerRegistry->getManager()->remove($document); $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('The document is successfully removed')); if ($request->query->has('returnPath')) { return $this->redirect($request->query->get('returnPath')); } return $this->redirectToRoute('chill_docstore_generic-doc_by-period_index', ['id' => $course->getId()]); } return $this->render( '@ChillDocStore/AccompanyingCourseDocument/delete.html.twig', [ 'document' => $document, 'delete_form' => $form->createView(), 'accompanyingCourse' => $course, ] ); } #[Route(path: '/{id}/edit', name: 'accompanying_course_document_edit', methods: 'GET|POST')] public function edit(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response { $this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::UPDATE, $document); $document->setUser($this->getUser()); $document->setDate(new \DateTime('Now')); $form = $this->createForm( AccompanyingCourseDocumentType::class, $document ); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('The document is successfully updated')); return $this->redirectToRoute( 'accompanying_course_document_edit', ['id' => $document->getId(), 'course' => $course->getId()] ); } if ($form->isSubmitted() && !$form->isValid()) { $this->addFlash('error', $this->translator->trans('This form contains errors')); } return $this->render( '@ChillDocStore/AccompanyingCourseDocument/edit.html.twig', [ 'document' => $document, 'form' => $form->createView(), 'accompanyingCourse' => $course, ] ); } #[Route(path: '/new', name: 'accompanying_course_document_new', methods: 'GET|POST')] public function new(Request $request, AccompanyingPeriod $course): Response { if (null === $course) { throw $this->createNotFoundException('Accompanying period not found'); } $document = new AccompanyingCourseDocument(); $document->setUser($this->getUser()); $document->setCourse($course); $document->setDate(new \DateTime('Now')); $this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::CREATE, $document); $form = $this->createForm(AccompanyingCourseDocumentType::class, $document); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->denyAccessUnlessGranted( 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_CREATE', $document, 'creation of this activity not allowed' ); $em = $this->managerRegistry->getManager(); $em->persist($document); $em->flush(); $this->addFlash('success', $this->translator->trans('The document is successfully registered')); return $this->redirectToRoute('chill_docstore_generic-doc_by-period_index', ['id' => $course->getId()]); } if ($form->isSubmitted() && !$form->isValid()) { $this->addFlash('error', $this->translator->trans('This form contains errors')); } return $this->render('@ChillDocStore/AccompanyingCourseDocument/new.html.twig', [ 'document' => $document, 'form' => $form->createView(), 'accompanyingCourse' => $course, ]); } #[Route(path: '/{id}', name: 'accompanying_course_document_show', methods: 'GET')] public function show(AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response { $this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::SEE_DETAILS, $document); return $this->render( '@ChillDocStore/AccompanyingCourseDocument/show.html.twig', ['document' => $document, 'accompanyingCourse' => $course] ); } }