Filter data
[MAILPOET-3135]
This commit is contained in:
@@ -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');
|
||||
|
||||
|
Reference in New Issue
Block a user