Files
breadcrumb-the-shire/pages/admin/mail-log/data().php

58 lines
1.6 KiB
PHP
Raw Normal View History

2026-02-04 23:31:53 +01:00
<?php
use MintyPHP\Router;
use MintyPHP\Support\Guard;
use MintyPHP\Service\MailLogService;
use MintyPHP\Service\PermissionService;
Guard::requireLogin();
Guard::requirePermissionOrForbidden(PermissionService::MAIL_LOG_VIEW);
$limit = (int) ($_GET['limit'] ?? 10);
$offset = (int) ($_GET['offset'] ?? 0);
$search = trim((string) ($_GET['search'] ?? ''));
$order = (string) ($_GET['order'] ?? 'created_at');
$dir = (string) ($_GET['dir'] ?? 'desc');
$status = trim((string) ($_GET['status'] ?? ''));
$createdFrom = trim((string) ($_GET['created_from'] ?? ''));
$createdTo = trim((string) ($_GET['created_to'] ?? ''));
$result = MailLogService::listPaged([
'limit' => $limit,
'offset' => $offset,
'search' => $search,
'order' => $order,
'dir' => $dir,
'status' => $status,
'created_from' => $createdFrom,
'created_to' => $createdTo,
]);
$rows = [];
foreach ($result['rows'] as $row) {
$status = (string) ($row['status'] ?? '');
$statusBadge = 'neutral';
if ($status === 'sent') {
$statusBadge = 'success';
} elseif ($status === 'failed') {
$statusBadge = 'danger';
}
$rows[] = [
'id' => $row['id'] ?? null,
'to_email' => $row['to_email'] ?? '',
'subject' => $row['subject'] ?? '',
'template' => $row['template'] ?? '',
'status' => $status,
'status_badge' => $statusBadge,
'status_label' => t(ucfirst($status)),
'created_at' => dt($row['created_at'] ?? ''),
'sent_at' => dt($row['sent_at'] ?? ''),
];
}
Router::json([
'data' => $rows,
'total' => $result['total'] ?? 0,
]);