diff --git a/core/Test/CoreControllerTest.php b/core/Test/CoreControllerTest.php index c28b94a5ec0e950cccc302c98d854bd5fe811c28..8e879e4eef4a50e294ad06f2a66f23fec909c620 100644 --- a/core/Test/CoreControllerTest.php +++ b/core/Test/CoreControllerTest.php @@ -32,7 +32,7 @@ class CoreControllerTest extends TestCase public function testrenderJnlp() { // ERROR FILE NAME - $coreController = new \SrcCore\controllers\CoreController(); + $coreController = new \ContentManagement\controllers\JnlpController(); $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $request = \Slim\Http\Request::createFromEnvironment($environment); diff --git a/rest/index.php b/rest/index.php index 435a0851ad5210b1a1749e46925715af44a14201..321ecad5a6af0c3f2e85e1aba5f1ae8f742fcaee 100755 --- a/rest/index.php +++ b/rest/index.php @@ -225,12 +225,12 @@ $app->get('/administration/statuses/new', \Status\controllers\StatusController:: //Templates $app->get('/templates', \Template\controllers\TemplateController::class . ':get'); -$app->get('/initTemplate', \Template\controllers\TemplateController::class . ':initTemplate'); $app->post('/templates', \Template\controllers\TemplateController::class . ':create'); -$app->get('/templates/{id}', \Template\controllers\TemplateController::class . ':getById'); +$app->get('/templates/{id}/details', \Template\controllers\TemplateController::class . ':getDetailledById'); $app->put('/templates/{id}', \Template\controllers\TemplateController::class . ':update'); $app->delete('/templates/{id}', \Template\controllers\TemplateController::class . ':delete'); $app->post('/templates/{id}/duplicate', \Template\controllers\TemplateController::class . ':duplicate'); +$app->get('/administration/templates/new', \Template\controllers\TemplateController::class . ':initTemplates'); //Users $app->get('/users', \User\controllers\UserController::class . ':get'); diff --git a/src/app/contentManagement/controllers/JnlpController.php b/src/app/contentManagement/controllers/JnlpController.php index bc8b951a95d834acb5b4d6882515f6cec033e088..5b6941174b8c1ac780baf31c5224d3bc48106ea4 100644 --- a/src/app/contentManagement/controllers/JnlpController.php +++ b/src/app/contentManagement/controllers/JnlpController.php @@ -14,7 +14,6 @@ namespace ContentManagement\controllers; - use Docserver\models\DocserverModel; use Slim\Http\Request; use Slim\Http\Response; diff --git a/src/app/template/controllers/TemplateController.php b/src/app/template/controllers/TemplateController.php index 4e0d75f56af93d331569d913308bcf6163af3ba6..91e62bcf69f76ff99e90c3b51428559245d7e779 100644 --- a/src/app/template/controllers/TemplateController.php +++ b/src/app/template/controllers/TemplateController.php @@ -40,21 +40,30 @@ class TemplateController return $response->withJson(['templates' => $templates]); } - public function getById(Request $request, Response $response, array $aArgs) + public function getDetailledById(Request $request, Response $response, array $aArgs) { if (!ServiceModel::hasService(['id' => 'admin_templates', 'userId' => $GLOBALS['userId'], 'location' => 'templates', 'type' => 'admin'])) { return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } $template = TemplateModel::getById(['id' => $aArgs['id']]); - $template['entities'] = []; - $linkedEntities = TemplateAssociationModel::get(['select' => ['value_field'], 'where' => ['template_id = ?'], 'data' => [$template['template_id']]]); - foreach ($linkedEntities as $linkedEntity) { - $template['entities'][] = $linkedEntity['value_field']; + $rawLinkedEntities = TemplateAssociationModel::get(['select' => ['value_field'], 'where' => ['template_id = ?'], 'data' => [$template['template_id']]]); + $linkedEntities = []; + foreach ($rawLinkedEntities as $rawLinkedEntity) { + $linkedEntities[] = $rawLinkedEntity['value_field']; } + $entities = EntityModel::getAllowedEntitiesByUserId(['userId' => 'superadmin']); + foreach ($entities as $key => $entity) { + $entities[$key]['selected'] = false; + if (in_array($entity['id'], $linkedEntities)) { + $entities[$key]['selected'] = true; + } + } + $template['entities'] = $entities; $attachmentModelsTmp = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentTypes = []; foreach ($attachmentModelsTmp as $key => $value) { $attachmentTypes[] = [ 'label' => $value['label'], @@ -66,8 +75,7 @@ class TemplateController 'template' => $template, 'templatesModels' => TemplateController::getModels(), 'attachmentTypes' => $attachmentTypes, - 'datasources' => '', - 'entities' => EntityModel::getAllowedEntitiesByUserId(['userId' => 'superadmin']) + 'datasources' => '' ]); } @@ -216,13 +224,14 @@ class TemplateController return $response->withJson(['id' => $templateId]); } - public function initTemplate(Request $request, Response $response) + public function initTemplates(Request $request, Response $response) { if (!ServiceModel::hasService(['id' => 'admin_templates', 'userId' => $GLOBALS['userId'], 'location' => 'templates', 'type' => 'admin'])) { return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } $attachmentModelsTmp = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentTypes = []; foreach ($attachmentModelsTmp as $key => $value) { $attachmentTypes[] = [ 'label' => $value['label'], @@ -230,15 +239,20 @@ class TemplateController ]; } + $entities = EntityModel::getAllowedEntitiesByUserId(['userId' => 'superadmin']); + foreach ($entities as $key => $entity) { + $entities[$key]['selected'] = false; + } + return $response->withJson([ 'templatesModels' => TemplateController::getModels(), 'attachmentTypes' => $attachmentTypes, 'datasources' => '', - 'entities' => EntityModel::getAllowedEntitiesByUserId(['userId' => 'superadmin']), + 'entities' => $entities, ]); } - public function getModels() + public static function getModels() { $customId = CoreConfigModel::getCustomId();