Skip to content
Snippets Groups Projects
Commit 819f0033 authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #67 refactoring logs and history

parent 80a981be
No related branches found
No related tags found
No related merge requests found
<?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.
*
*/
/**
* @brief HistoryBatch Controller
* @author dev@maarch.org
*/
namespace History\controllers;
use Core\Models\ServiceModel;
use History\models\HistoryBatchModel;
use Slim\Http\Request;
use Slim\Http\Response;
class HistoryBatchController
{
public function get(Request $request, Response $response, array $aArgs)
{
if (!ServiceModel::hasService(['id' => 'view_history_batch', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
$historyList = HistoryBatchModel::get(['event_date' => $aArgs['date']]);
$historyListFilters['modules'] = HistoryBatchModel::getFilter(['select' => 'module_name', 'event_date' => $aArgs['date']]);
return $response->withJson(['filters' => $historyListFilters, 'historyList' => $historyList]);
}
}
......@@ -79,7 +79,7 @@ class HistoryController
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
$historyList = HistoryModel::getHistoryList(['event_date' => $aArgs['date']]);
$historyList = HistoryModel::get(['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']]);
......
<?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.
*
*/
/**
* @brief HistoryBatch Model
* @author dev@maarch.org
*/
namespace History\models;
class HistoryBatchModel extends HistoryBatchModelAbstract
{
// Do your stuff in this class
}
<?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.
*
*/
/**
* @brief HistoryBatch Model
* @author dev@maarch.org
*/
namespace History\models;
use SrcCore\models\ValidatorModel;
use SrcCore\models\DatabaseModel;
require_once('apps/maarch_entreprise/tools/log4php/Logger.php'); //TODO composer
class HistoryBatchModelAbstract
{
public static function get(array $aArgs = [])
{
ValidatorModel::notEmpty($aArgs, ['event_date']);
$aReturn = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['history_batch'],
'where' => ["event_date >= date '".$aArgs['event_date']."'","event_date < date '".$aArgs['event_date']."' + interval '1 month'"],
'order_by' => ['event_date DESC']
]);
return $aReturn;
}
public static function getFilter(array $aArgs = [])
{
ValidatorModel::notEmpty($aArgs, ['select','event_date']);
ValidatorModel::stringType($aArgs, ['select']);
$aReturn = DatabaseModel::select(
[
'select' => ['DISTINCT('.$aArgs['select'].')'],
'table' => ['history_batch'],
'where' => ["event_date >= date '".$aArgs['event_date']."'","event_date < date '".$aArgs['event_date']."' + interval '1 month'"],
'order_by' => [$aArgs['select'].' ASC']
]
);
return $aReturn;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment