From 9ffdf03724a3c4470b1feef0051349ab65ea93f2 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Tue, 30 Jan 2018 16:20:28 +0100 Subject: [PATCH] FEAT #39 Refactoring reports --- composer.json | 1 + rest/index.php | 16 +++++----- .../report/controllers}/ReportController.php | 19 ++++++------ .../app/report/models}/ReportModel.php | 6 ++-- .../report/models}/ReportModelAbstract.php | 29 ++++++++++--------- 5 files changed, 36 insertions(+), 35 deletions(-) rename {core/Controllers => src/app/report/controllers}/ReportController.php (78%) mode change 100755 => 100644 rename {core/Models => src/app/report/models}/ReportModel.php (71%) mode change 100755 => 100644 rename {core/Models => src/app/report/models}/ReportModelAbstract.php (76%) mode change 100755 => 100644 diff --git a/composer.json b/composer.json index fd14246830b..9ba084e910e 100755 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "History\\" : "src/app/history/", "Parameter\\" : "src/app/parameter/", "Priority\\" : "src/app/priority/", + "Report\\" : "src/app/report/", "Resource\\" : "src/app/resource/", "Status\\" : "src/app/status/", diff --git a/rest/index.php b/rest/index.php index d849286c732..7e9f4f5ce5f 100755 --- a/rest/index.php +++ b/rest/index.php @@ -118,8 +118,8 @@ $app->get('/administration/notifications/{id}', \Notifications\Controllers\Notif //Baskets $app->get('/baskets', \Basket\controllers\BasketController::class . ':get'); -$app->get('/baskets/{id}', \Basket\controllers\BasketController::class . ':getById'); $app->post('/baskets', \Basket\controllers\BasketController::class . ':create'); +$app->get('/baskets/{id}', \Basket\controllers\BasketController::class . ':getById'); $app->put('/baskets/{id}', \Basket\controllers\BasketController::class . ':update'); $app->delete('/baskets/{id}', \Basket\controllers\BasketController::class . ':delete'); $app->get('/baskets/{id}/groups', \Basket\controllers\BasketController::class . ':getGroups'); @@ -132,11 +132,11 @@ $app->put('/sortedBaskets/{id}', \Basket\controllers\BasketController::class . ' //statuses $app->get('/statuses', \Status\controllers\StatusController::class . ':get'); -$app->get('/administration/statuses/new', \Status\controllers\StatusController::class . ':getNewInformations'); -$app->get('/statuses/{identifier}', \Status\controllers\StatusController::class . ':getByIdentifier'); $app->post('/statuses', \Status\controllers\StatusController::class . ':create'); +$app->get('/statuses/{identifier}', \Status\controllers\StatusController::class . ':getByIdentifier'); $app->put('/statuses/{identifier}', \Status\controllers\StatusController::class . ':update'); $app->delete('/statuses/{identifier}', \Status\controllers\StatusController::class . ':delete'); +$app->get('/administration/statuses/new', \Status\controllers\StatusController::class . ':getNewInformations'); //groups $app->get('/groups', \Core\Controllers\GroupController::class . ':get'); @@ -220,11 +220,11 @@ $app->put('/priorities/{id}', \Priority\controllers\PriorityController::class . $app->delete('/priorities/{id}', \Priority\controllers\PriorityController::class . ':delete'); //History -$app->get('/administration/history/eventDate/{date}', \History\controllers\HistoryController::class . ':getForAdministration'); +$app->get('/administration/history/eventDate/{date}', \History\controllers\HistoryController::class . ':getForAdministration'); //TODO No date $app->get('/histories/users/{userSerialId}', \History\controllers\HistoryController::class . ':getByUserId'); //HistoryBatch -$app->get('/administration/historyBatch/eventDate/{date}', \History\controllers\HistoryController::class . ':getBatchForAdministration'); +$app->get('/administration/historyBatch/eventDate/{date}', \History\controllers\HistoryController::class . ':getBatchForAdministration');//TODO No date //actions $app->get('/actions', \Action\controllers\ActionController::class . ':get'); @@ -242,8 +242,8 @@ $app->put('/notifications/{id}', \Notifications\Controllers\NotificationControll $app->delete('/notifications/{id}', \Notifications\Controllers\NotificationController::class . ':delete'); //Reports -$app->get('/reports/groups/{groupId}', \Core\Controllers\ReportController::class . ':getByGroupId'); -$app->put('/reports/groups/{groupId}', \Core\Controllers\ReportController::class . ':updateForGroupId'); +$app->get('/reports/groups/{groupId}', \Report\controllers\ReportController::class . ':getByGroupId'); +$app->put('/reports/groups/{groupId}', \Report\controllers\ReportController::class . ':updateForGroupId'); //Listinstance $app->get('/listinstance/{id}', \Core\Controllers\ListinstanceController::class . ':getById'); @@ -258,6 +258,6 @@ $app->post('/templates/{id}/duplicate', \Templates\Controllers\TemplateControlle $app->get('/links/resId/{resId}', \Core\Controllers\LinkController::class . ':getByResId'); //liste documents -$app->get('/res/listDocs/{clause}/{select}', \Core\Controllers\ResController::class . ':getListDocs'); +$app->get('/res/listDocs/{clause}/{select}', \Resource\controllers\ResController::class . ':getListDocs');//TODO No clause $app->run(); diff --git a/core/Controllers/ReportController.php b/src/app/report/controllers/ReportController.php old mode 100755 new mode 100644 similarity index 78% rename from core/Controllers/ReportController.php rename to src/app/report/controllers/ReportController.php index e8b9d93a4c0..f14e59a563f --- a/core/Controllers/ReportController.php +++ b/src/app/report/controllers/ReportController.php @@ -10,23 +10,22 @@ /** * @brief Report Controller * @author dev@maarch.org -* @ingroup core */ -namespace Core\Controllers; +namespace Report\controllers; use Core\Models\GroupModel; use Core\Models\ServiceModel; -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseInterface; -use Core\Models\ReportModel; +use Report\models\ReportModel; +use Slim\Http\Request; +use Slim\Http\Response; class ReportController { - public function getByGroupId(RequestInterface $request, ResponseInterface $response, $aArgs) + public function getByGroupId(Request $request, Response $response, array $aArgs) { - if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $_SESSION['user']['UserId'], 'location' => 'apps', 'type' => 'admin'])) { + if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } @@ -40,9 +39,9 @@ class ReportController return $response->withJson(['reports' => $reports]); } - public function updateForGroupId(RequestInterface $request, ResponseInterface $response, $aArgs) + public function updateForGroupId(Request $request, Response $response, array $aArgs) { - if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $_SESSION['user']['UserId'], 'location' => 'apps', 'type' => 'admin'])) { + if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } @@ -75,7 +74,7 @@ class ReportController ReportModel::deleteForGroupId(['groupId' => $aArgs['groupId'], 'reportIds' => $reportIdsToDelete]); } - return $response->withJson(['success' => _SAVED_CHANGE]); + return $response->withJson(['success' => 'success']); } } diff --git a/core/Models/ReportModel.php b/src/app/report/models/ReportModel.php old mode 100755 new mode 100644 similarity index 71% rename from core/Models/ReportModel.php rename to src/app/report/models/ReportModel.php index 149a59edb61..bfb7bed0398 --- a/core/Models/ReportModel.php +++ b/src/app/report/models/ReportModel.php @@ -8,14 +8,12 @@ */ /** -* @brief Attachment Model +* @brief Report Model * @author dev@maarch.org -* @ingroup core */ -namespace Core\Models; +namespace Report\models; class ReportModel extends ReportModelAbstract { - // Do your stuff in this class } diff --git a/core/Models/ReportModelAbstract.php b/src/app/report/models/ReportModelAbstract.php old mode 100755 new mode 100644 similarity index 76% rename from core/Models/ReportModelAbstract.php rename to src/app/report/models/ReportModelAbstract.php index 375ade90752..065cc9db969 --- a/core/Models/ReportModelAbstract.php +++ b/src/app/report/models/ReportModelAbstract.php @@ -8,12 +8,15 @@ */ /** -* @brief Reports Model +* @brief Report Model Abstract * @author dev@maarch.org -* @ingroup core */ -namespace Core\Models; +namespace Report\models; + +use Core\Models\CoreConfigModel; +use Core\Models\DatabaseModel; +use Core\Models\ValidatorModel; class ReportModelAbstract { @@ -30,21 +33,21 @@ class ReportModelAbstract } $reports = []; - $xmlfile = simplexml_load_file($path); + $xmlfile = simplexml_load_file($path); if ($xmlfile) { foreach ($xmlfile->REPORT as $value) { if ((string)$value->ENABLED == "true") { $reports[] = [ - 'id' => (string)$value->ID, - 'label' => constant((string)$value->LABEL), - 'desc' => constant((string)$value->DESCRIPTION), - 'url' => (string)$value->URL, - 'in_menu_reports' =>(string)$value->IN_MENU_REPORTS, - 'origin' => (string)$value->ORIGIN, - 'module' => (string)$value->MODULE, - 'module_label' => (string)$value->MODULE_LABEL, - 'checked' => false + 'id' => (string)$value->ID, + 'label' => constant((string)$value->LABEL), + 'desc' => constant((string)$value->DESCRIPTION), + 'url' => (string)$value->URL, + 'in_menu_reports' => (string)$value->IN_MENU_REPORTS, + 'origin' => (string)$value->ORIGIN, + 'module' => (string)$value->MODULE, + 'module_label' => (string)$value->MODULE_LABEL, + 'checked' => false ]; } } -- GitLab