diff --git a/app/api/module/Api/src/Domain/QueryHandler/Irfo/IrfoGvPermitTypeList.php b/app/api/module/Api/src/Domain/QueryHandler/Irfo/IrfoGvPermitTypeList.php index 3db0088a5b..4edcf114fa 100644 --- a/app/api/module/Api/src/Domain/QueryHandler/Irfo/IrfoGvPermitTypeList.php +++ b/app/api/module/Api/src/Domain/QueryHandler/Irfo/IrfoGvPermitTypeList.php @@ -19,11 +19,11 @@ public function handleQuery(QueryInterface $query) { $repo = $this->getRepo(); + $records = $repo->fetchActiveRecords(); + return [ - 'result' => $this->resultList( - $repo->fetchList($query, Query::HYDRATE_OBJECT) - ), - 'count' => $repo->fetchCount($query), + 'result' => $this->resultList($records), + 'count' => count($records), ]; } } diff --git a/app/api/module/Api/src/Domain/Repository/IrfoGvPermitType.php b/app/api/module/Api/src/Domain/Repository/IrfoGvPermitType.php index 2661bf3bbc..49b5939078 100644 --- a/app/api/module/Api/src/Domain/Repository/IrfoGvPermitType.php +++ b/app/api/module/Api/src/Domain/Repository/IrfoGvPermitType.php @@ -31,4 +31,19 @@ protected function applyListFilters(QueryBuilder $qb, QueryInterface $query) { $qb->orderBy($this->alias . '.description', 'ASC'); } + + public function fetchActiveRecords() + { + $doctrineQb = $this->createQueryBuilder(); + + $doctrineQb->where($doctrineQb->expr()->orX( + $doctrineQb->expr()->isNull($this->alias . '.displayUntil'), + $doctrineQb->expr()->gte($this->alias . '.displayUntil', ':today') + )) + ->setParameter('today', new \DateTime(), \Doctrine\DBAL\Types\Types::DATETIME_MUTABLE); + + $doctrineQb->orderBy($this->alias . '.description', 'ASC'); + + return $doctrineQb->getQuery()->getResult(); + } } diff --git a/app/api/module/Api/src/Entity/Irfo/AbstractIrfoGvPermitType.php b/app/api/module/Api/src/Entity/Irfo/AbstractIrfoGvPermitType.php old mode 100644 new mode 100755 index af57f5a5af..e8f5d76c43 --- a/app/api/module/Api/src/Entity/Irfo/AbstractIrfoGvPermitType.php +++ b/app/api/module/Api/src/Entity/Irfo/AbstractIrfoGvPermitType.php @@ -56,6 +56,15 @@ abstract class AbstractIrfoGvPermitType implements BundleSerializableInterface, */ protected $description; + /** + * Display until + * + * @var \DateTime + * + * @ORM\Column(type="date", name="display_until", nullable=true) + */ + protected $displayUntil; + /** * Identifier - Id * @@ -156,6 +165,37 @@ public function getDescription() return $this->description; } + /** + * Set the display until + * + * @param \DateTime $displayUntil new value being set + * + * @return IrfoGvPermitType + */ + public function setDisplayUntil($displayUntil) + { + $this->displayUntil = $displayUntil; + + return $this; + } + + /** + * Get the display until date + * + * @param bool $asDateTime If true will always return a \DateTime (or null) never a string datetime + * + * @return \DateTime|string + + */ + public function getDisplayUntil($asDateTime = false) + { + if ($asDateTime === true) { + return $this->asDateTime($this->displayUntil); + } + + return $this->displayUntil; + } + /** * Set the id * diff --git a/app/api/test/module/Api/src/Domain/QueryHandler/Irfo/IrfoGvPermitTypeListTest.php b/app/api/test/module/Api/src/Domain/QueryHandler/Irfo/IrfoGvPermitTypeListTest.php index 7c153ffdb3..9df00279c7 100644 --- a/app/api/test/module/Api/src/Domain/QueryHandler/Irfo/IrfoGvPermitTypeListTest.php +++ b/app/api/test/module/Api/src/Domain/QueryHandler/Irfo/IrfoGvPermitTypeListTest.php @@ -35,17 +35,16 @@ public function testHandleQuery() ->getMock(); $this->repoMap['IrfoGvPermitType'] - ->shouldReceive('fetchList') - ->with($query, \Doctrine\ORM\Query::HYDRATE_OBJECT) + ->shouldReceive('fetchActiveRecords') ->andReturn([$entity]) // ->shouldReceive('fetchCount') ->with($query) - ->andReturn(2); + ->andReturn(1); $actual = $this->sut->handleQuery($query); - static::assertEquals(2, $actual['count']); + static::assertEquals(1, $actual['count']); static::assertEquals(['SERIALIZED'], $actual['result']); } } diff --git a/app/api/test/module/Api/src/Domain/Repository/IrfoGvPermitTypeTest.php b/app/api/test/module/Api/src/Domain/Repository/IrfoGvPermitTypeTest.php index 02910b44cf..0e09870419 100644 --- a/app/api/test/module/Api/src/Domain/Repository/IrfoGvPermitTypeTest.php +++ b/app/api/test/module/Api/src/Domain/Repository/IrfoGvPermitTypeTest.php @@ -33,4 +33,24 @@ public function testApplyListFilters() $this->sut->applyListFilters($mockQb, $mockQ); } + + public function testFetchActiveRecords() + { + $qb = $this->createMockQb('QRYSTART'); + + $this->mockCreateQueryBuilder($qb); + + $qb->shouldReceive('getQuery') + ->once() + ->andReturn(m::mock(\Doctrine\ORM\AbstractQuery::class)->shouldReceive('getResult') + ->once() + ->andReturn(['Mocked Result']) + ->getMock()); + + $this->assertEquals(['Mocked Result'], $this->sut->fetchActiveRecords('ORG1')); + + $actualQuery = $this->query; + $expectedPattern = '/QRYSTART AND \(m\.displayUntil IS NULL OR m\.displayUntil >= \[\[.*\]\]\) ORDER BY m\.description ASC/'; + $this->assertMatchesRegularExpression($expectedPattern, $actualQuery); + } }