This commit is contained in:
Mathieu Jaumotte 2022-10-18 14:37:33 +02:00
parent 8928664f87
commit 9eb451e359
15 changed files with 79 additions and 76 deletions

View File

@ -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,
]);
}

View File

@ -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,
]);
}

View File

@ -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);
}
}

View File

@ -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'
);
}
}

View File

@ -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)

View File

@ -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.

View File

@ -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.

View File

@ -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()
);
}

View File

@ -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'])
);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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));
}
}