Created Core module

This commit is contained in:
Alejandro Celaya
2016-07-19 18:01:39 +02:00
parent ba06ad44bd
commit ab9c2f728a
41 changed files with 121 additions and 100 deletions

View File

@@ -0,0 +1,61 @@
<?php
namespace Shlinkio\Shlink\Core\Repository;
use Doctrine\ORM\EntityRepository;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
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();
}
/**
* Counts the number of elements in a list using provided filtering data
*
* @param null $searchTerm
* @return int
*/
public function countList($searchTerm = null)
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('COUNT(s)')
->from(ShortUrl::class, 's');
if (isset($searchTerm)) {
// TODO
}
return (int) $qb->getQuery()->getSingleScalarResult();
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace Shlinkio\Shlink\Core\Repository;
use Doctrine\Common\Persistence\ObjectRepository;
use Shlinkio\Shlink\Common\Repository\PaginableRepositoryInterface;
interface ShortUrlRepositoryInterface extends ObjectRepository, PaginableRepositoryInterface
{
}