Skip to content
Snippets Groups Projects
Verified Commit 67421bc2 authored by Damien's avatar Damien
Browse files

FEAT #7737 Template entities

parent 3c5382a3
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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');
......
......@@ -14,7 +14,6 @@
namespace ContentManagement\controllers;
use Docserver\models\DocserverModel;
use Slim\Http\Request;
use Slim\Http\Response;
......
......@@ -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();
......
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