94 lines
3.3 KiB
PHP
94 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* Training reminders widget for the production dashboard.
|
|
* Visible to HR / manager / Admin / User / Superuser.
|
|
*
|
|
* Expects $pdo to be set (DBHandlerSelect connection).
|
|
*/
|
|
if (!isset($pdo)) {
|
|
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
|
}
|
|
|
|
$__trWidgetHr = isset($user)
|
|
&& ( $user->hasRole('Admin')
|
|
|| $user->hasRole('Superuser')
|
|
|| $user->hasRole('employee-hr')
|
|
|| $user->hasRole('manager'));
|
|
|
|
if (!$__trWidgetHr) {
|
|
return;
|
|
}
|
|
|
|
$__trRows = $pdo->query("
|
|
SELECT et.id,
|
|
et.next_due_date,
|
|
et.reminder_days,
|
|
tt.default_reminder_days
|
|
FROM employee_trainings et
|
|
JOIN training_topics tt ON tt.id = et.training_topic_id
|
|
WHERE et.next_due_date IS NOT NULL
|
|
")->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$__expiredCount = 0;
|
|
$__dueSoonCount = 0;
|
|
$__today = new DateTime('today');
|
|
foreach ($__trRows as $__r) {
|
|
$__rem = $__r['reminder_days'] !== null
|
|
? (int)$__r['reminder_days']
|
|
: ($__r['default_reminder_days'] !== null ? (int)$__r['default_reminder_days'] : 30);
|
|
$__due = DateTime::createFromFormat('Y-m-d', $__r['next_due_date']);
|
|
if (!$__due) continue;
|
|
$__days = (int)$__today->diff($__due)->format('%r%a');
|
|
if ($__days < 0) { $__expiredCount++; }
|
|
elseif ($__days <= $__rem) { $__dueSoonCount++; }
|
|
}
|
|
|
|
/* Missing mandatory trainings (status = not_present) */
|
|
$__notPresentCount = (int)$pdo->query("
|
|
SELECT COUNT(*)
|
|
FROM employees e
|
|
CROSS JOIN training_topics tt
|
|
WHERE tt.is_active = 1 AND tt.is_mandatory = 1
|
|
AND NOT EXISTS (
|
|
SELECT 1 FROM employee_trainings et
|
|
WHERE et.employee_id = e.id AND et.training_topic_id = tt.id
|
|
)
|
|
")->fetchColumn();
|
|
|
|
if ($__expiredCount === 0 && $__dueSoonCount === 0 && $__notPresentCount === 0) {
|
|
return;
|
|
}
|
|
?>
|
|
<div class="my-deadlines-widgets">
|
|
<?php if ($__expiredCount > 0): ?>
|
|
<a class="mdw mdw-red" href="trainings.php?status=expired">
|
|
<span class="mdw-icon"><i class="fa-solid fa-graduation-cap"></i></span>
|
|
<span class="mdw-body">
|
|
<span class="mdw-count"><?= (int)$__expiredCount ?></span>
|
|
<span class="mdw-label d-block">Formazion<?= $__expiredCount === 1 ? 'e scaduta' : 'i scadute' ?></span>
|
|
</span>
|
|
<span class="mdw-arrow"><i class="fa-solid fa-arrow-right"></i></span>
|
|
</a>
|
|
<?php endif; ?>
|
|
<?php if ($__dueSoonCount > 0): ?>
|
|
<a class="mdw mdw-orange" href="trainings.php?status=due_soon">
|
|
<span class="mdw-icon"><i class="fa-solid fa-hourglass-half"></i></span>
|
|
<span class="mdw-body">
|
|
<span class="mdw-count"><?= (int)$__dueSoonCount ?></span>
|
|
<span class="mdw-label d-block">Formazion<?= $__dueSoonCount === 1 ? 'e da aggiornare' : 'i da aggiornare' ?></span>
|
|
</span>
|
|
<span class="mdw-arrow"><i class="fa-solid fa-arrow-right"></i></span>
|
|
</a>
|
|
<?php endif; ?>
|
|
<?php if ($__notPresentCount > 0): ?>
|
|
<a class="mdw mdw-gray" href="trainings.php?status=not_present">
|
|
<span class="mdw-icon"><i class="fa-solid fa-circle-question"></i></span>
|
|
<span class="mdw-body">
|
|
<span class="mdw-count"><?= (int)$__notPresentCount ?></span>
|
|
<span class="mdw-label d-block">Obbligator<?= $__notPresentCount === 1 ? 'ia non presente' : 'ie non presenti' ?></span>
|
|
</span>
|
|
<span class="mdw-arrow"><i class="fa-solid fa-arrow-right"></i></span>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|