63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
require_once dirname(dirname(__DIR__)) . '/bootstrap.php';
|
||
|
|
|
||
|
|
function task_cert_user_summary_widget_action(): array
|
||
|
|
{
|
||
|
|
$auth = TaskCertAuthContext::fromGlobals();
|
||
|
|
if (!$auth->isLoggedIn()) {
|
||
|
|
return [
|
||
|
|
'error' => null,
|
||
|
|
'open_count' => 0,
|
||
|
|
'overdue_count' => 0,
|
||
|
|
'escalated_count' => 0,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
$services = task_cert_services();
|
||
|
|
$assignments = $services['assignmentRepo']->listForUser($auth->contactId());
|
||
|
|
$now = new DateTimeImmutable();
|
||
|
|
|
||
|
|
$openCount = 0;
|
||
|
|
$overdueCount = 0;
|
||
|
|
$escalatedCount = 0;
|
||
|
|
|
||
|
|
foreach ($assignments as $assignment) {
|
||
|
|
$status = (string) ($assignment['status'] ?? '');
|
||
|
|
if (in_array($status, ['completed', 'expired'], true)) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
$openCount++;
|
||
|
|
|
||
|
|
$isOverdue = $status === 'overdue';
|
||
|
|
if (!$isOverdue) {
|
||
|
|
$dueAtRaw = trim((string) ($assignment['due_at'] ?? ''));
|
||
|
|
if ($dueAtRaw !== '') {
|
||
|
|
try {
|
||
|
|
$isOverdue = (new DateTimeImmutable($dueAtRaw)) < $now;
|
||
|
|
} catch (Throwable $throwable) {
|
||
|
|
$isOverdue = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($isOverdue) {
|
||
|
|
$overdueCount++;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ((int) ($assignment['escalation_level'] ?? 0) > 0) {
|
||
|
|
$escalatedCount++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return [
|
||
|
|
'error' => null,
|
||
|
|
'open_count' => $openCount,
|
||
|
|
'overdue_count' => $overdueCount,
|
||
|
|
'escalated_count' => $escalatedCount,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|