mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 18:13:48 +00:00
Add history page for all news items with a search filter on the basis of the title or content
This commit is contained in:
@@ -57,17 +57,46 @@ class NewsItemRepository implements ObjectRepository
|
||||
return NewsItem::class;
|
||||
}
|
||||
|
||||
public function buildBaseQuery(
|
||||
string $pattern = null
|
||||
): QueryBuilder {
|
||||
$qb = $this->createQueryBuilder('n');
|
||||
|
||||
if (null !== $pattern && '' !== $pattern) {
|
||||
$qb->andWhere($qb->expr()->like('LOWER(UNACCENT(n.title))', 'LOWER(UNACCENT(:pattern))'))
|
||||
->orWhere($qb->expr()->like('LOWER(UNACCENT(n.content))', 'LOWER(UNACCENT(:pattern))'))
|
||||
->setParameter('pattern', '%'.$pattern.'%');
|
||||
}
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function findAllFilteredByUser(string $pattern = null)
|
||||
{
|
||||
$qb = $this->buildBaseQuery($pattern);
|
||||
$qb->addOrderBy('n.startDate', 'DESC')
|
||||
->addOrderBy('n.id', 'DESC');
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function findWithDateFilter()
|
||||
{
|
||||
dump($this->buildQueryWithDateFilter()
|
||||
->getQuery()
|
||||
->getResult());
|
||||
|
||||
return $this->buildQueryWithDateFilter()
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
public function countAllFilteredByUser(string $pattern = null)
|
||||
{
|
||||
$qb = $this->buildBaseQuery($pattern);
|
||||
|
||||
return $qb
|
||||
->select('COUNT(n)')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function countWithDateFilter()
|
||||
{
|
||||
return $this->buildQueryWithDateFilter()
|
||||
|
Reference in New Issue
Block a user