Files
awo-hamburg-intranet/module/tasks/pages/user/overdue_widget.php

96 lines
4.0 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
if (!isset($assignments) && !isset($error)) {
require_once dirname(dirname(__DIR__)) . '/actions/user/overdue_widget_action.php';
$viewData = task_cert_user_overdue_widget_action();
if (is_array($viewData)) {
extract($viewData, EXTR_SKIP);
}
}
$error = $error ?? null;
$assignments = $assignments ?? [];
$hasMore = (bool) ($has_more ?? false);
$totalCount = (int) ($total_count ?? count($assignments));
$limit = (int) ($limit ?? 0);
$statusLabels = TaskCertConstants::assignmentStatusLabels();
if (!function_exists('task_cert_render_styles')) {
require_once dirname(dirname(__DIR__)) . '/bootstrap.php';
}
task_cert_render_styles(['user']);
$taskDetailUrl = task_cert_view_url('user.task_detail');
$myTasksUrl = task_cert_view_url('user.my_tasks');
$formatDateTime = static function ($value): string {
$value = trim((string) $value);
if ($value === '') {
return 'Keine Fälligkeit';
}
try {
return (new DateTimeImmutable($value))->format('d.m.Y H:i');
} catch (Throwable $throwable) {
return $value;
}
};
?>
<div class="task-cert task-cert-user-overdue-widget">
<?php if ($error): ?>
<div class="task-cert-error"><?php echo TaskCertView::e($error); ?></div>
<?php else: ?>
<div class="task-cert-user-widget-head widget_header">
<h2>Überfällige und eskalierte Aufgaben</h2>
<span class="task-cert-user-widget-count"><?php echo $totalCount; ?></span>
</div>
<?php if ($assignments === []): ?>
<div class="task-cert-block task-cert-user-widget-empty">Aktuell keine überfälligen oder eskalierten Aufgaben.</div>
<?php else: ?>
<div class="task-cert-user-widget-list">
<?php foreach ($assignments as $assignment): ?>
<?php
$status = (string) ($assignment['status'] ?? '');
$isEscalated = (int) ($assignment['is_escalated'] ?? 0) === 1;
$isOverdue = (int) ($assignment['is_overdue_by_date'] ?? 0) === 1 || $status === 'overdue';
$widgetClasses = ['task-cert-user-widget-item', 'status-' . $status];
if ($isEscalated) {
$widgetClasses[] = 'is-escalated';
}
if ($isOverdue) {
$widgetClasses[] = 'is-overdue';
}
?>
<a
href="<?php echo TaskCertView::e($taskDetailUrl . '?assignment_id=' . (int) ($assignment['id'] ?? 0)); ?>"
class="<?php echo TaskCertView::e(implode(' ', $widgetClasses)); ?>"
>
<div class="task-cert-user-widget-item-head">
<strong><?php echo TaskCertView::e((string) ($assignment['title'] ?? 'Aufgabe')); ?></strong>
<span class="task-cert-user-status-badge status-<?php echo TaskCertView::e($status); ?>">
<?php echo TaskCertView::e($statusLabels[$status] ?? $status); ?>
</span>
</div>
<div class="task-cert-user-widget-meta">
<span>Fällig: <?php echo TaskCertView::e($formatDateTime((string) ($assignment['due_at'] ?? ''))); ?></span>
<?php if ($isEscalated): ?>
<span class="task-cert-user-widget-pill">Eskalation Stufe <?php echo (int) ($assignment['escalation_level'] ?? 0); ?></span>
<?php endif; ?>
</div>
</a>
<?php endforeach; ?>
</div>
<?php if ($hasMore): ?>
<div class="task-cert-hint">
Es werden <?php echo max(0, $limit); ?> von <?php echo $totalCount; ?> Aufgaben angezeigt.
</div>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</div>