Introduce a scalable statistics architecture including `statistics` class, interface, and related implementations. Added support for tracking new bookings with routes and data handling through `bookings_s` and `statistic_t`. Integrated the feature into the application using autoloaders and response mechanisms.
48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace routes;
|
|
|
|
use classes\authentication;
|
|
use classes\response;
|
|
use classes\statistics;
|
|
use objects\logs_o;
|
|
use traits\route_t;
|
|
|
|
class statisticsRoute
|
|
{
|
|
use route_t;
|
|
|
|
public function run(): void
|
|
{
|
|
/** Statistics >> Bookings >> New bookings */
|
|
$this->get('/statistics/bookings/new', function () {
|
|
// Require the user to be logged in
|
|
global
|
|
/** @var response $response */
|
|
$EMAIL_WASH_CERTIFICATE_TOKEN,
|
|
$response;
|
|
$this->requirePermission('statistics_bookings_new');
|
|
// Get the user object
|
|
$user = (new authentication())->get_user();
|
|
// Check if the request was successful
|
|
if ($user) {
|
|
// Log the incident
|
|
(new logs_o())->add('statistics', 'global', 1, $user->id, 'NEW_BOOKINGS', 'User requested new bookings');
|
|
$statics = new statistics();
|
|
// Return the list of bookings
|
|
$response->success(
|
|
$statics
|
|
->bookings()
|
|
->get_new_bookings()
|
|
->get_response()
|
|
);
|
|
} else {
|
|
// Log the incident
|
|
(new logs_o())->add('statistics', 'global', 0, 0, 'NEW_BOOKINGS', 'User requested new bookings');
|
|
// Return an error
|
|
$response->error('Invalid session', 400);
|
|
}
|
|
});
|
|
|
|
}
|
|
} |