- Add `goals` class for managing goal metrics and calculations. - Extend `goals_criteria` with timeframe initialization and validation. - Implement `getListByCriteria` in `order_items_o.php` for product-based goal evaluation. - Add unit tests for `goals` to validate
58 lines
2.2 KiB
PHP
58 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace routes;
|
|
|
|
use classes\entra;
|
|
use classes\redis;
|
|
use goals\classes\goals;
|
|
use goals\classes\goals_criteria;
|
|
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;
|
|
$goal = (new goals());
|
|
$response->success(['message' => 'Debugging route!']);
|
|
});
|
|
}
|
|
} |