mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-23 21:27:44 +03:00
Added tags param to paginable repository adapter
This commit is contained in:
parent
4580d11d32
commit
8b9caf02d2
4 changed files with 34 additions and 14 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 = []);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue