From 21ee41ff29e9334bbdb198f4b6037ed1b5a8b7a6 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Wed, 27 Sep 2023 10:21:49 +0200 Subject: [PATCH] add count method on repository query add addForcedFilterHandler method --- src/core/Repository/RepositoryQuery.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/core/Repository/RepositoryQuery.php b/src/core/Repository/RepositoryQuery.php index 7d41fdc..7cc23e0 100644 --- a/src/core/Repository/RepositoryQuery.php +++ b/src/core/Repository/RepositoryQuery.php @@ -98,6 +98,15 @@ abstract class RepositoryQuery return $this; } + protected function addForcedFilterHandler(string $name): self + { + if (in_array($name, $this->forcedFilterHandlers)) { + $this->forcedFilterHandlers[] = $name; + } + + return $this; + } + protected function populateDqlId(&$data) { if (is_string($data)) { @@ -122,4 +131,15 @@ abstract class RepositoryQuery protected function filterHandler(string $name, $value) { } + + public function count() + { + return $this + ->select(sprintf('COUNT(%s.id) as total', $this->id)) + ->query + ->getQuery() + ->setMaxResults(1) + ->getOneOrNullResult()['total'] + ; + } }