From 18694a34cf5400086b14144e589b54831439c9ca Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 3 Mar 2022 16:24:37 +0100 Subject: [PATCH 01/25] logic added to only keep youngest descendant. works for issue, seems not to for action --- .../ChillActivityBundle/Entity/Activity.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index 0a344236c..f80d4ab86 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -229,7 +229,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialAction(SocialAction $socialAction): self { - if (!$this->socialActions->contains($socialAction)) { + $descendants = $socialAction->getDescendants(); + $inCollection = false; + + if(null != $descendants) { + foreach ($descendants as $d) { + $inCollection = $this->socialActions->contains($d); + } + } else { + $inCollection = $this->socialActions->contains($socialAction); + } + + if(!$inCollection) { $this->socialActions[] = $socialAction; } @@ -238,7 +249,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialIssue(SocialIssue $socialIssue): self { - if (!$this->socialIssues->contains($socialIssue)) { + $descendants = $socialIssue->getDescendants(); + $inCollection = false; + + if(null != $descendants) { + foreach ($descendants as $d) { + $inCollection = $this->socialIssues->contains($d); + } + } else { + $inCollection = $this->socialIssues->contains($socialIssue); + } + + if(!$inCollection) { $this->socialIssues[] = $socialIssue; } From 214ef09fe72e6971de5609b94bd60cb389581f38 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 3 Mar 2022 16:29:35 +0100 Subject: [PATCH 02/25] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a38f2ea47..efd8189bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ and this project adheres to * [confidential] Fix position of toggle button so it does not cover text nor fall outside of box (no issue) * [parcours] Fix edit of both thirdparty and contact name (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/474) * [template] do not list inactive templates (for doc generator) - +* [action] Only youngest descendant is kept for social issues and actions (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/471) ## Test releases ### test release 2022-02-21 From 7c043e9d85257c0e8104f8a026fee30b43a5735a Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 4 Mar 2022 12:06:53 +0100 Subject: [PATCH 03/25] fix logic in activity entity --- .../ChillActivityBundle/Entity/Activity.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index f80d4ab86..034e6073c 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -230,18 +230,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialAction(SocialAction $socialAction): self { $descendants = $socialAction->getDescendants(); - $inCollection = false; - if(null != $descendants) { + if(count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialActions->contains($d); + if ($inCollection) { + return $this; + } } } else { - $inCollection = $this->socialActions->contains($socialAction); - } - - if(!$inCollection) { - $this->socialActions[] = $socialAction; + if (!$this->socialActions->contains($socialAction)) { + $this->socialActions[] = $socialAction; + }; } return $this; @@ -250,18 +250,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialIssue(SocialIssue $socialIssue): self { $descendants = $socialIssue->getDescendants(); - $inCollection = false; - if(null != $descendants) { + if(count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialIssues->contains($d); + if ($inCollection) { + return $this; + } } } else { - $inCollection = $this->socialIssues->contains($socialIssue); - } - - if(!$inCollection) { - $this->socialIssues[] = $socialIssue; + if (!$this->socialIssues->contains($socialIssue)) { + $this->socialIssues[] = $socialIssue; + }; } return $this; From 0333e79b0ae1d3636720f595691b994b31c101a2 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 4 Mar 2022 12:07:29 +0100 Subject: [PATCH 04/25] csfixes --- src/Bundle/ChillActivityBundle/Entity/Activity.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index 034e6073c..f183ced60 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -35,6 +35,7 @@ use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\SerializedName; +use function count; /** * Class Activity. @@ -231,9 +232,10 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac { $descendants = $socialAction->getDescendants(); - if(count($descendants) > 0) { + if (count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialActions->contains($d); + if ($inCollection) { return $this; } @@ -241,7 +243,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac } else { if (!$this->socialActions->contains($socialAction)) { $this->socialActions[] = $socialAction; - }; + } } return $this; @@ -251,9 +253,10 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac { $descendants = $socialIssue->getDescendants(); - if(count($descendants) > 0) { + if (count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialIssues->contains($d); + if ($inCollection) { return $this; } @@ -261,7 +264,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac } else { if (!$this->socialIssues->contains($socialIssue)) { $this->socialIssues[] = $socialIssue; - }; + } } return $this; From 474fffcbb5b4dd63a8866feb46c1532c7a51fe93 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 4 Mar 2022 12:08:00 +0100 Subject: [PATCH 05/25] changelog updated --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index efd8189bc..55cc51fde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ and this project adheres to * [confidential] Fix position of toggle button so it does not cover text nor fall outside of box (no issue) * [parcours] Fix edit of both thirdparty and contact name (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/474) * [template] do not list inactive templates (for doc generator) -* [action] Only youngest descendant is kept for social issues and actions (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/471) +* [activity] Only youngest descendant is kept for social issues and actions (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/471) ## Test releases ### test release 2022-02-21 From 4ef22748033610a69325c826c119c32675d6039b Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 3 Mar 2022 16:24:37 +0100 Subject: [PATCH 06/25] logic added to only keep youngest descendant. works for issue, seems not to for action --- .../ChillActivityBundle/Entity/Activity.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index 0a344236c..f80d4ab86 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -229,7 +229,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialAction(SocialAction $socialAction): self { - if (!$this->socialActions->contains($socialAction)) { + $descendants = $socialAction->getDescendants(); + $inCollection = false; + + if(null != $descendants) { + foreach ($descendants as $d) { + $inCollection = $this->socialActions->contains($d); + } + } else { + $inCollection = $this->socialActions->contains($socialAction); + } + + if(!$inCollection) { $this->socialActions[] = $socialAction; } @@ -238,7 +249,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialIssue(SocialIssue $socialIssue): self { - if (!$this->socialIssues->contains($socialIssue)) { + $descendants = $socialIssue->getDescendants(); + $inCollection = false; + + if(null != $descendants) { + foreach ($descendants as $d) { + $inCollection = $this->socialIssues->contains($d); + } + } else { + $inCollection = $this->socialIssues->contains($socialIssue); + } + + if(!$inCollection) { $this->socialIssues[] = $socialIssue; } From b6e530fec6cd84ac44edd1897a0d594ec1e2b44b Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 3 Mar 2022 16:29:35 +0100 Subject: [PATCH 07/25] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 380cc6afe..926363314 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ and this project adheres to * [template] do not list inactive templates (for doc generator) * [person] email added to twig personRenderbox (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/490) +* [action] Only youngest descendant is kept for social issues and actions (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/471) ## Test releases ### test release 2022-02-21 From 25fe105590299fc02e79618095b6fc65c9b27d54 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 4 Mar 2022 12:06:53 +0100 Subject: [PATCH 08/25] fix logic in activity entity --- .../ChillActivityBundle/Entity/Activity.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index f80d4ab86..034e6073c 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -230,18 +230,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialAction(SocialAction $socialAction): self { $descendants = $socialAction->getDescendants(); - $inCollection = false; - if(null != $descendants) { + if(count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialActions->contains($d); + if ($inCollection) { + return $this; + } } } else { - $inCollection = $this->socialActions->contains($socialAction); - } - - if(!$inCollection) { - $this->socialActions[] = $socialAction; + if (!$this->socialActions->contains($socialAction)) { + $this->socialActions[] = $socialAction; + }; } return $this; @@ -250,18 +250,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialIssue(SocialIssue $socialIssue): self { $descendants = $socialIssue->getDescendants(); - $inCollection = false; - if(null != $descendants) { + if(count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialIssues->contains($d); + if ($inCollection) { + return $this; + } } } else { - $inCollection = $this->socialIssues->contains($socialIssue); - } - - if(!$inCollection) { - $this->socialIssues[] = $socialIssue; + if (!$this->socialIssues->contains($socialIssue)) { + $this->socialIssues[] = $socialIssue; + }; } return $this; From 1c21b8070365ca9cb3163104b12bf12c3089a82c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 4 Mar 2022 12:07:29 +0100 Subject: [PATCH 09/25] csfixes --- src/Bundle/ChillActivityBundle/Entity/Activity.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index 034e6073c..f183ced60 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -35,6 +35,7 @@ use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\SerializedName; +use function count; /** * Class Activity. @@ -231,9 +232,10 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac { $descendants = $socialAction->getDescendants(); - if(count($descendants) > 0) { + if (count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialActions->contains($d); + if ($inCollection) { return $this; } @@ -241,7 +243,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac } else { if (!$this->socialActions->contains($socialAction)) { $this->socialActions[] = $socialAction; - }; + } } return $this; @@ -251,9 +253,10 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac { $descendants = $socialIssue->getDescendants(); - if(count($descendants) > 0) { + if (count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialIssues->contains($d); + if ($inCollection) { return $this; } @@ -261,7 +264,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac } else { if (!$this->socialIssues->contains($socialIssue)) { $this->socialIssues[] = $socialIssue; - }; + } } return $this; From 2012df512cba695ade191a6df4643e3266d8fb83 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 4 Mar 2022 17:27:26 +0100 Subject: [PATCH 10/25] merge conflict fixed --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 926363314..caf897a68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,8 +29,7 @@ and this project adheres to * [parcours] Fix edit of both thirdparty and contact name (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/474) * [template] do not list inactive templates (for doc generator) * [person] email added to twig personRenderbox (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/490) - -* [action] Only youngest descendant is kept for social issues and actions (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/471) +* [activity] Only youngest descendant is kept for social issues and actions (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/471) ## Test releases ### test release 2022-02-21 From 16be28681ad0d7a017803b5668a23466e0c2f015 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 7 Mar 2022 14:53:54 +0100 Subject: [PATCH 11/25] Test added for activity-social action and social issue --- .../Tests/Entity/ActivityTest.php | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php diff --git a/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php b/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php new file mode 100644 index 000000000..c67c99894 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php @@ -0,0 +1,98 @@ +addChild($child); + $grandChild = new SocialAction(); + $child->addChild($grandChild); + + $activity = new Activity(); + + $activity->addSocialAction($parent); + + $this->assertCount(1, $activity->getSocialActions()); + $this->assertContains($parent, $activity->getSocialActions()); + + $activity->addSocialAction($grandChild); + + $this->assertCount(1, $activity->getSocialActions()); + $this->assertContains($grandChild, $activity->getSocialActions()); + $this->assertNotContains($parent, $activity->getSocialActions()); + + $activity->addSocialAction($child); + + $this->assertCount(1, $activity->getSocialActions()); + $this->assertContains($grandChild, $activity->getSocialActions()); + $this->assertNotContains($parent, $activity->getSocialActions()); + $this->assertNotContains($child, $activity->getSocialActions()); + + $activity->addSocialAction($another = new SocialAction()); + + $this->assertCount(2, $activity->getSocialActions()); + $this->assertContains($grandChild, $activity->getSocialActions()); + $this->assertContains($another, $activity->getSocialActions()); + $this->assertNotContains($parent, $activity->getSocialActions()); + $this->assertNotContains($child, $activity->getSocialActions()); + } + + public function testHierarchySocialIssues(): void + { + $parent = new SocialIssue(); + $child = new SocialIssue(); + + $parent->addChild($child); + $grandChild = new SocialIssue(); + $child->addChild($grandChild); + + $activity = new Activity(); + + $activity->addSocialIssue($parent); + + $this->assertCount(1, $activity->getSocialIssues()); + $this->assertContains($parent, $activity->getSocialIssues()); + + $activity->addSocialIssue($grandChild); + + $this->assertCount(1, $activity->getSocialIssues()); + $this->assertContains($grandChild, $activity->getSocialIssues()); + $this->assertNotContains($parent, $activity->getSocialIssues()); + + $activity->addSocialIssue($child); + + $this->assertCount(1, $activity->getSocialIssues()); + $this->assertContains($grandChild, $activity->getSocialIssues()); + $this->assertNotContains($parent, $activity->getSocialIssues()); + $this->assertNotContains($child, $activity->getSocialIssues()); + + $activity->addSocialIssue($another = new SocialIssue()); + + $this->assertCount(2, $activity->getSocialIssues()); + $this->assertContains($grandChild, $activity->getSocialIssues()); + $this->assertContains($another, $activity->getSocialIssues()); + $this->assertNotContains($parent, $activity->getSocialIssues()); + $this->assertNotContains($child, $activity->getSocialIssues()); + } + +} \ No newline at end of file From 9551e10d2b3d902410ac3369bebf4f630cfb5bf5 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 16 Mar 2022 11:55:19 +0100 Subject: [PATCH 12/25] improvement, but still not correct --- .../ChillActivityBundle/Entity/Activity.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index f183ced60..db16ac9f6 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -235,15 +235,13 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac if (count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialActions->contains($d); - if ($inCollection) { return $this; } } - } else { - if (!$this->socialActions->contains($socialAction)) { - $this->socialActions[] = $socialAction; - } + } + if (!$this->socialActions->contains($socialAction)) { + $this->socialActions[] = $socialAction; } return $this; @@ -256,15 +254,14 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac if (count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialIssues->contains($d); - if ($inCollection) { return $this; } } - } else { - if (!$this->socialIssues->contains($socialIssue)) { - $this->socialIssues[] = $socialIssue; - } + } + + if (!$this->socialIssues->contains($socialIssue)) { + $this->socialIssues[] = $socialIssue; } return $this; From 02571bf727135cbb305410a046bccee41694c8a3 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 22 Mar 2022 13:45:20 +0100 Subject: [PATCH 13/25] switch to using getDescendantsWithThis() --- src/Bundle/ChillActivityBundle/Entity/Activity.php | 13 +++++-------- .../Entity/SocialWork/SocialAction.php | 2 +- .../Entity/SocialWork/SocialIssue.php | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index db16ac9f6..ac67a73e4 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -230,7 +230,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialAction(SocialAction $socialAction): self { - $descendants = $socialAction->getDescendants(); + $descendants = $socialAction->getDescendantsWithThis(); if (count($descendants) > 0) { foreach ($descendants as $d) { @@ -240,16 +240,14 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac } } } - if (!$this->socialActions->contains($socialAction)) { - $this->socialActions[] = $socialAction; - } + $this->socialActions[] = $socialAction; return $this; } public function addSocialIssue(SocialIssue $socialIssue): self { - $descendants = $socialIssue->getDescendants(); + $descendants = $socialIssue->getDescendantsWithThis(); if (count($descendants) > 0) { foreach ($descendants as $d) { @@ -260,9 +258,8 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac } } - if (!$this->socialIssues->contains($socialIssue)) { - $this->socialIssues[] = $socialIssue; - } + $this->socialIssues[] = $socialIssue; + return $this; } diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index ec5e5a8e5..01f30f140 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -169,7 +169,7 @@ class SocialAction } /** - * @return Collection|self[] All the descendants with the current entity (this) + * @return Collection|self[] All the descendants including the current entity (this) */ public function getDescendantsWithThis(): Collection { diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php index c735c0132..fb277f56c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php @@ -202,7 +202,7 @@ class SocialIssue } /** - * @return Collection|self[] All the descendants with the current entity (this) + * @return Collection|self[] All the descendants including the current entity (this) */ public function getDescendantsWithThis(): Collection { From 988b67bd4b9122c85dc755ec4e36549cbcc43424 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 3 Mar 2022 16:24:37 +0100 Subject: [PATCH 14/25] logic added to only keep youngest descendant. works for issue, seems not to for action --- .../ChillActivityBundle/Entity/Activity.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index 0a344236c..f80d4ab86 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -229,7 +229,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialAction(SocialAction $socialAction): self { - if (!$this->socialActions->contains($socialAction)) { + $descendants = $socialAction->getDescendants(); + $inCollection = false; + + if(null != $descendants) { + foreach ($descendants as $d) { + $inCollection = $this->socialActions->contains($d); + } + } else { + $inCollection = $this->socialActions->contains($socialAction); + } + + if(!$inCollection) { $this->socialActions[] = $socialAction; } @@ -238,7 +249,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialIssue(SocialIssue $socialIssue): self { - if (!$this->socialIssues->contains($socialIssue)) { + $descendants = $socialIssue->getDescendants(); + $inCollection = false; + + if(null != $descendants) { + foreach ($descendants as $d) { + $inCollection = $this->socialIssues->contains($d); + } + } else { + $inCollection = $this->socialIssues->contains($socialIssue); + } + + if(!$inCollection) { $this->socialIssues[] = $socialIssue; } From 432b105be567a5b1669565d3e052227e01e852a1 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 3 Mar 2022 16:29:35 +0100 Subject: [PATCH 15/25] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c278ca93e..cf4991560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,9 @@ and this project adheres to * [notification] Display of social action within workflow notification set to display block (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/537) * [onthefly] trim trailing whitespace in email of person and thirdparty (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/542) +* [action] Only youngest descendant is kept for social issues and actions (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/471) +## Test releases + ### test release 2022-02-21 * [notifications] Word 'un' changed to number '1' for notifications in user menu (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/483) From f35479e4d210e9f1810cd084d8e4f8d6112a402f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 4 Mar 2022 12:06:53 +0100 Subject: [PATCH 16/25] fix logic in activity entity --- .../ChillActivityBundle/Entity/Activity.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index f80d4ab86..034e6073c 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -230,18 +230,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialAction(SocialAction $socialAction): self { $descendants = $socialAction->getDescendants(); - $inCollection = false; - if(null != $descendants) { + if(count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialActions->contains($d); + if ($inCollection) { + return $this; + } } } else { - $inCollection = $this->socialActions->contains($socialAction); - } - - if(!$inCollection) { - $this->socialActions[] = $socialAction; + if (!$this->socialActions->contains($socialAction)) { + $this->socialActions[] = $socialAction; + }; } return $this; @@ -250,18 +250,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialIssue(SocialIssue $socialIssue): self { $descendants = $socialIssue->getDescendants(); - $inCollection = false; - if(null != $descendants) { + if(count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialIssues->contains($d); + if ($inCollection) { + return $this; + } } } else { - $inCollection = $this->socialIssues->contains($socialIssue); - } - - if(!$inCollection) { - $this->socialIssues[] = $socialIssue; + if (!$this->socialIssues->contains($socialIssue)) { + $this->socialIssues[] = $socialIssue; + }; } return $this; From 7851d9956e9c3bf07a8dac7e5c5f96763c6f004c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 4 Mar 2022 12:07:29 +0100 Subject: [PATCH 17/25] csfixes --- src/Bundle/ChillActivityBundle/Entity/Activity.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index 034e6073c..f183ced60 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -35,6 +35,7 @@ use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\SerializedName; +use function count; /** * Class Activity. @@ -231,9 +232,10 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac { $descendants = $socialAction->getDescendants(); - if(count($descendants) > 0) { + if (count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialActions->contains($d); + if ($inCollection) { return $this; } @@ -241,7 +243,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac } else { if (!$this->socialActions->contains($socialAction)) { $this->socialActions[] = $socialAction; - }; + } } return $this; @@ -251,9 +253,10 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac { $descendants = $socialIssue->getDescendants(); - if(count($descendants) > 0) { + if (count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialIssues->contains($d); + if ($inCollection) { return $this; } @@ -261,7 +264,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac } else { if (!$this->socialIssues->contains($socialIssue)) { $this->socialIssues[] = $socialIssue; - }; + } } return $this; From d81a41bb1783d6b4c27de27b77df6c33511cc10b Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 7 Mar 2022 14:53:54 +0100 Subject: [PATCH 18/25] Test added for activity-social action and social issue --- .../Tests/Entity/ActivityTest.php | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php diff --git a/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php b/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php new file mode 100644 index 000000000..c67c99894 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php @@ -0,0 +1,98 @@ +addChild($child); + $grandChild = new SocialAction(); + $child->addChild($grandChild); + + $activity = new Activity(); + + $activity->addSocialAction($parent); + + $this->assertCount(1, $activity->getSocialActions()); + $this->assertContains($parent, $activity->getSocialActions()); + + $activity->addSocialAction($grandChild); + + $this->assertCount(1, $activity->getSocialActions()); + $this->assertContains($grandChild, $activity->getSocialActions()); + $this->assertNotContains($parent, $activity->getSocialActions()); + + $activity->addSocialAction($child); + + $this->assertCount(1, $activity->getSocialActions()); + $this->assertContains($grandChild, $activity->getSocialActions()); + $this->assertNotContains($parent, $activity->getSocialActions()); + $this->assertNotContains($child, $activity->getSocialActions()); + + $activity->addSocialAction($another = new SocialAction()); + + $this->assertCount(2, $activity->getSocialActions()); + $this->assertContains($grandChild, $activity->getSocialActions()); + $this->assertContains($another, $activity->getSocialActions()); + $this->assertNotContains($parent, $activity->getSocialActions()); + $this->assertNotContains($child, $activity->getSocialActions()); + } + + public function testHierarchySocialIssues(): void + { + $parent = new SocialIssue(); + $child = new SocialIssue(); + + $parent->addChild($child); + $grandChild = new SocialIssue(); + $child->addChild($grandChild); + + $activity = new Activity(); + + $activity->addSocialIssue($parent); + + $this->assertCount(1, $activity->getSocialIssues()); + $this->assertContains($parent, $activity->getSocialIssues()); + + $activity->addSocialIssue($grandChild); + + $this->assertCount(1, $activity->getSocialIssues()); + $this->assertContains($grandChild, $activity->getSocialIssues()); + $this->assertNotContains($parent, $activity->getSocialIssues()); + + $activity->addSocialIssue($child); + + $this->assertCount(1, $activity->getSocialIssues()); + $this->assertContains($grandChild, $activity->getSocialIssues()); + $this->assertNotContains($parent, $activity->getSocialIssues()); + $this->assertNotContains($child, $activity->getSocialIssues()); + + $activity->addSocialIssue($another = new SocialIssue()); + + $this->assertCount(2, $activity->getSocialIssues()); + $this->assertContains($grandChild, $activity->getSocialIssues()); + $this->assertContains($another, $activity->getSocialIssues()); + $this->assertNotContains($parent, $activity->getSocialIssues()); + $this->assertNotContains($child, $activity->getSocialIssues()); + } + +} \ No newline at end of file From ea21f2d9c4070fa98341a056700e6d9871c1acea Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 16 Mar 2022 11:55:19 +0100 Subject: [PATCH 19/25] improvement, but still not correct --- .../ChillActivityBundle/Entity/Activity.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index f183ced60..db16ac9f6 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -235,15 +235,13 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac if (count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialActions->contains($d); - if ($inCollection) { return $this; } } - } else { - if (!$this->socialActions->contains($socialAction)) { - $this->socialActions[] = $socialAction; - } + } + if (!$this->socialActions->contains($socialAction)) { + $this->socialActions[] = $socialAction; } return $this; @@ -256,15 +254,14 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac if (count($descendants) > 0) { foreach ($descendants as $d) { $inCollection = $this->socialIssues->contains($d); - if ($inCollection) { return $this; } } - } else { - if (!$this->socialIssues->contains($socialIssue)) { - $this->socialIssues[] = $socialIssue; - } + } + + if (!$this->socialIssues->contains($socialIssue)) { + $this->socialIssues[] = $socialIssue; } return $this; From f09870931c7f8b3e945f7e52f2007b0839a0f384 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 22 Mar 2022 13:45:20 +0100 Subject: [PATCH 20/25] switch to using getDescendantsWithThis() --- src/Bundle/ChillActivityBundle/Entity/Activity.php | 13 +++++-------- .../Entity/SocialWork/SocialAction.php | 2 +- .../Entity/SocialWork/SocialIssue.php | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index db16ac9f6..ac67a73e4 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -230,7 +230,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialAction(SocialAction $socialAction): self { - $descendants = $socialAction->getDescendants(); + $descendants = $socialAction->getDescendantsWithThis(); if (count($descendants) > 0) { foreach ($descendants as $d) { @@ -240,16 +240,14 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac } } } - if (!$this->socialActions->contains($socialAction)) { - $this->socialActions[] = $socialAction; - } + $this->socialActions[] = $socialAction; return $this; } public function addSocialIssue(SocialIssue $socialIssue): self { - $descendants = $socialIssue->getDescendants(); + $descendants = $socialIssue->getDescendantsWithThis(); if (count($descendants) > 0) { foreach ($descendants as $d) { @@ -260,9 +258,8 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac } } - if (!$this->socialIssues->contains($socialIssue)) { - $this->socialIssues[] = $socialIssue; - } + $this->socialIssues[] = $socialIssue; + return $this; } diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index ec5e5a8e5..01f30f140 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -169,7 +169,7 @@ class SocialAction } /** - * @return Collection|self[] All the descendants with the current entity (this) + * @return Collection|self[] All the descendants including the current entity (this) */ public function getDescendantsWithThis(): Collection { diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php index c735c0132..fb277f56c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php @@ -202,7 +202,7 @@ class SocialIssue } /** - * @return Collection|self[] All the descendants with the current entity (this) + * @return Collection|self[] All the descendants including the current entity (this) */ public function getDescendantsWithThis(): Collection { From a78c62789c88b43f982700d744a14cdf028673cd Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 8 Apr 2022 18:56:37 +0200 Subject: [PATCH 21/25] if parent in collection replace with child, problem, sibling isn't added --- src/Bundle/ChillActivityBundle/Entity/Activity.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index ac67a73e4..f157401a7 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -231,6 +231,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialAction(SocialAction $socialAction): self { $descendants = $socialAction->getDescendantsWithThis(); + $parent = $socialAction->getParent(); + + dump($this->socialActions); + dump($parent); + + $parentKey = array_search($parent, $this->socialActions->toArray()); + + if (null !== $parentKey) { + dump(true); + $this->socialActions[$parentKey] = $socialAction; + // return $this; + } if (count($descendants) > 0) { foreach ($descendants as $d) { From 5eea202586de5c49098949c7fd88e9939f22b9ae Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 8 Apr 2022 19:04:13 +0200 Subject: [PATCH 22/25] fix adding sibling action --- src/Bundle/ChillActivityBundle/Entity/Activity.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index f157401a7..016c4b6fa 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -237,8 +237,9 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac dump($parent); $parentKey = array_search($parent, $this->socialActions->toArray()); + dump($parentKey); - if (null !== $parentKey) { + if (false !== $parentKey) { dump(true); $this->socialActions[$parentKey] = $socialAction; // return $this; From 03b0a8766eefbae23144df14fbf58cb0abafe444 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 8 Apr 2022 19:12:11 +0200 Subject: [PATCH 23/25] remove dumps --- src/Bundle/ChillActivityBundle/Entity/Activity.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index 016c4b6fa..dba4f9c62 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -233,14 +233,9 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac $descendants = $socialAction->getDescendantsWithThis(); $parent = $socialAction->getParent(); - dump($this->socialActions); - dump($parent); - $parentKey = array_search($parent, $this->socialActions->toArray()); - dump($parentKey); if (false !== $parentKey) { - dump(true); $this->socialActions[$parentKey] = $socialAction; // return $this; } From b2fb86111d3ab26c452b4d8f1287ed27fc8f8dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 26 Apr 2022 21:12:31 +0200 Subject: [PATCH 24/25] fix social action consistency --- .../ChillActivityBundle/Entity/Activity.php | 54 ++++++++---------- .../Tests/Entity/ActivityTest.php | 15 ++++- .../Entity/SocialWork/SocialAction.php | 55 +++++++++++++++++++ 3 files changed, 93 insertions(+), 31 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index dba4f9c62..d77e0250b 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -230,45 +230,39 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac public function addSocialAction(SocialAction $socialAction): self { - $descendants = $socialAction->getDescendantsWithThis(); - $parent = $socialAction->getParent(); - - $parentKey = array_search($parent, $this->socialActions->toArray()); - - if (false !== $parentKey) { - $this->socialActions[$parentKey] = $socialAction; - // return $this; + if (!$this->socialActions->contains($socialAction)) { + $this->socialActions[] = $socialAction; + $this->ensureSocialActionConsistency(); } - if (count($descendants) > 0) { - foreach ($descendants as $d) { - $inCollection = $this->socialActions->contains($d); - if ($inCollection) { - return $this; - } - } - } - - $this->socialActions[] = $socialAction; return $this; } + private function ensureSocialActionConsistency(): void + { + $ancestors = SocialAction::findAncestorSocialActions($this->getSocialActions()); + + foreach ($ancestors as $ancestor) { + $this->removeSocialAction($ancestor); + } + } + + /** + * Add a social issue + * + * Note: the social issue consistency (the fact that only yougest social issues + * are kept) is processed by an entity listener: + * @see{\Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodSocialIssueConsistencyEntityListener} + * + * @param SocialIssue $socialIssue + * @return $this + */ public function addSocialIssue(SocialIssue $socialIssue): self { - $descendants = $socialIssue->getDescendantsWithThis(); - - if (count($descendants) > 0) { - foreach ($descendants as $d) { - $inCollection = $this->socialIssues->contains($d); - if ($inCollection) { - return $this; - } - } + if (!$this->socialIssues->contains($socialIssue)) { + $this->socialIssues[] = $socialIssue; } - $this->socialIssues[] = $socialIssue; - - return $this; } diff --git a/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php b/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php index c67c99894..a14ac4a24 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php @@ -12,12 +12,17 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Tests\Entity; use Chill\ActivityBundle\Entity\Activity; +use Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodSocialIssueConsistencyEntityListener; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; +use Doctrine\ORM\Event\LifecycleEventArgs; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; final class ActivityTest extends TestCase { + use ProphecyTrait; public function testHierarchySocialActions(): void { @@ -59,6 +64,9 @@ final class ActivityTest extends TestCase public function testHierarchySocialIssues(): void { + $listener = new AccompanyingPeriodSocialIssueConsistencyEntityListener(); + $event = $this->prophesize(LifecycleEventArgs::class)->reveal(); + $parent = new SocialIssue(); $child = new SocialIssue(); @@ -67,19 +75,23 @@ final class ActivityTest extends TestCase $child->addChild($grandChild); $activity = new Activity(); + $activity->setAccompanyingPeriod(new AccompanyingPeriod()); $activity->addSocialIssue($parent); + $listener->preUpdate($activity, $event); $this->assertCount(1, $activity->getSocialIssues()); $this->assertContains($parent, $activity->getSocialIssues()); $activity->addSocialIssue($grandChild); + $listener->preUpdate($activity, $event); $this->assertCount(1, $activity->getSocialIssues()); $this->assertContains($grandChild, $activity->getSocialIssues()); $this->assertNotContains($parent, $activity->getSocialIssues()); $activity->addSocialIssue($child); + $listener->preUpdate($activity, $event); $this->assertCount(1, $activity->getSocialIssues()); $this->assertContains($grandChild, $activity->getSocialIssues()); @@ -87,6 +99,7 @@ final class ActivityTest extends TestCase $this->assertNotContains($child, $activity->getSocialIssues()); $activity->addSocialIssue($another = new SocialIssue()); + $listener->preUpdate($activity, $event); $this->assertCount(2, $activity->getSocialIssues()); $this->assertContains($grandChild, $activity->getSocialIssues()); @@ -95,4 +108,4 @@ final class ActivityTest extends TestCase $this->assertNotContains($child, $activity->getSocialIssues()); } -} \ No newline at end of file +} diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index 01f30f140..198950494 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -307,4 +307,59 @@ class SocialAction return $this; } + + /** + * Recursive method which return true if the current $action + * is a descendant of the $action given in parameter. + */ + public function isDescendantOf(SocialAction $action): bool + { + if (!$this->hasParent()) { + return false; + } + + if ($this->getParent() === $action) { + return true; + } + + return $this->getParent()->isDescendantOf($action); + } + + /** + * In a SocialIssues's collection, find the elements which are an ancestor of + * other elements. + * + * The difference of the given list (thus, the elements which are **not** kept + * in the returned collection) are the most-grand-child elements of the list. + * + * Removing those elements of the Collection (which is not done by this method) + * will ensure that only the most descendent elements are present in the collection, + * (any ancestor of another element are present). + * + * @param Collection|SocialAction[] $socialActions + * + * @return Collection|SocialAction[] a list with the elements of the given list which are parent of other elements in the given list + */ + public static function findAncestorSocialActions(Collection $socialActions): Collection + { + $ancestors = new ArrayCollection(); + + foreach ($socialActions as $candidateChild) { + if ($ancestors->contains($candidateChild)) { + continue; + } + + foreach ($socialActions as $candidateParent) { + if ($ancestors->contains($candidateParent)) { + continue; + } + + if ($candidateChild->isDescendantOf($candidateParent)) { + $ancestors->add($candidateParent); + } + } + } + + return $ancestors; + } } From c2061110ddef45e43f6fd78f2634d4ecd8c22787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 26 Apr 2022 21:16:55 +0200 Subject: [PATCH 25/25] fix cs --- .../ChillActivityBundle/Entity/Activity.php | 23 ++-- .../Tests/Entity/ActivityTest.php | 5 +- .../Entity/SocialWork/SocialAction.php | 110 +++++++++--------- 3 files changed, 70 insertions(+), 68 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index d77e0250b..eabaa44d1 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -35,7 +35,6 @@ use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\SerializedName; -use function count; /** * Class Activity. @@ -238,23 +237,14 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac return $this; } - private function ensureSocialActionConsistency(): void - { - $ancestors = SocialAction::findAncestorSocialActions($this->getSocialActions()); - - foreach ($ancestors as $ancestor) { - $this->removeSocialAction($ancestor); - } - } - /** - * Add a social issue + * Add a social issue. * * Note: the social issue consistency (the fact that only yougest social issues * are kept) is processed by an entity listener: + * * @see{\Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodSocialIssueConsistencyEntityListener} * - * @param SocialIssue $socialIssue * @return $this */ public function addSocialIssue(SocialIssue $socialIssue): self @@ -652,4 +642,13 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac return $this; } + + private function ensureSocialActionConsistency(): void + { + $ancestors = SocialAction::findAncestorSocialActions($this->getSocialActions()); + + foreach ($ancestors as $ancestor) { + $this->removeSocialAction($ancestor); + } + } } diff --git a/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php b/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php index a14ac4a24..7a68a36fc 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php @@ -20,6 +20,10 @@ use Doctrine\ORM\Event\LifecycleEventArgs; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; +/** + * @internal + * @coversNothing + */ final class ActivityTest extends TestCase { use ProphecyTrait; @@ -107,5 +111,4 @@ final class ActivityTest extends TestCase $this->assertNotContains($parent, $activity->getSocialIssues()); $this->assertNotContains($child, $activity->getSocialIssues()); } - } diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index 198950494..904950489 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -128,6 +128,44 @@ class SocialAction return $this; } + /** + * In a SocialIssues's collection, find the elements which are an ancestor of + * other elements. + * + * The difference of the given list (thus, the elements which are **not** kept + * in the returned collection) are the most-grand-child elements of the list. + * + * Removing those elements of the Collection (which is not done by this method) + * will ensure that only the most descendent elements are present in the collection, + * (any ancestor of another element are present). + * + * @param Collection|SocialAction[] $socialActions + * + * @return Collection|SocialAction[] a list with the elements of the given list which are parent of other elements in the given list + */ + public static function findAncestorSocialActions(Collection $socialActions): Collection + { + $ancestors = new ArrayCollection(); + + foreach ($socialActions as $candidateChild) { + if ($ancestors->contains($candidateChild)) { + continue; + } + + foreach ($socialActions as $candidateParent) { + if ($ancestors->contains($candidateParent)) { + continue; + } + + if ($candidateChild->isDescendantOf($candidateParent)) { + $ancestors->add($candidateParent); + } + } + } + + return $ancestors; + } + /** * @return Collection|self[] */ @@ -233,6 +271,23 @@ class SocialAction return $this->getParent() instanceof self; } + /** + * Recursive method which return true if the current $action + * is a descendant of the $action given in parameter. + */ + public function isDescendantOf(SocialAction $action): bool + { + if (!$this->hasParent()) { + return false; + } + + if ($this->getParent() === $action) { + return true; + } + + return $this->getParent()->isDescendantOf($action); + } + public function removeChild(self $child): self { if ($this->children->removeElement($child)) { @@ -307,59 +362,4 @@ class SocialAction return $this; } - - /** - * Recursive method which return true if the current $action - * is a descendant of the $action given in parameter. - */ - public function isDescendantOf(SocialAction $action): bool - { - if (!$this->hasParent()) { - return false; - } - - if ($this->getParent() === $action) { - return true; - } - - return $this->getParent()->isDescendantOf($action); - } - - /** - * In a SocialIssues's collection, find the elements which are an ancestor of - * other elements. - * - * The difference of the given list (thus, the elements which are **not** kept - * in the returned collection) are the most-grand-child elements of the list. - * - * Removing those elements of the Collection (which is not done by this method) - * will ensure that only the most descendent elements are present in the collection, - * (any ancestor of another element are present). - * - * @param Collection|SocialAction[] $socialActions - * - * @return Collection|SocialAction[] a list with the elements of the given list which are parent of other elements in the given list - */ - public static function findAncestorSocialActions(Collection $socialActions): Collection - { - $ancestors = new ArrayCollection(); - - foreach ($socialActions as $candidateChild) { - if ($ancestors->contains($candidateChild)) { - continue; - } - - foreach ($socialActions as $candidateParent) { - if ($ancestors->contains($candidateParent)) { - continue; - } - - if ($candidateChild->isDescendantOf($candidateParent)) { - $ancestors->add($candidateParent); - } - } - } - - return $ancestors; - } }