Files
api/services/nginx/app/routes/exampleRoute.php
T

56 lines
2.1 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 quite 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);
}
}
}
$response->success(['message' => 'Hello World!', 'time' => date('Y-m-d H:i:s'), 'date' => (int)date('N')]);
});
$this->get('/debug', function () {
global $response;
$entra = new entra();
$GraphClient = $entra->getGraphClient();
$response->success(['message' => 'Debugging route!']);
});
}
}