From 817b2b5c7f17b0139b7387b61f7c72a816038d1e Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Thu, 14 Jun 2018 16:54:15 +0200 Subject: [PATCH] FEAT #7739 History services --- apps/maarch_entreprise/xml/services.xml | 2 +- src/app/group/models/ServiceModelAbstract.php | 41 ++++++++++--------- .../controllers/TemplateController.php | 4 +- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/apps/maarch_entreprise/xml/services.xml b/apps/maarch_entreprise/xml/services.xml index 562ef4fec16..f0958ba837a 100755 --- a/apps/maarch_entreprise/xml/services.xml +++ b/apps/maarch_entreprise/xml/services.xml @@ -90,7 +90,7 @@ <id>view_history_batch</id> <name>_HISTORY_BATCH</name> <comment>_ADMIN_HISTORY_BATCH_DESC</comment> - <servicepage>/administration/historyBatch</servicepage> + <servicepage>/administration</servicepage> <servicetype>admin</servicetype> <category>supervision</category> <system_service>false</system_service> diff --git a/src/app/group/models/ServiceModelAbstract.php b/src/app/group/models/ServiceModelAbstract.php index cca49003ed0..03dd8a34673 100755 --- a/src/app/group/models/ServiceModelAbstract.php +++ b/src/app/group/models/ServiceModelAbstract.php @@ -104,18 +104,29 @@ abstract class ServiceModelAbstract $applicationServices = []; if ($xmlfile) { + $hasHistory = false; foreach ($xmlfile->SERVICE as $value) { if ((string) $value->servicetype == 'admin' && (string) $value->enabled === 'true' && ((string) $value->system_service == 'true' || in_array((string) $value->id, $aArgs['userServices']))) { - $category = (string) $value->category; - $name = defined((string) $value->name) ? constant((string) $value->name) : (string) $value->name; - $comment = defined((string) $value->comment) ? constant((string) $value->comment) : (string) $value->comment; - $applicationServices[$category][] = [ - 'name' => $name, - 'comment' => $comment, - 'servicepage' => (string) $value->servicepage, - 'style' => (string) $value->style, - 'angular' => empty((string) $value->angular) ? 'false' : (string) $value->angular, - ]; + if ((string)$value->id == 'view_history' || (string)$value->id == 'view_history_batch') { + $hasHistory = true; + } + } + } + foreach ($xmlfile->SERVICE as $value) { + $historyByPass = (string)$value->id == 'view_history' && $hasHistory; + if ($historyByPass || ((string) $value->servicetype == 'admin' && (string) $value->enabled === 'true' && ((string) $value->system_service == 'true' || in_array((string) $value->id, $aArgs['userServices'])))) { + if ((string)$value->id != 'view_history_batch') { + $category = (string) $value->category; + $name = defined((string) $value->name) ? constant((string) $value->name) : (string) $value->name; + $comment = defined((string) $value->comment) ? constant((string) $value->comment) : (string) $value->comment; + $applicationServices[$category][] = [ + 'name' => $name, + 'comment' => $comment, + 'servicepage' => (string) $value->servicepage, + 'style' => (string) $value->style, + 'angular' => empty((string) $value->angular) ? 'false' : (string) $value->angular, + ]; + } } } } @@ -319,17 +330,7 @@ abstract class ServiceModelAbstract $administration = []; $administrationApplication = ServiceModel::getApplicationAdministrationServicesByUserServices(['userServices' => $servicesStoredInDB]); $administrationModule = ServiceModel::getModulesAdministrationServicesByUserServices(['userServices' => $servicesStoredInDB]); - - foreach ($administrationApplication['supervision'] as $key => $value) { - if ($value['name'] === _HISTORY_BATCH) { - array_splice($administrationApplication['supervision'], $key, 1); - } - } - unset($key); - $administration['administrations'] = array_merge_recursive($administrationApplication, $administrationModule); - - return $administration; } diff --git a/src/app/template/controllers/TemplateController.php b/src/app/template/controllers/TemplateController.php index 948202985c3..73753615cb0 100644 --- a/src/app/template/controllers/TemplateController.php +++ b/src/app/template/controllers/TemplateController.php @@ -58,7 +58,7 @@ class TemplateController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $template = TemplateModel::getById(['id' => $aArgs['id']]); + $template = TemplateModel::getById(['id' => $aArgs['id'], 'select' => [1]]); if (empty($template)) { return $response->withStatus(400)->withJson(['errors' => 'Template does not exist']); } @@ -225,8 +225,8 @@ class TemplateController $data['template_file_name'] = $storeResult['file_destination_name']; } + TemplateAssociationModel::delete(['where' => ['template_id = ?'], 'data' => [$aArgs['id']]]); if (!empty($data['entities']) && is_array($data['entities'])) { - TemplateAssociationModel::delete(['where' => ['template_id = ?'], 'data' => [$aArgs['id']]]); foreach ($data['entities'] as $entity) { TemplateAssociationModel::create(['templateId' => $aArgs['id'], 'entityId' => $entity]); } -- GitLab