From 4cf6721e351f5f95ea14fd3aaf05c151247db605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 3 Apr 2023 19:54:10 +0200 Subject: [PATCH] Feature: [calendar] convert calendar to activity in the context of a person --- .../Controller/CalendarController.php | 22 ++++++---- .../Resources/views/Calendar/_list.html.twig | 43 ++++++++++++++++++- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 550c6e984..5f1b70aa0 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -526,14 +526,20 @@ class CalendarController extends AbstractController 'comment' => $calendar->getComment()->getComment(), ]; - return $this->redirectToRoute( - 'chill_activity_activity_new', - [ - 'accompanying_period_id' => $calendar->getAccompanyingPeriod()->getId(), - 'activityData' => $activityData, - 'returnPath' => $request->query->get('returnPath', null), - ] - ); + $routeParams = [ + 'activityData' => $activityData, + 'returnPath' => $request->query->get('returnPath', null), + ]; + + if ($calendar->getContext() === 'accompanying_period'){ + $routeParams['accompanying_period_id'] = $calendar->getAccompanyingPeriod()->getId(); + } elseif ($calendar->getContext() === 'person') { + $routeParams['person_id'] = $calendar->getPerson()->getId(); + } else { + throw new RuntimeException('context not found for this calendar'); + } + + return $this->redirectToRoute('chill_activity_activity_new', $routeParams); } private function buildListFilterOrder(): FilterOrderHelper diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig index d6110917a..c09be27b7 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig @@ -103,6 +103,42 @@ {% endif %} + {% if calendar.activity is not null %} +
+
+
+
+

{{ 'Activity'|trans }}

+
+

+ + + {{ calendar.activity.type.name | localize_translatable_string }} + + {% if calendar.activity.emergency %} + {{ 'Emergency'|trans|upper }} + {% endif %} + +

+ +
    +
  • + {{ 'Created by'|trans }} {{ calendar.activity.createdBy|chill_entity_render_string }}, {{ 'on'|trans }} {{ calendar.activity.createdAt|format_datetime('short', 'short') }} +
  • + {% if is_granted('CHILL_ACTIVITY_SEE', calendar.activity) %} +
  • + +
  • + {% endif %} +
+ +
+
+
+
+
+ {% endif %} +
@@ -147,7 +183,12 @@ {% endif %} {% endif %} - {% if accompanyingCourse is defined and is_granted('CHILL_ACTIVITY_CREATE', accompanyingCourse) and calendar.activity is null %} + {% if calendar.activity is null and ( + (calendar.context == 'accompanying_period' and is_granted('CHILL_ACTIVITY_CREATE', calendar.accompanyingPeriod)) + or + (calendar.context == 'person' and is_granted('CHILL_ACTIVITY_CREATE', calendar.person)) + ) + %}