mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 18:13:48 +00:00
update controller not to extend apiController and make some changes in repository + serializer
This commit is contained in:
@@ -5,7 +5,9 @@ namespace Chill\MainBundle\Repository;
|
||||
use Chill\MainBundle\Entity\NewsItem;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use Faker\Core\DateTime;
|
||||
|
||||
class NewsItemRepository implements ObjectRepository
|
||||
{
|
||||
@@ -17,6 +19,11 @@ class NewsItemRepository implements ObjectRepository
|
||||
$this->repository = $entityManager->getRepository(NewsItem::class);
|
||||
}
|
||||
|
||||
public function createQueryBuilder(string $alias, string $indexBy = null): QueryBuilder
|
||||
{
|
||||
return $this->repository->createQueryBuilder($alias, $indexBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -40,7 +47,6 @@ class NewsItemRepository implements ObjectRepository
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -56,4 +62,39 @@ class NewsItemRepository implements ObjectRepository
|
||||
{
|
||||
return NewsItem::class;
|
||||
}
|
||||
|
||||
public function findWithDateFilter()
|
||||
{
|
||||
return $this->buildQueryWithDateFilter()
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
public function countWithDateFilter()
|
||||
{
|
||||
return $this->buildQueryWithDateFilter()
|
||||
->select('COUNT(n)')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function buildQueryWithDateFilter(): QueryBuilder
|
||||
{
|
||||
$now = new \DateTime('now');
|
||||
|
||||
$qb = $this->createQueryBuilder('n');
|
||||
$qb
|
||||
->where(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->gte('n.startDate', ':now'),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->lt('n.endDate', ':now'),
|
||||
$qb->expr()->isNull('n.endDate')
|
||||
)
|
||||
)
|
||||
)
|
||||
->setParameter('now', $now);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user