Files
api/services/nginx/app/routes/exampleRoute.php
T
Jeppe Bundgaard 16f041600c Refactor Slack notification logic in departments_o.php and exampleRoute.php
- Update `send_webhook_message` to include custom department webhook.
- Add `sendSlackInternalStatisticNotification` to handle additional statistics notifications.
2026-01-26 13:15:38 +01:00

57 lines
2.2 KiB
PHP

<?php
namespace routes;
use classes\entra;
use classes\redis;
use objects\departments_o;
use traits\route_t;
class exampleRoute
{
use route_t;
public function run(): void
{
$this->get('/example', function () {
global $response;
// This is very hack-y, but it works for now
// Check if it's monday
if ((int)date('N') === 1) {
// Check if the time is between 06:00 and 17:00
if (!redis->exists('system:last_sent_monday_message') && (date('H') >= 6 && date('H') < 17)) {
// Set the key to expire in 24 hours
redis->set('system:last_sent_monday_message', date('Y-m-d H:i:s'));
redis->expire('system:last_sent_monday_message', 86400);
// Send the messages
$departments = [
1,
2,
3,
4,
5,
6,
7,
];
foreach ($departments as $department_id) {
$department = (new departments_o())->select((int)$department_id);
$days = 7;
// The time should be from 00:00:00 of the start date to 23:59:59 of the end date
$date_end = date('Y-m-d 23:59:59', strtotime("-1 days")); // Yesterday (Sunday) at 23:59:59
$date_start = date('Y-m-d 00:00:00', strtotime("-$days days")); // $days ago at 00:00:00
$department->sendPeriodStatisticsToSlack($date_start, $date_end); // Sends message to "daglig-ledelse".
}
$department->sendSlackInternalStatisticNotification($date_start, $date_end, $departments);
}
}
$response->success(['message' => 'Hello World!']);
});
$this->get('/debug', function () {
global $response;
$entra = new entra();
$GraphClient = $entra->getGraphClient();
$response->success(['message' => 'Debugging route!']);
});
}
}