diff --git a/module/Common/src/Paginator/Adapter/PaginableRepositoryAdapter.php b/module/Common/src/Paginator/Adapter/PaginableRepositoryAdapter.php index 017f5e89..995c7263 100644 --- a/module/Common/src/Paginator/Adapter/PaginableRepositoryAdapter.php +++ b/module/Common/src/Paginator/Adapter/PaginableRepositoryAdapter.php @@ -20,12 +20,21 @@ class PaginableRepositoryAdapter implements AdapterInterface * @var null|array|string */ private $orderBy; + /** + * @var array + */ + private $tags; - public function __construct(PaginableRepositoryInterface $paginableRepository, $searchQuery = null, $orderBy = null) - { + public function __construct( + PaginableRepositoryInterface $paginableRepository, + $searchTerm = null, + array $tags = [], + $orderBy = null + ) { $this->paginableRepository = $paginableRepository; - $this->searchTerm = trim(strip_tags($searchQuery)); + $this->searchTerm = trim(strip_tags($searchTerm)); $this->orderBy = $orderBy; + $this->tags = $tags; } /** @@ -37,7 +46,13 @@ class PaginableRepositoryAdapter implements AdapterInterface */ public function getItems($offset, $itemCountPerPage) { - return $this->paginableRepository->findList($itemCountPerPage, $offset, $this->searchTerm, $this->orderBy); + return $this->paginableRepository->findList( + $itemCountPerPage, + $offset, + $this->searchTerm, + $this->tags, + $this->orderBy + ); } /** @@ -51,6 +66,6 @@ class PaginableRepositoryAdapter implements AdapterInterface */ public function count() { - return $this->paginableRepository->countList($this->searchTerm); + return $this->paginableRepository->countList($this->searchTerm, $this->tags); } } diff --git a/module/Common/src/Repository/PaginableRepositoryInterface.php b/module/Common/src/Repository/PaginableRepositoryInterface.php index b9a75aea..7481d186 100644 --- a/module/Common/src/Repository/PaginableRepositoryInterface.php +++ b/module/Common/src/Repository/PaginableRepositoryInterface.php @@ -9,16 +9,18 @@ interface PaginableRepositoryInterface * @param int|null $limit * @param int|null $offset * @param string|null $searchTerm + * @param array $tags * @param string|array|null $orderBy * @return array */ - public function findList($limit = null, $offset = null, $searchTerm = null, $orderBy = null); + public function findList($limit = null, $offset = null, $searchTerm = null, array $tags = [], $orderBy = null); /** * Counts the number of elements in a list using provided filtering data * * @param null $searchTerm + * @param array $tags * @return int */ - public function countList($searchTerm = null); + public function countList($searchTerm = null, array $tags = []); } diff --git a/module/Common/test/Paginator/PaginableRepositoryAdapterTest.php b/module/Common/test/Paginator/PaginableRepositoryAdapterTest.php index 1135682f..196cf0c9 100644 --- a/module/Common/test/Paginator/PaginableRepositoryAdapterTest.php +++ b/module/Common/test/Paginator/PaginableRepositoryAdapterTest.php @@ -20,7 +20,7 @@ class PaginableRepositoryAdapterTest extends TestCase public function setUp() { $this->repo = $this->prophesize(PaginableRepositoryInterface::class); - $this->adapter = new PaginableRepositoryAdapter($this->repo->reveal(), 'search', 'order'); + $this->adapter = new PaginableRepositoryAdapter($this->repo->reveal(), 'search', ['foo', 'bar'], 'order'); } /** @@ -28,7 +28,7 @@ class PaginableRepositoryAdapterTest extends TestCase */ public function getItemsFallbacksToFindList() { - $this->repo->findList(10, 5, 'search', 'order')->shouldBeCalledTimes(1); + $this->repo->findList(10, 5, 'search', ['foo', 'bar'], 'order')->shouldBeCalledTimes(1); $this->adapter->getItems(5, 10); } @@ -37,7 +37,7 @@ class PaginableRepositoryAdapterTest extends TestCase */ public function countFallbacksToCountList() { - $this->repo->countList('search')->shouldBeCalledTimes(1); + $this->repo->countList('search', ['foo', 'bar'])->shouldBeCalledTimes(1); $this->adapter->count(); } } diff --git a/module/Core/src/Repository/ShortUrlRepository.php b/module/Core/src/Repository/ShortUrlRepository.php index 9becb216..78962ccd 100644 --- a/module/Core/src/Repository/ShortUrlRepository.php +++ b/module/Core/src/Repository/ShortUrlRepository.php @@ -11,10 +11,11 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI * @param int|null $limit * @param int|null $offset * @param string|null $searchTerm + * @param array $tags * @param string|array|null $orderBy - * @return ShortUrl[] + * @return \Shlinkio\Shlink\Core\Entity\ShortUrl[] */ - public function findList($limit = null, $offset = null, $searchTerm = null, $orderBy = null) + public function findList($limit = null, $offset = null, $searchTerm = null, array $tags = [], $orderBy = null) { $qb = $this->createListQueryBuilder($searchTerm); $qb->select('s'); @@ -43,9 +44,10 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI * Counts the number of elements in a list using provided filtering data * * @param null|string $searchTerm + * @param array $tags * @return int */ - public function countList($searchTerm = null) + public function countList($searchTerm = null, array $tags = []) { $qb = $this->createListQueryBuilder($searchTerm); $qb->select('COUNT(s)'); @@ -55,9 +57,10 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI /** * @param null|string $searchTerm + * @param array $tags * @return QueryBuilder */ - protected function createListQueryBuilder($searchTerm = null) + protected function createListQueryBuilder($searchTerm = null, array $tags = []) { $qb = $this->getEntityManager()->createQueryBuilder(); $qb->from(ShortUrl::class, 's');