Add history page for all news items with a search filter on the basis of the title or content

This commit is contained in:
2023-11-20 17:13:04 +01:00
parent e8b8f30e3c
commit c185c35c44
5 changed files with 174 additions and 4 deletions

View File

@@ -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()