diff --git a/composer.json b/composer.json index 15f92bee..374fed26 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Repository/PaginableRepository.php b/src/Repository/PaginableRepository.php new file mode 100644 index 00000000..ad993961 --- /dev/null +++ b/src/Repository/PaginableRepository.php @@ -0,0 +1,14 @@ +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(); + } +} diff --git a/src/Repository/ShortUrlRepositoryInterface.php b/src/Repository/ShortUrlRepositoryInterface.php new file mode 100644 index 00000000..37b013d9 --- /dev/null +++ b/src/Repository/ShortUrlRepositoryInterface.php @@ -0,0 +1,8 @@ +