Filter data
[MAILPOET-3135]
This commit is contained in:
@@ -22,9 +22,18 @@ class Logs {
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$search = isset($_GET['search']) ? $_GET['search'] : null;
|
||||
$from = isset($_GET['from']) ? $_GET['from'] : null;
|
||||
$to = isset($_GET['to']) ? $_GET['to'] : null;
|
||||
$dateFrom = (new Carbon())->subDays(7);
|
||||
$dateTo = new Carbon();
|
||||
$logs = $this->logRepository->getLogs($dateFrom, $dateTo);
|
||||
if (isset($from)) {
|
||||
$dateFrom = new Carbon($from);
|
||||
}
|
||||
$dateTo = null;
|
||||
if (isset($to)) {
|
||||
$dateTo = new Carbon($to);
|
||||
}
|
||||
$logs = $this->logRepository->getLogs($dateFrom, $dateTo, $search);
|
||||
$data = ['logs' => []];
|
||||
foreach ($logs as $log) {
|
||||
$data['logs'][] = [
|
||||
|
@@ -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