diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index b84f72d73..b9952a45d 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -199,213 +199,194 @@ class CalendarController extends AbstractController ]); } - // public function showAction(Request $request, $id): Response - // { - // $em = $this->getDoctrine()->getManager(); + /** + * Show a calendar item + * @Route("/{_locale}/calendar/{id}/show", name="chill_calendar_calendar_show") + */ + public function showAction(Request $request, $id): Response + { + $em = $this->getDoctrine()->getManager(); - // [$person, $accompanyingPeriod] = $this->getEntity($request); + [$user, $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); + // $deleteForm = $this->createDeleteForm($id, $accompanyingPeriod); - // $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod); + if ($view === null) { + throw $this->createNotFoundException('Template not found'); + } - // // TODO - // /* - // $event = new PrivacyEvent($person, array( - // 'element_class' => Activity::class, - // 'element_id' => $entity->getId(), - // 'action' => 'show' - // )); - // $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); - // */ + return $this->render($view, array( + //'person' => $person, + 'accompanyingCourse' => $accompanyingPeriod, + 'entity' => $entity, + //'delete_form' => $deleteForm->createView(), + )); + } - // if ($view === null) { - // throw $this->createNotFoundException('Template not found'); - // } - // 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(); + /** + * Edit a calendar item + * @Route("/{_locale}/calendar/{id}/edit", name="chill_calendar_calendar_edit") + */ + 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); + $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); + if ($view === null) { + throw $this->createNotFoundException('Template not found'); + } - // /* - // * TODO - // $event = new PrivacyEvent($person, array( - // 'element_class' => Calendar::class, - // 'element_id' => $entity->getId(), - // 'action' => 'edit' - // )); - // $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); - // */ + $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); - // if ($view === null) { - // throw $this->createNotFoundException('Template not found'); - // } + return $this->render($view, array( + 'entity' => $entity, + 'edit_form' => $form->createView(), + 'delete_form' => $deleteForm->createView(), + 'accompanyingCourse' => $accompanyingPeriod, + 'activity_json' => $activity_array + )); + } - // $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); + /** + * Delete a calendar item + * @Route("/{_locale}/calendar/{id}/delete", name="chill_calendar_calendar_delete") + */ + public function deleteAction(Request $request, $id) + { + $em = $this->getDoctrine()->getManager(); - // return $this->render($view, array( - // 'entity' => $entity, - // 'edit_form' => $form->createView(), - // 'delete_form' => $deleteForm->createView(), - // 'person' => $person, - // 'accompanyingCourse' => $accompanyingPeriod, - // 'activity_json' => $activity_array - // )); - // } + [$person, $accompanyingPeriod] = $this->getEntity($request); - // /** - // * Deletes a Calendar entity. - // * - // */ - // public function deleteAction(Request $request, $id) - // { - // $em = $this->getDoctrine()->getManager(); + if ($accompanyingPeriod instanceof AccompanyingPeriod) { + $view = 'ChillCalendarBundle:Calendar:confirm_deleteAccompanyingCourse.html.twig'; + } elseif ($person instanceof Person) { + $view = 'ChillCalendarBundle:Calendar:confirm_deletePerson.html.twig'; + } - // [$person, $accompanyingPeriod] = $this->getEntity($request); + /* @var $activity Calendar */ + $activity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); - // if ($accompanyingPeriod instanceof AccompanyingPeriod) { - // $view = 'ChillCalendarBundle:Calendar:confirm_deleteAccompanyingCourse.html.twig'; - // } elseif ($person instanceof Person) { - // $view = 'ChillCalendarBundle:Calendar:confirm_deletePerson.html.twig'; - // } + if (!$activity) { + throw $this->createNotFoundException('Unable to find Calendar entity.'); + } - // /* @var $activity Calendar */ - // $activity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); + // TODO + // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity); - // if (!$activity) { - // throw $this->createNotFoundException('Unable to find Calendar entity.'); - // } + $form = $this->createDeleteForm($id, $person, $accompanyingPeriod); - // // TODO - // // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity); + if ($request->getMethod() === Request::METHOD_DELETE) { + $form->handleRequest($request); - // $form = $this->createDeleteForm($id, $person, $accompanyingPeriod); + if ($form->isValid()) { - // if ($request->getMethod() === Request::METHOD_DELETE) { - // $form->handleRequest($request); + $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() + )); - // if ($form->isValid()) { + $em->remove($activity); + $em->flush(); - // $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->addFlash('success', $this->get('translator') + ->trans("The activity has been successfully removed.")); - // $em->remove($activity); - // $em->flush(); + $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + return $this->redirectToRoute('chill_activity_activity_list', $params); + } + } - // $this->addFlash('success', $this->get('translator') - // ->trans("The activity has been successfully removed.")); + if ($view === null) { + throw $this->createNotFoundException('Template not found'); + } - // $params = $this->buildParamsToUrl($person, $accompanyingPeriod); - // return $this->redirectToRoute('chill_activity_activity_list', $params); - // } - // } + return $this->render($view, array( + 'activity' => $activity, + 'delete_form' => $form->createView(), + 'person' => $person, + 'accompanyingCourse' => $accompanyingPeriod, + )); + } - // if ($view === null) { - // throw $this->createNotFoundException('Template not found'); - // } + /** + * 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->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; - - // 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 { diff --git a/src/Bundle/ChillCalendarBundle/Entity/Calendar.php b/src/Bundle/ChillCalendarBundle/Entity/Calendar.php index 6d898133e..508279664 100644 --- a/src/Bundle/ChillCalendarBundle/Entity/Calendar.php +++ b/src/Bundle/ChillCalendarBundle/Entity/Calendar.php @@ -373,4 +373,32 @@ class Calendar return $this; } + + public function getPersonsAssociated(): array + { + if (null !== $this->accompanyingPeriod) { + $personsAssociated = []; + foreach ($this->accompanyingPeriod->getParticipations() as $participation) { + if ($this->persons->contains($participation->getPerson())) { + $personsAssociated[] = $participation->getPerson(); + } + } + return $personsAssociated; + } + return []; + } + + public function getPersonsNotAssociated(): array + { + if (null !== $this->accompanyingPeriod) { + $personsNotAssociated = []; + foreach ($this->persons as $person) { + if (!in_array($person, $this->getPersonsAssociated())) { + $personsNotAssociated[] = $person; + } + } + return $personsNotAssociated; + } + return []; + } } diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig index 84b3cc37e..58f20230e 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig @@ -36,10 +36,6 @@ .. location -{%- if form.status is defined -%} - {{ form_row(form.status) }} -{% endif %} - {%- if form.cancelReason is defined -%} {{ form_row(form.cancelReason) }} {% endif %} diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/show.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/show.html.twig new file mode 100644 index 000000000..95af5c686 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/show.html.twig @@ -0,0 +1,75 @@ +

