diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php index ebdc0a3c8..312d601ad 100644 --- a/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php @@ -31,7 +31,8 @@ class ActivityRepository extends ServiceEntityRepository } /** - * @deprecated use @link{ActivityACLAwareRepositoryInterface::findByAccompanyingPeriod} + * @deprecated use @see{ActivityACLAwareRepositoryInterface::findByAccompanyingPeriod} + * * @return Activity[] */ public function findByAccompanyingPeriod(AccompanyingPeriod $period, array $scopes, ?bool $allowNullScope = false, ?int $limit = 100, ?int $offset = 0, array $orderBy = ['date' => 'desc']): array diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php index b8a9141e4..80b106b4e 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php @@ -122,7 +122,7 @@ class SocialIssue } /** - * get all the ancestors of the social issue + * get all the ancestors of the social issue. * * @param bool $includeThis if the array in the result must include the present SocialIssue */ @@ -135,6 +135,7 @@ class SocialIssue } $current = $this; + while ($current->hasParent()) { $ancestors[] = $current = $current->getParent(); } diff --git a/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php b/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php index 491a2fffb..a3b49b596 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php @@ -39,6 +39,22 @@ final class SocialIssueTest extends TestCase $this->assertContains($grandChild, $ancestors); } + public function testGetAncestors() + { + $parent = new SocialIssue(); + $child = (new SocialIssue())->setParent($parent); + $grandChild = (new SocialIssue())->setParent($child); + $grandGrandChild = (new SocialIssue())->setParent($grandChild); + $unrelated = new SocialIssue(); + + $this->assertContains($parent, $grandGrandChild->getAncestors(true)); + $this->assertContains($child, $grandGrandChild->getAncestors(true)); + $this->assertContains($grandChild, $grandGrandChild->getAncestors(true)); + $this->assertContains($grandGrandChild, $grandGrandChild->getAncestors(true)); + $this->assertNotContains($grandGrandChild, $grandGrandChild->getAncestors(false)); + $this->assertCount(0, $unrelated->getAncestors(false)); + } + public function testIsDescendantOf() { $parent = new SocialIssue(); @@ -61,20 +77,4 @@ final class SocialIssueTest extends TestCase $this->assertFalse($child->isDescendantOf($grandChild)); } - - public function testGetAncestors() - { - $parent = new SocialIssue(); - $child = (new SocialIssue())->setParent($parent); - $grandChild = (new SocialIssue())->setParent($child); - $grandGrandChild = (new SocialIssue())->setParent($grandChild); - $unrelated = new SocialIssue(); - - $this->assertContains($parent, $grandGrandChild->getAncestors(true)); - $this->assertContains($child, $grandGrandChild->getAncestors(true)); - $this->assertContains($grandChild, $grandGrandChild->getAncestors(true)); - $this->assertContains($grandGrandChild, $grandGrandChild->getAncestors(true)); - $this->assertNotContains($grandGrandChild, $grandGrandChild->getAncestors(false)); - $this->assertCount(0, $unrelated->getAncestors(false)); - } } diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidityValidator.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidityValidator.php index d3df79c38..3ce3fdff1 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidityValidator.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidityValidator.php @@ -11,7 +11,6 @@ declare(strict_types=1); namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod; -use Chill\ActivityBundle\Repository\ActivityACLAwareRepository; use Chill\ActivityBundle\Repository\ActivityRepository; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; @@ -57,21 +56,26 @@ class AccompanyingPeriodValidityValidator extends ConstraintValidator } $socialIssuesByKey = []; + foreach ($socialIssues as $si) { $socialIssuesByKey[$si->getId()] = $si; } $periodIssuesWithAncestors = []; + foreach ($period->getSocialIssues() as $si) { /** @var SocialIssue $si */ - $periodIssuesWithAncestors = array_merge($periodIssuesWithAncestors, \array_map( - function (SocialIssue $si) { return $si->getId(); }, - $si->getAncestors(true)) + $periodIssuesWithAncestors = array_merge( + $periodIssuesWithAncestors, + array_map( + static function (SocialIssue $si) { return $si->getId(); }, + $si->getAncestors(true) + ) ); } foreach ($socialIssuesByKey as $key => $si) { - if (!in_array($key, $periodIssuesWithAncestors)) { + if (!in_array($key, $periodIssuesWithAncestors, true)) { $this->context ->buildViolation( $constraint->messageSocialIssueCannotBeDeleted