From 3a3baa79c8155c5e9c33a869794fe187ebc9e201 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 1 Oct 2021 20:48:45 +0200 Subject: [PATCH] resume: list associated persons sorted by household. add method in entity --- .../AccompanyingCourseController.php | 1 + .../Entity/AccompanyingPeriod.php | 38 +++++++++++++++++++ .../Resources/public/chill/chillperson.scss | 21 ++++++++++ .../views/AccompanyingCourse/index.html.twig | 28 +++++++++----- 4 files changed, 79 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php index 1bf40d146..5c11f4802 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php @@ -118,6 +118,7 @@ class AccompanyingCourseController extends Controller return $this->render('@ChillPerson/AccompanyingCourse/index.html.twig', [ 'accompanyingCourse' => $accompanyingCourse, 'withoutHousehold' => $withoutHousehold, + 'participationsByHousehold' => $accompanyingCourse->actualParticipationsByHousehold(), 'works' => $works, 'activities' => $activities ]); diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 14fb26f1a..8a834736b 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -513,6 +513,44 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface ); } + /** + * Return an array with open participations sorted by household + * [ + * [ + * "household" => Household x, + * "members" => [ + * Participation y , Participation z, ... + * ] + * ], + * ] + * + */ + public function actualParticipationsByHousehold(): array + { + $participations = $this->getOPenParticipations()->toArray(); + + $households = []; + foreach ($participations as $p) { + $households[] = $p->getPerson()->getCurrentHousehold(); + } + $households = array_unique($households, SORT_REGULAR); + + $array = []; + foreach ($households as $household) { + $members = []; + foreach ($participations as $p) { + if ($household === $p->getPerson()->getCurrentHousehold()) { + $members[] = array_shift($participations); + } else { + $participations[] = array_shift($participations); + } + } + $array[] = [ 'household' => $household, 'members' => $members ]; + } + + return $array; + } + /** * Return true if the accompanying period contains a person. * diff --git a/src/Bundle/ChillPersonBundle/Resources/public/chill/chillperson.scss b/src/Bundle/ChillPersonBundle/Resources/public/chill/chillperson.scss index 071d0f9a5..64ea09cdc 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/chill/chillperson.scss +++ b/src/Bundle/ChillPersonBundle/Resources/public/chill/chillperson.scss @@ -247,3 +247,24 @@ span.fa-holder { font-family: "Open Sans Extrabold"; } } + +div.accompanyingcourse-resume { + div.associated-persons { + span.household { + border-radius: 8px; + border: 1px solid $white; + &:hover { + border: 1px solid $chill-beige; + } + i { + color: $chill-beige; + } + padding: 0.5em; + margin-right: 2px; + span.badge-person, span.badge-thirdparty { + margin-bottom: 1em; + } + &.no-household {} + } + } +} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index fa30389fc..a879e1ccb 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -23,17 +23,27 @@ {% block content %}
-
- {% for p in accompanyingCourse.participations %} +
+ {% for h in participationsByHousehold %} + {% set householdClass = (h.household is not null) ? 'household-' ~ h.household.id : 'no-household' %} + + {% if h.household is not null %} + + {% endif %} + {% for p in h.members %} - {# include vue_onthefly component #} - {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with { - targetEntity: { name: 'person', id: p.person.id }, - action: 'show', - displayBadge: true, - buttonText: p.person|chill_entity_render_string - } %} + {# include vue_onthefly component #} + {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with { + targetEntity: { name: 'person', id: p.person.id }, + action: 'show', + displayBadge: true, + buttonText: p.person|chill_entity_render_string + } %} + {% endfor %} + {% endfor %}