From 0d5d4b3f0582a69d09dd966731e8c1430a1cc9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 1 Oct 2021 09:50:13 +0200 Subject: [PATCH] add accompanying period where the person is requestor + badge in results --- .../Entity/AccompanyingPeriod.php | 2 +- .../AccompanyingPeriodParticipation.php | 39 ++++---- .../ChillPersonBundle/Entity/Person.php | 94 ++++++++++++++++++- .../views/Person/list_with_period.html.twig | 40 ++++---- .../translations/messages+intl-icu.fr.yaml | 7 ++ .../translations/messages.fr.yml | 1 - 6 files changed, 145 insertions(+), 38 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 14fb26f1a..c71136d88 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -213,7 +213,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface private $scopes; /** - * @ORM\ManyToOne(targetEntity=Person::class) + * @ORM\ManyToOne(targetEntity=Person::class, inversedBy="accompanyingPeriodRequested") * @ORM\JoinColumn(nullable=true) */ private $requestorPerson; diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php index 70c5a0505..c873e527a 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php @@ -47,86 +47,91 @@ class AccompanyingPeriodParticipation * @Groups({"read"}) */ private $id; - + /** * @ORM\ManyToOne(targetEntity=Person::class, inversedBy="accompanyingPeriodParticipations") * @ORM\JoinColumn(name="person_id", referencedColumnName="id", nullable=false) * @Groups({"read"}) */ private $person; - + /** * @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class, inversedBy="participations", cascade={"persist"}) * @ORM\JoinColumn(name="accompanyingperiod_id", referencedColumnName="id", nullable=false) */ private $accompanyingPeriod; - + /** * @ORM\Column(type="date", nullable=false) * @Groups({"read"}) */ private $startDate; - + /** * @ORM\Column(type="date", nullable=true) * @Groups({"read"}) */ private $endDate = null; - + public function __construct(AccompanyingPeriod $accompanyingPeriod, Person $person) { $this->startDate = new \DateTimeImmutable('now'); $this->accompanyingPeriod = $accompanyingPeriod; $this->person = $person; } - + public function getId(): ?int { return $this->id; } - + public function getPerson(): ?Person { return $this->person; } - + public function setPerson(?Person $person): self { $this->person = $person; - + return $this; } - + public function getAccompanyingPeriod(): ?AccompanyingPeriod { return $this->accompanyingPeriod; } - + public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self { $this->accompanyingPeriod = $accompanyingPeriod; - + return $this; } - + public function getStartDate(): ?\DateTimeInterface { return $this->startDate; } - + /* * public function setStartDate(\DateTimeInterface $startDate): self { $this->startDate = $startDate; return $this; } */ - + public function getEndDate(): ?\DateTimeInterface { return $this->endDate; } - + public function setEndDate(?\DateTimeInterface $endDate): self { $this->endDate = $endDate; - + return $this; } + + public function isOpen(): bool + { + return $this->endDate === null; + } } diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 69429219f..9aaad8c04 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -28,9 +28,9 @@ use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Country; use Chill\MainBundle\Entity\User; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\MaritalStatus; -use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\MainBundle\Entity\HasCenterInterface; use Chill\MainBundle\Entity\Address; @@ -329,6 +329,15 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ private $accompanyingPeriodParticipations; + /** + * The accompanying period requested by the Person + * + * @ORM\OneToMany(targetEntity=AccompanyingPeriod::class, + * mappedBy="requestorPerson") + * @var Collection|AccompanyingPeriod[] + */ + private Collection $accompanyingPeriodRequested; + /** * A remark over the person * @var string @@ -478,6 +487,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI $this->genderComment = new CommentEmbeddable(); $this->maritalStatusComment = new CommentEmbeddable(); $this->periodLocatedOn = new ArrayCollection(); + $this->accompanyingPeriodRequested = new ArrayCollection(); } /** @@ -605,6 +615,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * Get AccompanyingPeriodParticipations Collection + * + * @return AccompanyingPeriodParticipation[]|Collection */ public function getAccompanyingPeriodParticipations(): Collection { @@ -614,6 +626,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * Return a collection of participation, where the participation * is still opened, not a draft, and the period is still opened + * + * @return AccompanyingPeriodParticipation[]|Collection */ public function getOpenedParticipations(): Collection { @@ -1650,6 +1664,84 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this; } + /** + * @return AccompanyingPeriod[]|Collection + */ + public function getAccompanyingPeriodRequested(): Collection + { + return $this->accompanyingPeriodRequested; + } + + /** + * Return a list of all accompanying period where the person is involved: + * + * * as requestor; + * * as participant, only for opened participation; + * + * @param bool $asParticipantOpen add participation which are still opened + * @param bool $asRequestor add accompanying period where the person is requestor + * @return AccompanyingPeriod[]|Collection + */ + public function getAccompanyingPeriodInvolved( + bool $asParticipantOpen = true, + bool $asRequestor = true + ): Collection + { + $result = new ArrayCollection(); + + if ($asParticipantOpen) { + foreach ($this->getOpenedParticipations() + ->map(fn (AccompanyingPeriodParticipation $app) => + $app->getAccompanyingPeriod()) + as $period + ) { + if (!$result->contains($period)) { + $result->add($period); + } + } + } + + if ($asRequestor) { + foreach ($this->accompanyingPeriodRequested as $period) { + if (!$result->contains($period)) { + $result->add($period); + } + } + } + + return $result; + } + + /** + * Handy method to get the AccompanyingPeriodParticipation + * matching a given AccompanyingPeriod. + * + * Used in template, to find the participation when iterating on a list + * of period. + * + * @param \Chill\PersonBundle\Entity\AccompanyingPeriod $period + * @return AccompanyingPeriodParticipation + */ + public function findParticipationForPeriod(AccompanyingPeriod $period): ?AccompanyingPeriodParticipation + { + $closeCandidates = []; + + foreach ($this->getAccompanyingPeriodParticipations() as $participation) { + if ($participation->getAccompanyingPeriod() === $period) { + if ($participation->isOpen()) { + return $participation; + } + $closeCandidates[] = $participation; + } + } + + if (0 < count($closeCandidates)) { + return $closeCandidates[0]; + } + + return null; + } + public function getCreatedBy(): ?User { return $this->createdBy; diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig index f586d7ac0..2fd1de9c1 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig @@ -59,47 +59,51 @@ 'customButtons': { 'after': _self.button_person(person) } }) }} - {#- 'apps' is for AccompanyingPeriodParticipationS #} - {%- set apps = [] %} - {%- for app in person.openedParticipations %} - {%- if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', app.accompanyingPeriod) %} - {%- set apps = apps|merge([app]) %} + {#- 'acps' is for AcCompanyingPeriodS #} + {%- set acps = [] %} + {%- for acp in person.accompanyingPeriodInvolved %} + {%- if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', acp) %} + {%- set acps = acps|merge([acp]) %} {%- endif %} {%- endfor %} - {% if apps|length > 0 %} + {# add as requestor #} + + {% if acps|length > 0 %}
- {% for app in apps %} + {% for acp in acps %} + {% set app = person.findParticipationForPeriod(acp) %}
- {{ 'Since %date%'|trans({'%date%': app.startDate|format_date('medium') }) }} + {% if acp.requestorPerson == person %} + + {{ 'Requestor'|trans({'gender': person.gender}) }} + + {% endif %} + {% if app != null %} + {{ 'Since %date%'|trans({'%date%': app.startDate|format_date('medium') }) }} + {% endif %}
- {% if app.accompanyingPeriod.user is not null %} + {% if acp.user is not null %}
ref: - {{ app.accompanyingPeriod.user|chill_entity_render_box }} + {{ acp.user|chill_entity_render_box }}
{% endif %}
- {% for issue in app.accompanyingPeriod.socialIssues %} + {% for issue in acp.socialIssues %} {{ issue|chill_entity_render_box }} {% endfor %} - {# ^^ display all socialIssues, or slice vv - |slice(0,2) - {% if app.accompanyingPeriod.socialIssues|length > 2 %} - {{ 'and %number% other'|transchoice(app.accompanyingPeriod.socialIssues|length-2) }} - {% endif %} - #}
  • - diff --git a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml index cea908ccf..32ce0ff45 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml +++ b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml @@ -5,6 +5,13 @@ Born the date: >- other {Né·e le {birthdate}} } +Requestor: >- + {gender, select, + man {Demandeur} + woman {Demandeuse} + other {Demandeur·euse} + } + household: Household: Ménage Household number: Ménage {household_num} diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 8b6b6db58..2e0f518be 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -189,7 +189,6 @@ Create an accompanying course: Créer un parcours This accompanying course is still a draft: Ce parcours est à l'état brouillon Associated peoples: Usagers concernés Resources: Interlocuteurs privilégiés -Requestor: Demandeur Any requestor to this accompanying course: Aucun demandeur pour ce parcours Social actions: Actions d'accompagnement Social issues: Problématiques sociales