mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 15:13:59 -06:00
Created stuff to handle pagination on list results
This commit is contained in:
parent
67ef171262
commit
35f1a4b672
@ -18,6 +18,7 @@
|
||||
"zendframework/zend-expressive-twigrenderer": "^1.0",
|
||||
"zendframework/zend-stdlib": "^2.7",
|
||||
"zendframework/zend-servicemanager": "^3.0",
|
||||
"zendframework/zend-paginator": "^2.6",
|
||||
"doctrine/orm": "^2.5",
|
||||
"guzzlehttp/guzzle": "^6.2",
|
||||
"acelaya/zsm-annotated-services": "^0.2.0",
|
||||
|
14
src/Repository/PaginableRepository.php
Normal file
14
src/Repository/PaginableRepository.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace Acelaya\UrlShortener\Repository;
|
||||
|
||||
interface PaginableRepository
|
||||
{
|
||||
/**
|
||||
* @param int|null $limit
|
||||
* @param int|null $offset
|
||||
* @param string|null $searchTerm
|
||||
* @param string|array|null $orderBy
|
||||
* @return array
|
||||
*/
|
||||
public function findList($limit = null, $offset = null, $searchTerm = null, $orderBy = null);
|
||||
}
|
42
src/Repository/ShortUrlRepository.php
Normal file
42
src/Repository/ShortUrlRepository.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Acelaya\UrlShortener\Repository;
|
||||
|
||||
use Acelaya\UrlShortener\Entity\ShortUrl;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param int|null $limit
|
||||
* @param int|null $offset
|
||||
* @param string|null $searchTerm
|
||||
* @param string|array|null $orderBy
|
||||
* @return ShortUrl[]
|
||||
*/
|
||||
public function findList($limit = null, $offset = null, $searchTerm = null, $orderBy = null)
|
||||
{
|
||||
$qb = $this->createQueryBuilder('s');
|
||||
|
||||
if (isset($limit)) {
|
||||
$qb->setMaxResults($limit);
|
||||
}
|
||||
if (isset($offset)) {
|
||||
$qb->setFirstResult($offset);
|
||||
}
|
||||
if (isset($searchTerm)) {
|
||||
// TODO
|
||||
}
|
||||
if (isset($orderBy)) {
|
||||
if (is_string($orderBy)) {
|
||||
$qb->orderBy($orderBy);
|
||||
} elseif (is_array($orderBy)) {
|
||||
$key = key($orderBy);
|
||||
$qb->orderBy($key, $orderBy[$key]);
|
||||
}
|
||||
} else {
|
||||
$qb->orderBy('s.dateCreated');
|
||||
}
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
8
src/Repository/ShortUrlRepositoryInterface.php
Normal file
8
src/Repository/ShortUrlRepositoryInterface.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Acelaya\UrlShortener\Repository;
|
||||
|
||||
use Doctrine\Common\Persistence\ObjectRepository;
|
||||
|
||||
interface ShortUrlRepositoryInterface extends ObjectRepository, PaginableRepository
|
||||
{
|
||||
}
|
@ -4,6 +4,7 @@ namespace Acelaya\UrlShortener\Service;
|
||||
use Acelaya\UrlShortener\Entity\ShortUrl;
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Zend\Paginator\Paginator;
|
||||
|
||||
class ShortUrlService implements ShortUrlServiceInterface
|
||||
{
|
||||
@ -24,7 +25,7 @@ class ShortUrlService implements ShortUrlServiceInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ShortUrl[]
|
||||
* @return Paginator|ShortUrl[]
|
||||
*/
|
||||
public function listShortUrls()
|
||||
{
|
||||
|
@ -2,11 +2,12 @@
|
||||
namespace Acelaya\UrlShortener\Service;
|
||||
|
||||
use Acelaya\UrlShortener\Entity\ShortUrl;
|
||||
use Zend\Paginator\Paginator;
|
||||
|
||||
interface ShortUrlServiceInterface
|
||||
{
|
||||
/**
|
||||
* @return ShortUrl[]
|
||||
* @return Paginator|ShortUrl[]
|
||||
*/
|
||||
public function listShortUrls();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use Acelaya\UrlShortener\Exception\InvalidArgumentException;
|
||||
use Acelaya\UrlShortener\Exception\InvalidShortCodeException;
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Zend\Paginator\Paginator;
|
||||
|
||||
class VisitsTracker implements VisitsTrackerInterface
|
||||
{
|
||||
@ -65,7 +66,7 @@ class VisitsTracker implements VisitsTrackerInterface
|
||||
* Returns the visits on certain shortcode
|
||||
*
|
||||
* @param $shortCode
|
||||
* @return Visit[]
|
||||
* @return Paginator|Visit[]
|
||||
*/
|
||||
public function info($shortCode)
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace Acelaya\UrlShortener\Service;
|
||||
|
||||
use Acelaya\UrlShortener\Entity\Visit;
|
||||
use Zend\Paginator\Paginator;
|
||||
|
||||
interface VisitsTrackerInterface
|
||||
{
|
||||
@ -17,7 +18,7 @@ interface VisitsTrackerInterface
|
||||
* Returns the visits on certain shortcode
|
||||
*
|
||||
* @param $shortCode
|
||||
* @return Visit[]
|
||||
* @return Paginator|Visit[]
|
||||
*/
|
||||
public function info($shortCode);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user