diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php index a7d6e5e3a..b897cde8c 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php @@ -43,7 +43,8 @@ class BySocialActionFilter implements FilterInterface $clause = $qb->expr()->in('actsocialaction.id', ':socialactions'); $qb->andWhere($clause) - ->setParameter('socialactions', + ->setParameter( + 'socialactions', SocialAction::getDescendantsWithThisForActions($data['accepted_socialactions']) ); } @@ -56,7 +57,7 @@ class BySocialActionFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { $builder->add('accepted_socialactions', PickSocialActionType::class, [ - 'multiple' => true + 'multiple' => true, ]); } diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php index 94189169d..f827c8c56 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php @@ -43,7 +43,8 @@ class BySocialIssueFilter implements FilterInterface $clause = $qb->expr()->in('actsocialissue.id', ':socialissues'); $qb->andWhere($clause) - ->setParameter('socialissues', + ->setParameter( + 'socialissues', SocialIssue::getDescendantsWithThisForIssues($data['accepted_socialissues']) ); } @@ -56,7 +57,7 @@ class BySocialIssueFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { $builder->add('accepted_socialissues', PickSocialIssueType::class, [ - 'multiple' => true + 'multiple' => true, ]); } diff --git a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php index 657ba8942..bf6a5d172 100644 --- a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php +++ b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php @@ -17,10 +17,8 @@ use Symfony\Component\Form\FormBuilderInterface; class UserCurrentLocationType extends AbstractType { - public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('currentLocation', PickUserLocationType::class); } } - diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php index ffb7e4380..af0e3843a 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php @@ -111,6 +111,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase * Compare aliases array before and after that aggregator alter query. * * @dataProvider dataProviderAliasDidNotDisappears + * * @return void */ public function testAliasDidNotDisappears(QueryBuilder $qb, array $data) @@ -290,5 +291,4 @@ abstract class AbstractAggregatorTest extends KernelTestCase 'test that the title is not empty' ); } - } diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php index 5632ee022..e1c8665ec 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php @@ -103,6 +103,7 @@ abstract class AbstractFilterTest extends KernelTestCase * Compare aliases array before and after that filter alter query. * * @dataProvider dataProviderAliasDidNotDisappears + * * @return void */ public function testAliasDidNotDisappears(QueryBuilder $qb, array $data) diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index 08fc4bf9e..29e8a413d 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -230,7 +230,6 @@ class SocialAction /** * @param Collection|SocialAction[] $socialActions - * @return Collection */ public static function getDescendantsWithThisForActions($socialActions): Collection { @@ -291,16 +290,16 @@ class SocialAction return $this->title; } - public function hasParent(): bool - { - return $this->getParent() instanceof self; - } - public function hasChildren(): bool { return 0 < $this->getChildren()->count(); } + public function hasParent(): bool + { + return $this->getParent() instanceof self; + } + /** * Recursive method which return true if the current $action * is a descendant of the $action given in parameter. diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php index 8708e34f3..42c8442c1 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php @@ -73,7 +73,9 @@ class SocialIssue /** * @internal use @see{SocialIssue::setParent} instead + * * @param SocialIssue $child + * * @return $this */ public function addChild(self $child): self @@ -221,7 +223,6 @@ class SocialIssue /** * @param array|SocialIssue[] $socialIssues - * @return Collection */ public static function getDescendantsWithThisForIssues(array $socialIssues): Collection { @@ -283,16 +284,16 @@ class SocialIssue return $this->title; } - public function hasParent(): bool - { - return null !== $this->parent; - } - public function hasChildren(): bool { return 0 < $this->getChildren()->count(); } + public function hasParent(): bool + { + return null !== $this->parent; + } + /** * Recursive method which return true if the current $issue is a descendant * of the $issue given in parameter. diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php index a1834aa0e..e3bf77af2 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php @@ -23,10 +23,10 @@ use function in_array; class SocialActionFilter implements FilterInterface { - private TranslatableStringHelper $translatableStringHelper; - private SocialActionRender $actionRender; + private TranslatableStringHelper $translatableStringHelper; + public function __construct( TranslatableStringHelper $translatableStringHelper, SocialActionRender $actionRender @@ -53,7 +53,8 @@ class SocialActionFilter implements FilterInterface $clause = $qb->expr()->in('acpwsocialaction.id', ':socialactions'); $qb->andWhere($clause) - ->setParameter('socialactions', + ->setParameter( + 'socialactions', SocialAction::getDescendantsWithThisForActions($data['accepted_socialactions'])->toArray() ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialIssueFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialIssueFilter.php index 08ab7fca2..083c15f91 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialIssueFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialIssueFilter.php @@ -57,7 +57,8 @@ class SocialIssueFilter implements FilterInterface $clause = $qb->expr()->in('acpsocialissue.id', ':socialissues'); $qb->andWhere($clause) - ->setParameter('socialissues', + ->setParameter( + 'socialissues', SocialIssue::getDescendantsWithThisForIssues($data['accepted_socialissues']) ); } diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php index 86e8e41a8..370704aed 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\SocialAction; +use DateTime; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; @@ -44,6 +45,14 @@ final class SocialActionRepository implements ObjectRepository return $this->repository->findAll(); } + /** + * @return array|SocialAction[] + */ + public function findAllActive(): array + { + return $this->buildQueryWithDesactivatedDateCriteria()->getQuery()->getResult(); + } + /** * @param mixed|null $limit * @param mixed|null $offset @@ -68,22 +77,14 @@ final class SocialActionRepository implements ObjectRepository return SocialAction::class; } - /** - * @return array|SocialAction[] - */ - public function findAllActive(): array - { - return $this->buildQueryWithDesactivatedDateCriteria()->getQuery()->getResult(); - } - private function buildQueryWithDesactivatedDateCriteria(): QueryBuilder { $qb = $this->repository->createQueryBuilder('sa'); - - $qb ->where('sa.desactivationDate is null') + + $qb->where('sa.desactivationDate is null') ->orWhere('sa.desactivationDate > :now') ->orderBy('sa.ordering', 'ASC') - ->setParameter('now', new \DateTime('now')); + ->setParameter('now', new DateTime('now')); return $qb; } diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php index 21831b432..8dd8f6a62 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; +use DateTime; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; @@ -39,6 +40,14 @@ final class SocialIssueRepository implements ObjectRepository return $this->repository->findAll(); } + /** + * @return array|SocialIssue[] + */ + public function findAllActive(): array + { + return $this->buildQueryWithDesactivatedDateCriteria()->getQuery()->getResult(); + } + /** * @param mixed|null $limit * @param mixed|null $offset @@ -63,22 +72,14 @@ final class SocialIssueRepository implements ObjectRepository return SocialIssue::class; } - /** - * @return array|SocialIssue[] - */ - public function findAllActive(): array - { - return $this->buildQueryWithDesactivatedDateCriteria()->getQuery()->getResult(); - } - private function buildQueryWithDesactivatedDateCriteria(): QueryBuilder { $qb = $this->repository->createQueryBuilder('si'); - $qb ->where('si.desactivationDate is null') + $qb->where('si.desactivationDate is null') ->orWhere('si.desactivationDate > :now') ->orderBy('si.ordering', 'ASC') - ->setParameter('now', new \DateTime('now')); + ->setParameter('now', new DateTime('now')); return $qb; } diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php index 8f1bfaccb..bfe49c0a4 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php @@ -22,6 +22,8 @@ use function implode; class SocialActionRender implements ChillEntityRenderInterface { + public const AND_CHILDREN_MENTION = 'show_and_children_mention'; + public const DEFAULT_ARGS = [ self::SEPARATOR_KEY => ' > ', self::NO_BADGE => false, @@ -38,12 +40,10 @@ class SocialActionRender implements ChillEntityRenderInterface /** * Show a mention "and children" on each SocialAction, if the social action - * has at least one child + * has at least one child. */ public const SHOW_AND_CHILDREN = 'show_and_children'; - public const AND_CHILDREN_MENTION = 'show_and_children_mention'; - private EngineInterface $engine; private TranslatableStringHelper $translatableStringHelper; diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php index 20a9c9fd2..62d17f47e 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php @@ -21,6 +21,8 @@ use function implode; final class SocialIssueRender implements ChillEntityRenderInterface { + public const AND_CHILDREN_MENTION = 'show_and_children_mention'; + public const DEFAULT_ARGS = [ self::SEPARATOR_KEY => ' > ', self::SHOW_AND_CHILDREN => false, @@ -31,11 +33,9 @@ final class SocialIssueRender implements ChillEntityRenderInterface /** * Show a mention "and children" on each SocialIssue, if the social issue - * has at least one child + * has at least one child. */ - public const SHOW_AND_CHILDREN = 'show_and_children'; - - public const AND_CHILDREN_MENTION = 'show_and_children_mention'; + public const SHOW_AND_CHILDREN = 'show_and_children'; private EngineInterface $engine; diff --git a/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialActionTest.php b/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialActionTest.php index 804ea2b1b..2dcfa6b11 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialActionTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialActionTest.php @@ -12,7 +12,6 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Entity\SocialWork; use Chill\PersonBundle\Entity\SocialWork\SocialAction; -use Doctrine\Common\Collections\ArrayCollection; use PHPUnit\Framework\TestCase; /** @@ -49,5 +48,4 @@ final class SocialActionTest extends TestCase $this->assertNotContains($unrelatedA, $actual); $this->assertNotContains($unrelatedB, $actual); } - } diff --git a/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php b/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php index aee4bec07..b846ae5f4 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php @@ -55,29 +55,6 @@ final class SocialIssueTest extends TestCase $this->assertCount(0, $unrelated->getAncestors(false)); } - public function testIsDescendantOf() - { - $parent = new SocialIssue(); - $child = (new SocialIssue())->setParent($parent); - $grandChild = (new SocialIssue())->setParent($child); - $grandGrandChild = (new SocialIssue())->setParent($grandChild); - $unrelated = new SocialIssue(); - - $this->assertTrue($grandGrandChild->isDescendantOf($parent)); - $this->assertTrue($grandGrandChild->isDescendantOf($grandChild)); - $this->assertTrue($grandGrandChild->isDescendantOf($child)); - $this->assertFalse($grandGrandChild->isDescendantOf($unrelated)); - - $this->assertTrue($grandChild->isDescendantOf($parent)); - $this->assertTrue($grandChild->isDescendantOf($child)); - $this->assertFalse($grandChild->isDescendantOf($unrelated)); - $this->assertFalse($grandChild->isDescendantOf($grandChild)); - - $this->assertFalse($unrelated->isDescendantOf($parent)); - - $this->assertFalse($child->isDescendantOf($grandChild)); - } - public function testGetDescendantsWithThisForIssues() { $parentA = new SocialIssue(); @@ -106,4 +83,27 @@ final class SocialIssueTest extends TestCase $this->assertNotContains($unrelatedA, $actual); $this->assertNotContains($unrelatedB, $actual); } + + public function testIsDescendantOf() + { + $parent = new SocialIssue(); + $child = (new SocialIssue())->setParent($parent); + $grandChild = (new SocialIssue())->setParent($child); + $grandGrandChild = (new SocialIssue())->setParent($grandChild); + $unrelated = new SocialIssue(); + + $this->assertTrue($grandGrandChild->isDescendantOf($parent)); + $this->assertTrue($grandGrandChild->isDescendantOf($grandChild)); + $this->assertTrue($grandGrandChild->isDescendantOf($child)); + $this->assertFalse($grandGrandChild->isDescendantOf($unrelated)); + + $this->assertTrue($grandChild->isDescendantOf($parent)); + $this->assertTrue($grandChild->isDescendantOf($child)); + $this->assertFalse($grandChild->isDescendantOf($unrelated)); + $this->assertFalse($grandChild->isDescendantOf($grandChild)); + + $this->assertFalse($unrelated->isDescendantOf($parent)); + + $this->assertFalse($child->isDescendantOf($grandChild)); + } }