From b01eba2533887432a40bc6f42f48b479e800c504 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 16 Jul 2021 11:58:30 +0200 Subject: [PATCH] rdv: add route, twig for listing and creating calendar items --- .../Controller/CalendarController.php | 551 +++++++++--------- .../ChillCalendarExtension.php | 28 +- .../Repository/CalendarRepository.php | 2 +- .../Resources/config/routing.yml | 3 + .../Resources/config/services.yml | 8 + .../Resources/config/services/controller.yml | 5 + .../config/services/fixtures.yml} | 0 .../Resources/views/Calendar/list.html.twig | 189 ++++++ .../listByAccompanyingCourse.html.twig | 9 + .../Resources/views/Calendar/new.html.twig | 0 .../Calendar/newAccompanyingCourse.html.twig | 37 ++ 11 files changed, 540 insertions(+), 292 deletions(-) create mode 100644 src/Bundle/ChillCalendarBundle/Resources/config/routing.yml create mode 100644 src/Bundle/ChillCalendarBundle/Resources/config/services.yml create mode 100644 src/Bundle/ChillCalendarBundle/Resources/config/services/controller.yml rename src/Bundle/ChillCalendarBundle/{config/services/fixtures.yaml => Resources/config/services/fixtures.yml} (100%) create mode 100644 src/Bundle/ChillCalendarBundle/Resources/views/Calendar/list.html.twig create mode 100644 src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig create mode 100644 src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig create mode 100644 src/Bundle/ChillCalendarBundle/Resources/views/Calendar/newAccompanyingCourse.html.twig diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 616829f19..92771ed32 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -36,7 +36,9 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Role\Role; use Chill\CalendarBundle\Entity\Calendar; use Chill\CalendarBundle\Form\CalendarType; +use Chill\MainBundle\Entity\User; use Symfony\Component\Serializer\SerializerInterface; +use Symfony\Component\Routing\Annotation\Route; /** * Class CalendarController @@ -67,381 +69,374 @@ class CalendarController extends AbstractController /** * Lists all Calendar entities. + * @Route("/{_locale}/calendar/", name="chill_calendar_calendar") */ public function listAction(Request $request): Response { $em = $this->getDoctrine()->getManager(); $view = null; - [$person, $accompanyingPeriod] = $this->getEntity($request); + [$user, $accompanyingPeriod] = $this->getEntity($request); - if ($person instanceof Person) { - $reachableScopes = $this->authorizationHelper - ->getReachableCircles($this->getUser(), new Role('CHILL_Calendar_SEE'), - $person->getCenter()); + if ($user instanceof User) { - $activities = $em->getRepository(Calendar::class) - ->findByPersonImplied($person, $reachableScopes) - ; + // $calendar = $em->getRepository(Calendar::class) + // ->findByUser($user) + // ; - $event = new PrivacyEvent($person, array( - 'element_class' => Calendar::class, - 'action' => 'list' - )); - $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); - - $view = 'ChillCalendarBundle:Calendar:listPerson.html.twig'; + // $view = 'ChillCalendarBundle:Calendar:listByUser.html.twig'; } elseif ($accompanyingPeriod instanceof AccompanyingPeriod) { - $activities = $em->getRepository('ChillCalendarBundle:Calendar')->findBy( - ['accompanyingPeriod' => $accompanyingPeriod], - ['date' => 'DESC'], + $calendarItems = $em->getRepository(Calendar::class)->findBy( + ['accompanyingPeriod' => $accompanyingPeriod] ); - $view = 'ChillCalendarBundle:Calendar:listAccompanyingCourse.html.twig'; + $view = 'ChillCalendarBundle:Calendar:listByAccompanyingCourse.html.twig'; } return $this->render($view, array( - 'activities' => $activities, - 'person' => $person, + 'calendarItems' => $calendarItems, + 'user' => $user, 'accompanyingCourse' => $accompanyingPeriod, )); } - public function selectTypeAction(Request $request): Response - { - $em = $this->getDoctrine()->getManager(); - $view = null; + // public function selectTypeAction(Request $request): Response + // { + // $em = $this->getDoctrine()->getManager(); + // $view = null; - [$person, $accompanyingPeriod] = $this->getEntity($request); + // [$person, $accompanyingPeriod] = $this->getEntity($request); - if ($accompanyingPeriod instanceof AccompanyingPeriod) { - $view = 'ChillCalendarBundle:Calendar:selectTypeAccompanyingCourse.html.twig'; - } elseif ($person instanceof Person) { - $view = 'ChillCalendarBundle:Calendar:selectTypePerson.html.twig'; - } + // if ($accompanyingPeriod instanceof AccompanyingPeriod) { + // $view = 'ChillCalendarBundle:Calendar:selectTypeAccompanyingCourse.html.twig'; + // } elseif ($person instanceof Person) { + // $view = 'ChillCalendarBundle:Calendar:selectTypePerson.html.twig'; + // } - $data = []; + // $data = []; - $activityTypeCategories = $em->getRepository(\Chill\CalendarBundle\Entity\ActivityTypeCategory::class) - ->findBy(['active' => true], ['ordering' => 'ASC']); + // $activityTypeCategories = $em->getRepository(\Chill\CalendarBundle\Entity\ActivityTypeCategory::class) + // ->findBy(['active' => true], ['ordering' => 'ASC']); - foreach ($activityTypeCategories as $activityTypeCategory) { - $activityTypes = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) - ->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']); + // foreach ($activityTypeCategories as $activityTypeCategory) { + // $activityTypes = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) + // ->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']); - $data[] = [ - 'activityTypeCategory' => $activityTypeCategory, - 'activityTypes' => $activityTypes, - ]; - } + // $data[] = [ + // 'activityTypeCategory' => $activityTypeCategory, + // 'activityTypes' => $activityTypes, + // ]; + // } - if ($view === null) { - throw $this->createNotFoundException('Template not found'); - } + // if ($view === null) { + // throw $this->createNotFoundException('Template not found'); + // } - return $this->render($view, [ - 'person' => $person, - 'accompanyingCourse' => $accompanyingPeriod, - 'data' => $data, - ]); - } + // return $this->render($view, [ + // 'person' => $person, + // 'accompanyingCourse' => $accompanyingPeriod, + // 'data' => $data, + // ]); + // } + /** + * Create a new calendar item + * @Route("/{_locale}/calendar/new", name="chill_calendar_calendar_new") + */ public function newAction(Request $request): Response { $em = $this->getDoctrine()->getManager(); - [$person, $accompanyingPeriod] = $this->getEntity($request); + [$user, $accompanyingPeriod] = $this->getEntity($request); if ($accompanyingPeriod instanceof AccompanyingPeriod) { $view = 'ChillCalendarBundle:Calendar:newAccompanyingCourse.html.twig'; - } elseif ($person instanceof Person) { - $view = 'ChillCalendarBundle:Calendar:newPerson.html.twig'; - } + } + // elseif ($user instanceof User) { + // $view = 'ChillCalendarBundle:Calendar:newUser.html.twig'; + // } - $activityType_id = $request->get('activityType_id', 0); - $activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) - ->find($activityType_id); + // $activityType_id = $request->get('activityType_id', 0); + // $activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) + // ->find($activityType_id); - if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType || - !$activityType->isActive()) { + // if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType || + // !$activityType->isActive()) { - $params = $this->buildParamsToUrl($person, $accompanyingPeriod); - return $this->redirectToRoute('chill_activity_activity_select_type', $params); - } + // $params = $this->buildParamsToUrl($user, $accompanyingPeriod); + // return $this->redirectToRoute('chill_activity_activity_select_type', $params); + // } $entity = new Calendar(); $entity->setUser($this->getUser()); - if ($person instanceof Person) { - $entity->setPerson($person); - } + // if ($user instanceof User) { + // $entity->setPerson($user); + // } if ($accompanyingPeriod instanceof AccompanyingPeriod) { $entity->setAccompanyingPeriod($accompanyingPeriod); } - $entity->setType($activityType); - $entity->setDate(new \DateTime('now')); + // $entity->setType($activityType); + // $entity->setDate(new \DateTime('now')); - // TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période - // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity); + // $form = $this->createForm(ActivityType::class, $entity, [ + // 'center' => $entity->getCenter(), + // 'role' => new Role('CHILL_ACTIVITY_CREATE'), + // 'activityType' => $entity->getType(), + // 'accompanyingPeriod' => $accompanyingPeriod, + // ])->handleRequest($request); - $form = $this->createForm(ActivityType::class, $entity, [ - 'center' => $entity->getCenter(), - 'role' => new Role('CHILL_ACTIVITY_CREATE'), - 'activityType' => $entity->getType(), - 'accompanyingPeriod' => $accompanyingPeriod, - ])->handleRequest($request); + // if ($form->isSubmitted() && $form->isValid()) { + // $em->persist($entity); + // $em->flush(); - if ($form->isSubmitted() && $form->isValid()) { - $em->persist($entity); - $em->flush(); + // $this->addFlash('success', $this->get('translator')->trans('Success : activity created!')); - $this->addFlash('success', $this->get('translator')->trans('Success : activity created!')); + // $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + // $params['id'] = $entity->getId(); - $params = $this->buildParamsToUrl($person, $accompanyingPeriod); - $params['id'] = $entity->getId(); + // return $this->redirectToRoute('chill_activity_activity_show', $params); + // } - return $this->redirectToRoute('chill_activity_activity_show', $params); - } + // if ($view === null) { + // throw $this->createNotFoundException('Template not found'); + // } - if ($view === null) { - throw $this->createNotFoundException('Template not found'); - } - - $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); + // $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); return $this->render($view, [ - 'person' => $person, + 'user' => $user, 'accompanyingCourse' => $accompanyingPeriod, 'entity' => $entity, - 'form' => $form->createView(), - 'activity_json' => $activity_array + // 'form' => $form->createView(), + //'activity_json' => $calendar_array ]); } - public function showAction(Request $request, $id): Response - { - $em = $this->getDoctrine()->getManager(); + // public function showAction(Request $request, $id): Response + // { + // $em = $this->getDoctrine()->getManager(); - [$person, $accompanyingPeriod] = $this->getEntity($request); + // [$person, $accompanyingPeriod] = $this->getEntity($request); - if ($accompanyingPeriod instanceof AccompanyingPeriod) { - $view = 'ChillCalendarBundle:Calendar:showAccompanyingCourse.html.twig'; - } elseif ($person instanceof Person) { - $view = 'ChillCalendarBundle:Calendar:showPerson.html.twig'; - } + // if ($accompanyingPeriod instanceof AccompanyingPeriod) { + // $view = 'ChillCalendarBundle:Calendar:showAccompanyingCourse.html.twig'; + // } elseif ($person instanceof Person) { + // $view = 'ChillCalendarBundle:Calendar:showPerson.html.twig'; + // } - $entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); + // $entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); - if (!$entity) { - throw $this->createNotFoundException('Unable to find Calendar entity.'); - } + // if (!$entity) { + // throw $this->createNotFoundException('Unable to find Calendar entity.'); + // } - if (null !== $accompanyingPeriod) { - $entity->personsAssociated = $entity->getPersonsAssociated(); - $entity->personsNotAssociated = $entity->getPersonsNotAssociated(); - } + // if (null !== $accompanyingPeriod) { + // $entity->personsAssociated = $entity->getPersonsAssociated(); + // $entity->personsNotAssociated = $entity->getPersonsNotAssociated(); + // } - // TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période - // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_SEE', $entity); + // // TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période + // // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_SEE', $entity); - $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod); + // $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod); - // TODO - /* - $event = new PrivacyEvent($person, array( - 'element_class' => Activity::class, - 'element_id' => $entity->getId(), - 'action' => 'show' - )); - $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); - */ + // // TODO + // /* + // $event = new PrivacyEvent($person, array( + // 'element_class' => Activity::class, + // 'element_id' => $entity->getId(), + // 'action' => 'show' + // )); + // $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); + // */ - if ($view === null) { - throw $this->createNotFoundException('Template not found'); - } + // if ($view === null) { + // throw $this->createNotFoundException('Template not found'); + // } - return $this->render($view, array( - 'person' => $person, - 'accompanyingCourse' => $accompanyingPeriod, - 'entity' => $entity, - 'delete_form' => $deleteForm->createView(), - )); - } + // return $this->render($view, array( + // 'person' => $person, + // 'accompanyingCourse' => $accompanyingPeriod, + // 'entity' => $entity, + // 'delete_form' => $deleteForm->createView(), + // )); + // } - /** - * Displays a form to edit an existing Activity entity. - * - */ - public function editAction($id, Request $request): Response - { - $em = $this->getDoctrine()->getManager(); + // /** + // * Displays a form to edit an existing Activity entity. + // * + // */ + // public function editAction($id, Request $request): Response + // { + // $em = $this->getDoctrine()->getManager(); - [$person, $accompanyingPeriod] = $this->getEntity($request); + // [$person, $accompanyingPeriod] = $this->getEntity($request); - if ($accompanyingPeriod instanceof AccompanyingPeriod) { - $view = 'ChillCalendarBundle:Calendar:editAccompanyingCourse.html.twig'; - } elseif ($person instanceof Person) { - $view = 'ChillCalendarBundle:Calendar:editPerson.html.twig'; - } + // if ($accompanyingPeriod instanceof AccompanyingPeriod) { + // $view = 'ChillCalendarBundle:Calendar:editAccompanyingCourse.html.twig'; + // } elseif ($person instanceof Person) { + // $view = 'ChillCalendarBundle:Calendar:editPerson.html.twig'; + // } - $entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); + // $entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); - if (!$entity) { - throw $this->createNotFoundException('Unable to find Calendar entity.'); - } + // if (!$entity) { + // throw $this->createNotFoundException('Unable to find Calendar entity.'); + // } - // TODO - // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity); + // // TODO + // // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity); - $form = $this->createForm(CalendarType::class, $entity, [ - 'center' => $entity->getCenter(), - 'role' => new Role('CHILL_ACTIVITY_UPDATE'), - 'activityType' => $entity->getType(), - 'accompanyingPeriod' => $accompanyingPeriod, - ])->handleRequest($request); + // $form = $this->createForm(CalendarType::class, $entity, [ + // 'center' => $entity->getCenter(), + // 'role' => new Role('CHILL_ACTIVITY_UPDATE'), + // 'activityType' => $entity->getType(), + // 'accompanyingPeriod' => $accompanyingPeriod, + // ])->handleRequest($request); - if ($form->isSubmitted() && $form->isValid()) { - $em->persist($entity); - $em->flush(); + // if ($form->isSubmitted() && $form->isValid()) { + // $em->persist($entity); + // $em->flush(); - $this->addFlash('success', $this->get('translator')->trans('Success : activity updated!')); + // $this->addFlash('success', $this->get('translator')->trans('Success : activity updated!')); - $params = $this->buildParamsToUrl($person, $accompanyingPeriod); - $params['id'] = $id; - return $this->redirectToRoute('chill_activity_activity_show', $params); - } + // $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + // $params['id'] = $id; + // return $this->redirectToRoute('chill_activity_activity_show', $params); + // } - $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod); + // $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod); - /* - * TODO - $event = new PrivacyEvent($person, array( - 'element_class' => Calendar::class, - 'element_id' => $entity->getId(), - 'action' => 'edit' - )); - $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); - */ + // /* + // * TODO + // $event = new PrivacyEvent($person, array( + // 'element_class' => Calendar::class, + // 'element_id' => $entity->getId(), + // 'action' => 'edit' + // )); + // $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); + // */ - if ($view === null) { - throw $this->createNotFoundException('Template not found'); - } + // if ($view === null) { + // throw $this->createNotFoundException('Template not found'); + // } - $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); + // $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); - return $this->render($view, array( - 'entity' => $entity, - 'edit_form' => $form->createView(), - 'delete_form' => $deleteForm->createView(), - 'person' => $person, - 'accompanyingCourse' => $accompanyingPeriod, - 'activity_json' => $activity_array - )); - } + // return $this->render($view, array( + // 'entity' => $entity, + // 'edit_form' => $form->createView(), + // 'delete_form' => $deleteForm->createView(), + // 'person' => $person, + // 'accompanyingCourse' => $accompanyingPeriod, + // 'activity_json' => $activity_array + // )); + // } - /** - * Deletes a Calendar entity. - * - */ - public function deleteAction(Request $request, $id) - { - $em = $this->getDoctrine()->getManager(); + // /** + // * Deletes a Calendar entity. + // * + // */ + // public function deleteAction(Request $request, $id) + // { + // $em = $this->getDoctrine()->getManager(); - [$person, $accompanyingPeriod] = $this->getEntity($request); + // [$person, $accompanyingPeriod] = $this->getEntity($request); - if ($accompanyingPeriod instanceof AccompanyingPeriod) { - $view = 'ChillCalendarBundle:Calendar:confirm_deleteAccompanyingCourse.html.twig'; - } elseif ($person instanceof Person) { - $view = 'ChillCalendarBundle:Calendar:confirm_deletePerson.html.twig'; - } + // if ($accompanyingPeriod instanceof AccompanyingPeriod) { + // $view = 'ChillCalendarBundle:Calendar:confirm_deleteAccompanyingCourse.html.twig'; + // } elseif ($person instanceof Person) { + // $view = 'ChillCalendarBundle:Calendar:confirm_deletePerson.html.twig'; + // } - /* @var $activity Calendar */ - $activity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); + // /* @var $activity Calendar */ + // $activity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); - if (!$activity) { - throw $this->createNotFoundException('Unable to find Calendar entity.'); - } + // if (!$activity) { + // throw $this->createNotFoundException('Unable to find Calendar entity.'); + // } - // TODO - // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity); + // // TODO + // // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity); - $form = $this->createDeleteForm($id, $person, $accompanyingPeriod); + // $form = $this->createDeleteForm($id, $person, $accompanyingPeriod); - if ($request->getMethod() === Request::METHOD_DELETE) { - $form->handleRequest($request); + // if ($request->getMethod() === Request::METHOD_DELETE) { + // $form->handleRequest($request); - if ($form->isValid()) { + // if ($form->isValid()) { - $this->logger->notice("An activity has been removed", array( - 'by_user' => $this->getUser()->getUsername(), - 'activity_id' => $activity->getId(), - 'person_id' => $activity->getPerson() ? $activity->getPerson()->getId() : null, - 'comment' => $activity->getComment()->getComment(), - 'scope_id' => $activity->getScope() ? $activity->getScope()->getId() : null, - 'reasons_ids' => $activity->getReasons() - ->map(function ($ar) { return $ar->getId(); }) - ->toArray(), - 'type_id' => $activity->getType()->getId(), - 'duration' => $activity->getDurationTime() ? $activity->getDurationTime()->format('U') : null, - 'date' => $activity->getDate()->format('Y-m-d'), - 'attendee' => $activity->getAttendee() - )); + // $this->logger->notice("An activity has been removed", array( + // 'by_user' => $this->getUser()->getUsername(), + // 'activity_id' => $activity->getId(), + // 'person_id' => $activity->getPerson() ? $activity->getPerson()->getId() : null, + // 'comment' => $activity->getComment()->getComment(), + // 'scope_id' => $activity->getScope() ? $activity->getScope()->getId() : null, + // 'reasons_ids' => $activity->getReasons() + // ->map(function ($ar) { return $ar->getId(); }) + // ->toArray(), + // 'type_id' => $activity->getType()->getId(), + // 'duration' => $activity->getDurationTime() ? $activity->getDurationTime()->format('U') : null, + // 'date' => $activity->getDate()->format('Y-m-d'), + // 'attendee' => $activity->getAttendee() + // )); - $em->remove($activity); - $em->flush(); + // $em->remove($activity); + // $em->flush(); - $this->addFlash('success', $this->get('translator') - ->trans("The activity has been successfully removed.")); + // $this->addFlash('success', $this->get('translator') + // ->trans("The activity has been successfully removed.")); - $params = $this->buildParamsToUrl($person, $accompanyingPeriod); - return $this->redirectToRoute('chill_activity_activity_list', $params); - } - } + // $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + // return $this->redirectToRoute('chill_activity_activity_list', $params); + // } + // } - if ($view === null) { - throw $this->createNotFoundException('Template not found'); - } + // if ($view === null) { + // throw $this->createNotFoundException('Template not found'); + // } - return $this->render($view, array( - 'activity' => $activity, - 'delete_form' => $form->createView(), - 'person' => $person, - 'accompanyingCourse' => $accompanyingPeriod, - )); - } + // return $this->render($view, array( + // 'activity' => $activity, + // 'delete_form' => $form->createView(), + // 'person' => $person, + // 'accompanyingCourse' => $accompanyingPeriod, + // )); + // } - /** - * Creates a form to delete a Calendar entity by id. - */ - private function createDeleteForm(int $id, ?Person $person, ?AccompanyingPeriod $accompanyingPeriod): Form - { - $params = $this->buildParamsToUrl($person, $accompanyingPeriod); - $params['id'] = $id; + // /** + // * Creates a form to delete a Calendar entity by id. + // */ + // private function createDeleteForm(int $id, ?Person $person, ?AccompanyingPeriod $accompanyingPeriod): Form + // { + // $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + // $params['id'] = $id; - return $this->createFormBuilder() - ->setAction($this->generateUrl('chill_activity_activity_delete', $params)) - ->setMethod('DELETE') - ->add('submit', SubmitType::class, array('label' => 'Delete')) - ->getForm() - ; - } + // return $this->createFormBuilder() + // ->setAction($this->generateUrl('chill_activity_activity_delete', $params)) + // ->setMethod('DELETE') + // ->add('submit', SubmitType::class, array('label' => 'Delete')) + // ->getForm() + // ; + // } private function getEntity(Request $request): array { $em = $this->getDoctrine()->getManager(); - $person = $accompanyingPeriod = null; + $user = $accompanyingPeriod = null; - if ($request->query->has('person_id')) { - $person_id = $request->get('person_id'); - $person = $em->getRepository(Person::class)->find($person_id); + if ($request->query->has('user_id')) { + $user_id = $request->get('user_id'); + $user = $em->getRepository(User::class)->find($user_id); - if ($person === null) { - throw $this->createNotFoundException('Person not found'); + if ($user === null) { + throw $this->createNotFoundException('User not found'); } - $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $user); } elseif ($request->query->has('accompanying_period_id')) { $accompanying_period_id = $request->get('accompanying_period_id'); $accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($accompanying_period_id); @@ -457,24 +452,24 @@ class CalendarController extends AbstractController } return [ - $person, $accompanyingPeriod + $user, $accompanyingPeriod ]; } - private function buildParamsToUrl( - ?Person $person, - ?AccompanyingPeriod $accompanyingPeriod - ): array { - $params = []; + // private function buildParamsToUrl( + // ?Person $person, + // ?AccompanyingPeriod $accompanyingPeriod + // ): array { + // $params = []; - if ($person) { - $params['person_id'] = $person->getId(); - } + // if ($person) { + // $params['person_id'] = $person->getId(); + // } - if ($accompanyingPeriod) { - $params['accompanying_period_id'] = $accompanyingPeriod->getId(); - } + // if ($accompanyingPeriod) { + // $params['accompanying_period_id'] = $accompanyingPeriod->getId(); + // } - return $params; - } + // return $params; + // } } diff --git a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php index a1f68da1e..5804b93ff 100644 --- a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php +++ b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php @@ -23,26 +23,28 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); - $loader->load('services/fixtures.yaml'); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); + $loader->load('services/controller.yml'); + $loader->load('services/fixtures.yml'); } public function prepend(ContainerBuilder $container) { - // $this->preprendRoutes($container); + $this->preprendRoutes($container); } - // protected function preprendRoutes(ContainerBuilder $container) - // { + protected function preprendRoutes(ContainerBuilder $container) + { - // $container->prependExtensionConfig('chill_main', array( - // 'routing' => array( - // 'resources' => array( - // '@ChillCalendarBundle/config/routes.yaml' - // ) - // ) - // )); - // } + $container->prependExtensionConfig('chill_main', array( + 'routing' => array( + 'resources' => array( + '@ChillCalendarBundle/Resources/config/routing.yml' + ) + ) + )); + } } diff --git a/src/Bundle/ChillCalendarBundle/Repository/CalendarRepository.php b/src/Bundle/ChillCalendarBundle/Repository/CalendarRepository.php index 4f99c6d8e..edb51bb35 100644 --- a/src/Bundle/ChillCalendarBundle/Repository/CalendarRepository.php +++ b/src/Bundle/ChillCalendarBundle/Repository/CalendarRepository.php @@ -2,7 +2,7 @@ namespace Chill\CalendarBundle\Repository; -use CalendarBundle\Entity\Calendar; +use Chill\CalendarBundle\Entity\Calendar; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; diff --git a/src/Bundle/ChillCalendarBundle/Resources/config/routing.yml b/src/Bundle/ChillCalendarBundle/Resources/config/routing.yml new file mode 100644 index 000000000..70ce2b6d4 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/config/routing.yml @@ -0,0 +1,3 @@ +chill_calendar_controllers: + resource: '../../Controller/' + type: annotation diff --git a/src/Bundle/ChillCalendarBundle/Resources/config/services.yml b/src/Bundle/ChillCalendarBundle/Resources/config/services.yml new file mode 100644 index 000000000..4810e877b --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services.yml @@ -0,0 +1,8 @@ +--- +services: + + Chill\CalendarBundle\Repository\: + autowire: true + resource: '../../Repository/' + tags: + - { name: 'doctrine.repository_service' } diff --git a/src/Bundle/ChillCalendarBundle/Resources/config/services/controller.yml b/src/Bundle/ChillCalendarBundle/Resources/config/services/controller.yml new file mode 100644 index 000000000..a0457c5a8 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services/controller.yml @@ -0,0 +1,5 @@ +services: + Chill\CalendarBundle\Controller\: + autowire: true + resource: '../../../Controller' + tags: ['controller.service_arguments'] diff --git a/src/Bundle/ChillCalendarBundle/config/services/fixtures.yaml b/src/Bundle/ChillCalendarBundle/Resources/config/services/fixtures.yml similarity index 100% rename from src/Bundle/ChillCalendarBundle/config/services/fixtures.yaml rename to src/Bundle/ChillCalendarBundle/Resources/config/services/fixtures.yml diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/list.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/list.html.twig new file mode 100644 index 000000000..94b5f772b --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/list.html.twig @@ -0,0 +1,189 @@ +{% set user_id = null %} +{% if user %} + {% set user_id = user.id %} +{% endif %} + +{% set accompanying_course_id = null %} +{% if accompanyingCourse %} + {% set accompanying_course_id = accompanyingCourse.id %} +{% endif %} + +

{{ 'Calendar list' |trans }}

+ +{% if calendarItems|length == 0 %} +

+ {{ "There is no calendar items."|trans }} + +

+{% else %} + +
+ + {% for calendar in calendarItems %} + + + {% set t = calendar.type %} +
+
+
+ + {% if calendar.date %} +

{{ calendar.date|format_date('long') }}

+ {% endif %} + +
+ {% if t.durationTimeVisible > 0 %} +

+ + {{ calendar.durationTime|date('H:i') }} +

+ {% endif %} + + {% if calendar.travelTime and t.travelTimeVisible %} +

+ + {{ calendar.travelTime|date('H:i') }} +

+ {% endif %} +
+ + {% if context == 'user' and calendar.accompanyingPeriod is not empty %} + + {% endif %} + +
+
+
    + {% if calendar.user and t.userVisible %} +
  • + {{ 'by'|trans }}{{ calendar.user.usernameCanonical }} +
  • + {% endif %} + +
  • + {{ calendar.type.name | localize_translatable_string }} + + {% if calendar.attendee is not null and t.attendeeVisible %} + {% if calendar.attendee %} + {{ '→ ' ~ 'present'|trans|capitalize }} + {% else %} + {{ '→ ' ~ 'not present'|trans|capitalize }} + {% endif %} + {% endif %} +
  • + +
  • + {{ 'location'|trans ~ ': ' }} + Domicile de l'usager + {# + {% if calendar.location %}{{ calendar.location }}{% endif %} + #} +
  • + + {%- if t.reasonsVisible -%} +
  • + {%- if calendar.reasons is empty -%} + {{ 'No reason associated'|trans }} + {%- else -%} + {% for r in calendar.reasons %} + {{ r|chill_entity_render_box }} + {% endfor %} + {%- endif -%} +
  • + {% endif %} + + {%- if t.socialIssuesVisible %} + + {% endif %} + + {%- if t.socialActionsVisible -%} + + {% endif %} + + +
+
    +
  • + +
  • + {# TOOD + {% if is_granted('CHILL_ACTIVITY_UPDATE', calendar) %} + #} +
  • + +
  • + {# TOOD + {% endif %} + {% if is_granted('CHILL_ACTIVITY_DELETE', calendar) %} + #} +
  • + +
  • + {# + {% endif %} + #} +
+
+
+ + {% + if calendar.comment.comment is not empty + or calendar.users|length > 0 + or calendar.thirdParties|length > 0 + or calendar.users|length > 0 + %} +
+
+ + {% include 'ChillCalendarBundle:Calendar:concernedGroups.html.twig' with {'context': context, 'with_display': 'row', 'entity': calendar } %} +
+ + {% if calendar.comment.comment is not empty %} +
+ {{ calendar.comment|chill_entity_render_box( { 'limit_lines': 3, 'metadata': false } ) }} +
+ {% endif %} +
+ {% endif %} + +
+ {% endfor %} +
+{% endif %} + +{% if context != 'user' %} +{# TODO set this condition in configuration #} + +{% endif %} diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig new file mode 100644 index 000000000..c0230344d --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig @@ -0,0 +1,9 @@ +{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %} + +{% set activeRouteKey = 'chill_calendar_calendar_list' %} + +{% block title %}{{ 'Calendar list' |trans }}{% endblock title %} + +{% block content %} + {% include 'ChillCalendarBundle:Calendar:list.html.twig' with {'context': 'accompanyingCourse'} %} +{% endblock %} diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig new file mode 100644 index 000000000..e69de29bb diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/newAccompanyingCourse.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/newAccompanyingCourse.html.twig new file mode 100644 index 000000000..3cc1f9486 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/newAccompanyingCourse.html.twig @@ -0,0 +1,37 @@ +{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %} + +{% set activeRouteKey = 'chill_calendar_calendar_new' %} + +{% block title 'Calendar creation' |trans %} + +{% block content %} +
+
+
+ +
{# <=== vue component #} + {% include 'ChillCalendarBundle:Calendar:new.html.twig' with {'context': 'accompanyingCourse'} %} + +
+
+
+{% endblock %} + +{% block js %} + {{ parent() }} + {{ encore_entry_script_tags('async_upload') }} + + {{ encore_entry_script_tags('vue_calendar') }} +{% endblock %} + +{% block css %} + {{ parent() }} + + {{ encore_entry_link_tags('vue_calendar') }} +{% endblock %}