Filter data

[MAILPOET-3135]
This commit is contained in:
Pavel Dohnal
2021-03-03 14:02:41 +01:00
committed by Veljko V
parent 8bdcfebee8
commit 4481444282
2 changed files with 21 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ namespace MailPoet\Logging;
use MailPoet\Doctrine\Repository;
use MailPoet\Entities\LogEntity;
use MailPoet\Util\Helpers;
/**
* @extends Repository<LogEntity>
@@ -16,15 +17,16 @@ class LogRepository extends Repository {
/**
* @param \DateTimeInterface|null $dateFrom
* @param \DateTimeInterface|null $dateTo
* @param string|null $search
* @return LogEntity[]
*/
public function getLogs(\DateTimeInterface $dateFrom = null, \DateTimeInterface $dateTo = null): array {
public function getLogs(\DateTimeInterface $dateFrom = null, \DateTimeInterface $dateTo = null, string $search = null): array {
$query = $this->doctrineRepository->createQueryBuilder('l')
->select('l');
if ($dateFrom instanceof \DateTimeInterface) {
$query
->where('l.createdAt > :dateFrom')
->andWhere('l.createdAt > :dateFrom')
->setParameter('dateFrom', $dateFrom->format('Y-m-d H:i:s'));
}
if ($dateTo instanceof \DateTimeInterface) {
@@ -32,6 +34,12 @@ class LogRepository extends Repository {
->andWhere('l.createdAt < :dateTo')
->setParameter('dateTo', $dateTo->format('Y-m-d H:i:s'));
}
if ($search) {
$search = Helpers::escapeSearch($search);
$query
->andWhere('l.name LIKE :search or l.message LIKE :search')
->setParameter('search', "%$search%");
}
$query->orderBy('l.createdAt', 'desc');