{{ "Calendar"|trans }}

+ +
+ +
+ + +

{{ 'Calendar data'|trans }}

+ +
{{ 'start date'|trans }}
+
{{ entity.startDate|format_date('long') }}
+ +
{{ 'end date'|trans }}
+
{{ entity.endDate|format_date('long') }}
+ +
{{ 'cancel reason'|trans }}
+
+ {% if entity.cancelReason is not null %} + {{ entity.cancelReason }} + {% else %} + {{ 'Unknown'|trans }} + {% endif %} +
+ +
{{ 'status'|trans }}
+
{{ entity.status }}
+ + {% if not entity.comment.isEmpty %} +
{{ 'calendar comment'|trans }}
+
{{ entity.comment|chill_entity_render_box }}
+ {% endif %} + +
{{ 'sendSMS'|trans }}
+
+ {% if entity.sendSMS is not null %} + {% if entity.sendSMS %}Oui{% else %}Non{% endif %} + {% else %} + {{ 'Unknown'|trans }} + {% endif %} +
+ + + + +{% set accompanying_course_id = null %} +{% if accompanyingCourse %} + {% set accompanying_course_id = accompanyingCourse.id %} +{% endif %} + + diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/showAccompanyingCourse.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/showAccompanyingCourse.html.twig new file mode 100644 index 000000000..587d764b8 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/showAccompanyingCourse.html.twig @@ -0,0 +1,15 @@ +{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %} + +{% set activeRouteKey = 'chill_calendar_calendar_list' %} + +{% block title 'Calendar'|trans %} + +{% block content -%} +
+
+
+ {% include 'ChillCalendarBundle:Calendar:show.html.twig' with {'context': 'accompanyingCourse'} %} +
+
+
+{% endblock content %}