From 1959d4d8df3ce9883f54f51ccd4751984232bae3 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Sat, 1 Oct 2022 23:25:33 +0200 Subject: [PATCH] added filter for globalActivities in project collection (#3565) --- src/API/ProjectController.php | 5 +++++ src/Repository/ProjectRepository.php | 5 +++++ src/Repository/Query/ProjectQuery.php | 15 +++++++++++++++ tests/Repository/Query/ProjectQueryTest.php | 7 +++++++ 4 files changed, 32 insertions(+) diff --git a/src/API/ProjectController.php b/src/API/ProjectController.php index 610e0f5e..f9c577a3 100644 --- a/src/API/ProjectController.php +++ b/src/API/ProjectController.php @@ -96,6 +96,7 @@ class ProjectController extends BaseApiController * @Rest\QueryParam(name="start", requirements=@Constraints\DateTime(format="Y-m-d\TH:i:s"), strict=true, nullable=true, description="Only projects that started before this date will be included. Allowed format: HTML5 (default: now, if end is also empty)") * @Rest\QueryParam(name="end", requirements=@Constraints\DateTime(format="Y-m-d\TH:i:s"), strict=true, nullable=true, description="Only projects that ended after this date will be included. Allowed format: HTML5 (default: now, if start is also empty)") * @Rest\QueryParam(name="ignoreDates", requirements="1", strict=true, nullable=true, description="If set, start and end are completely ignored. Allowed values: 1 (default: off)") + * @Rest\QueryParam(name="globalActivities", requirements="0|1", strict=true, nullable=true, description="If given, filters projects by their 'global activity' support. Allowed values: 1 (supports global activities) and 0 (without global activities) (default: all)") * @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order. Allowed values: ASC, DESC (default: ASC)") * @Rest\QueryParam(name="orderBy", requirements="id|name|customer", strict=true, nullable=true, description="The field by which results will be ordered. Allowed values: id, name, customer (default: name)") * @Rest\QueryParam(name="term", description="Free search term") @@ -134,6 +135,10 @@ class ProjectController extends BaseApiController $query->setVisibility($visible); } + if (null !== ($globalActivities = $paramFetcher->get('globalActivities'))) { + $query->setGlobalActivities((bool) $globalActivities); + } + $ignoreDates = false; if (null !== $paramFetcher->get('ignoreDates')) { $ignoreDates = \intval($paramFetcher->get('ignoreDates')) === 1; diff --git a/src/Repository/ProjectRepository.php b/src/Repository/ProjectRepository.php index 580b85c2..5556e7b4 100644 --- a/src/Repository/ProjectRepository.php +++ b/src/Repository/ProjectRepository.php @@ -367,6 +367,11 @@ class ProjectRepository extends EntityRepository ->setParameter('customer', $query->getCustomers()); } + if ($query->getGlobalActivities() !== null) { + $qb->andWhere($qb->expr()->eq('p.globalActivities', ':globalActivities')) + ->setParameter('globalActivities', $query->getGlobalActivities(), Types::BOOLEAN); + } + // this is far from being perfect, possible enhancements: // there could also be a range selection to be able to select all projects that were active between from and to // begin = null and end = null diff --git a/src/Repository/Query/ProjectQuery.php b/src/Repository/Query/ProjectQuery.php index 2b44668f..08783423 100644 --- a/src/Repository/Query/ProjectQuery.php +++ b/src/Repository/Query/ProjectQuery.php @@ -34,6 +34,10 @@ class ProjectQuery extends BaseQuery implements VisibilityInterface * @var \DateTime|null */ private $projectEnd; + /** + * @var null|bool + */ + private $globalActivities = null; public function __construct() { @@ -43,6 +47,7 @@ class ProjectQuery extends BaseQuery implements VisibilityInterface 'projectStart' => null, 'projectEnd' => null, 'visibility' => VisibilityInterface::SHOW_VISIBLE, + 'globalActivities' => null, ]); } @@ -126,4 +131,14 @@ class ProjectQuery extends BaseQuery implements VisibilityInterface return $this; } + + public function getGlobalActivities(): ?bool + { + return $this->globalActivities; + } + + public function setGlobalActivities(?bool $globalActivities): void + { + $this->globalActivities = $globalActivities; + } } diff --git a/tests/Repository/Query/ProjectQueryTest.php b/tests/Repository/Query/ProjectQueryTest.php index 19c0e544..e156abde 100644 --- a/tests/Repository/Query/ProjectQueryTest.php +++ b/tests/Repository/Query/ProjectQueryTest.php @@ -31,6 +31,7 @@ class ProjectQueryTest extends BaseQueryTest self::assertNull($sut->getProjectStart()); self::assertNull($sut->getProjectEnd()); + self::assertNull($sut->getGlobalActivities()); } public function testSetter() @@ -44,5 +45,11 @@ class ProjectQueryTest extends BaseQueryTest $end = new \DateTime('-1 day'); $sut->setProjectEnd($end); self::assertSame($end, $sut->getProjectEnd()); + + $sut->setGlobalActivities(false); + self::assertFalse($sut->getGlobalActivities()); + + $sut->setGlobalActivities(true); + self::assertTrue($sut->getGlobalActivities()); } }