diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php index 5791d1ad9..512747b01 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php @@ -72,26 +72,12 @@ class DocumentAccompanyingCourseController extends AbstractController $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::SEE, $course); - // $reachableScopes = $this->authorizationHelper - // ->getReachableScopes( - // $this->getUser(), new Role(PersonDocumentVoter::SEE), - // $person->getCenter()); - $documents = $em ->getRepository("ChillDocStoreBundle:AccompanyingCourseDocument") ->findBy( ['course' => $course], ['date' => 'DESC'] ); - - // dump($course); - // dump($documents); - - // $event = new PrivacyEvent($course, [ - // 'element_class' => AccompanyingCourseDocument::class, - // 'action' => 'index' - // ]); - // $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); return $this->render( 'ChillDocStoreBundle:AccompanyingCourseDocument:index.html.twig', @@ -121,9 +107,9 @@ class DocumentAccompanyingCourseController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - // $this->denyAccessUnlessGranted( - // 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_CREATE', $document, - // 'creation of this activity not allowed'); + $this->denyAccessUnlessGranted( + 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_CREATE', $document, + 'creation of this activity not allowed'); $em = $this->getDoctrine()->getManager(); $em->persist($document); @@ -150,13 +136,6 @@ class DocumentAccompanyingCourseController extends AbstractController { $this->denyAccessUnlessGranted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', $course); $this->denyAccessUnlessGranted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_SEE', $document); - - // $event = new PrivacyEvent($person, array( - // 'element_class' => PersonDocument::class, - // 'element_id' => $document->getId(), - // 'action' => 'show' - // )); - // $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); return $this->render( 'ChillDocStoreBundle:AccompanyingCourseDocument:show.html.twig', @@ -169,7 +148,7 @@ class DocumentAccompanyingCourseController extends AbstractController public function edit(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response { $this->denyAccessUnlessGranted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', $course); - $this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_UPDATE', $document); + $this->denyAccessUnlessGranted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_UPDATE', $document); $document->setUser($this->getUser()); $document->setDate(new \DateTime('Now')); @@ -182,28 +161,14 @@ class DocumentAccompanyingCourseController extends AbstractController $this->getDoctrine()->getManager()->flush(); $this->addFlash('success', $this->translator->trans("The document is successfully updated")); - - // $event = new PrivacyEvent($person, array( - // 'element_class' => PersonDocument::class, - // 'element_id' => $document->getId(), - // 'action' => 'update' - // )); - // $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); return $this->redirectToRoute( 'accompanying_course_document_edit', - ['id' => $document->getId(), 'accompanyingCourse' => $course->getId()]); + ['id' => $document->getId(), 'course' => $course->getId()]); } elseif ($form->isSubmitted() and !$form->isValid()) { $this->addFlash('error', $this->translator->trans("This form contains errors")); } - - // $event = new PrivacyEvent($person, array( - // 'element_class' => PersonDocument::class, - // 'element_id' => $document->getId(), - // 'action' => 'edit' - // )); - // $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); return $this->render( 'ChillDocStoreBundle:AccompanyingCourseDocument:edit.html.twig', @@ -220,7 +185,7 @@ class DocumentAccompanyingCourseController extends AbstractController public function delete(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response { $this->denyAccessUnlessGranted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', $course); - $this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_DELETE', $document); + $this->denyAccessUnlessGranted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_DELETE', $document); if ($this->isCsrfTokenValid('delete'.$document->getId(), $request->request->get('_token'))) { $em = $this->getDoctrine()->getManager(); diff --git a/src/Bundle/ChillDocStoreBundle/Entity/AccompanyingCourseDocument.php b/src/Bundle/ChillDocStoreBundle/Entity/AccompanyingCourseDocument.php index 3649bd51c..fd3ba93bc 100644 --- a/src/Bundle/ChillDocStoreBundle/Entity/AccompanyingCourseDocument.php +++ b/src/Bundle/ChillDocStoreBundle/Entity/AccompanyingCourseDocument.php @@ -16,12 +16,7 @@ class AccompanyingCourseDocument extends Document * @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class) * @ORM\JoinColumn(nullable=false) */ - private $course; - - public function getId(): ?int - { - return $this->id; - } + private ?AccompanyingPeriod $course = null; public function getCourse(): ?AccompanyingPeriod { diff --git a/src/Bundle/ChillDocStoreBundle/Form/AccompanyingCourseDocumentType.php b/src/Bundle/ChillDocStoreBundle/Form/AccompanyingCourseDocumentType.php index bdaea7ee0..b1a113a0a 100644 --- a/src/Bundle/ChillDocStoreBundle/Form/AccompanyingCourseDocumentType.php +++ b/src/Bundle/ChillDocStoreBundle/Form/AccompanyingCourseDocumentType.php @@ -66,6 +66,7 @@ class AccompanyingCourseDocumentType extends AbstractType 'error_bubbling' => true ]) ->add('date', ChillDateType::class) + //TODO : adapt to using AccompanyingCourseDocument categories. Currently there are none... ->add('category', EntityType::class, array( 'placeholder' => 'Choose a document category', 'class' => 'ChillDocStoreBundle:DocumentCategory', diff --git a/src/Bundle/ChillDocStoreBundle/Menu/MenuBuilder.php b/src/Bundle/ChillDocStoreBundle/Menu/MenuBuilder.php index 03a8b7038..c48d45833 100644 --- a/src/Bundle/ChillDocStoreBundle/Menu/MenuBuilder.php +++ b/src/Bundle/ChillDocStoreBundle/Menu/MenuBuilder.php @@ -50,6 +50,9 @@ class MenuBuilder implements LocalMenuBuilderInterface public function buildMenu($menuId, MenuItem $menu, array $parameters) { switch($menuId) { + case 'accompanyingCourse': + $this->buildMenuAccompanyingCourse($menu, $parameters); + break; case 'person': $this->buildMenuPerson($menu, $parameters); break; @@ -57,7 +60,7 @@ class MenuBuilder implements LocalMenuBuilderInterface throw new \LogicException("this menuid $menuId is not implemented"); } } - + protected function buildMenuPerson(MenuItem $menu, array $parameters) { /* @var $person \Chill\PersonBundle\Entity\Person */ @@ -80,8 +83,25 @@ class MenuBuilder implements LocalMenuBuilderInterface } + protected function buildMenuAccompanyingCourse(MenuItem $menu, array $parameters){ + $course = $parameters['accompanyingCourse']; + // $user = $this->tokenStorage->getToken()->getUser(); + + //TODO : add condition to check user rights? + + $menu->addChild($this->translator->trans('Documents'), [ + 'route' => 'accompanying_course_document_index', + 'routeParameters' => [ + 'course' => $course->getId() + ] + ]) + ->setExtras([ + 'order'=> 400 + ]); + } + public static function getMenuIds(): array { - return [ 'person' ]; + return [ 'person', 'accompanyingCourse' ]; } } diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig index e2b0a9559..3ca7291b2 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig +++ b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig @@ -5,7 +5,7 @@ {% block title %} {# {{ 'Editing document for %name%'|trans({ '%name%': accompanyingCourse|chill_entity_render_string } ) }} #} {% endblock %} -{% block accompanyingCoursecontent %} +{% block content %}

{{ 'Edit Document' | trans }}

@@ -16,13 +16,12 @@ {{ form_row(form.title) }} {{ form_row(form.date) }} {{ form_row(form.category) }} - {{ form_row(form.scope) }} {{ form_row(form.description) }} {{ form_row(form.object, { 'label': 'Document', 'existing': document.object }) }}