Newer
Older
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
use SrcCore\controllers\LogsController;
use SrcCore\models\ValidatorModel;
use Notification\controllers\NotificationsEventsController;
ValidatorModel::notEmpty($aArgs, ['tableName', 'recordId', 'eventType', 'info', 'eventId']);
ValidatorModel::stringType($aArgs, ['tableName', 'eventType', 'info', 'eventId', 'moduleId', 'level']);
$aArgs['isTech'] = false;
}
HistoryModel::create([
'tableName' => $aArgs['tableName'],
'recordId' => $aArgs['recordId'],
'eventType' => $aArgs['eventType'],
'info' => $aArgs['info'],
'moduleId' => $aArgs['moduleId'],
'eventId' => $aArgs['eventId'],
]);
NotificationsEventsController::fill_event_stack([
"eventId" => $aArgs['eventId'],
"tableName" => $aArgs['tableName'],
"recordId" => $aArgs['recordId'],
"userId" => $GLOBALS['userId'],
"info" => $aArgs['info'],
public function getByUserId(Request $request, Response $response, array $aArgs)
{
$user = UserModel::getById(['id' => $aArgs['userSerialId'], 'select' => ['user_id']]);
if ($user['user_id'] != $GLOBALS['userId'] && !ServiceModel::hasService(['id' => 'view_history', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
$aHistories = HistoryModel::getByUserId(['userId' => $user['user_id'], 'select' => ['info', 'event_date']]);
return $response->withJson(['histories' => $aHistories]);
}
public function get(Request $request, Response $response, array $aArgs)
if (!ServiceModel::hasService(['id' => 'view_history', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
$historyList = HistoryModel::getHistoryList(['event_date' => $aArgs['date']]);
$historyListFilters['users'] = HistoryModel::getFilter(['select' => 'user_id', 'event_date' => $aArgs['date']]);
$historyListFilters['eventType'] = HistoryModel::getFilter(['select' => 'event_type', 'event_date' => $aArgs['date']]);
return $response->withJson(['filters' => $historyListFilters, 'historyList' => $historyList]);