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

FEAT #7737 Template file Update

parent 0fe24bbf
No related branches found
No related tags found
No related merge requests found
...@@ -61,7 +61,6 @@ class TemplateController ...@@ -61,7 +61,6 @@ class TemplateController
$entities[$key]['selected'] = true; $entities[$key]['selected'] = true;
} }
} }
$template['entities'] = $entities;
$attachmentModelsTmp = AttachmentModel::getAttachmentsTypesByXML(); $attachmentModelsTmp = AttachmentModel::getAttachmentsTypesByXML();
$attachmentTypes = []; $attachmentTypes = [];
...@@ -73,10 +72,11 @@ class TemplateController ...@@ -73,10 +72,11 @@ class TemplateController
} }
return $response->withJson([ return $response->withJson([
'template' => $template, 'template' => $template,
'templatesModels' => TemplateController::getModels(), 'templatesModels' => TemplateController::getModels(),
'attachmentTypes' => $attachmentTypes, 'attachmentTypes' => $attachmentTypes,
'datasources' => TemplateModel::getDatasources() 'datasources' => TemplateModel::getDatasources(),
'entities' => $entities
]); ]);
} }
...@@ -92,21 +92,25 @@ class TemplateController ...@@ -92,21 +92,25 @@ class TemplateController
} }
if ($data['template_type'] == 'OFFICE') { if ($data['template_type'] == 'OFFICE') {
$explodeStyle = explode(':', $data['template_style']); if (!empty($data['userUniqueId'])) {
$fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['userUniqueId']}." . strtolower($explodeStyle[0]); $explodeStyle = explode(':', $data['template_style']);
$storeResult = DocserverController::storeResourceOnDocServer([ $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['userUniqueId']}." . strtolower($explodeStyle[0]);
'collId' => 'templates', $storeResult = DocserverController::storeResourceOnDocServer([
'docserverTypeId' => 'TEMPLATES', 'collId' => 'templates',
'fileInfos' => [ 'docserverTypeId' => 'TEMPLATES',
'tmpDir' => CoreConfigModel::getTmpPath(), 'fileInfos' => [
'tmpFileName' => $fileOnTmp, 'tmpDir' => CoreConfigModel::getTmpPath(),
] 'tmpFileName' => $fileOnTmp,
]); ]
if (!empty($storeResult['errors'])) { ]);
return $response->withStatus(500)->withJson(['errors' => '[storeResource] ' . $storeResult['errors']]); if (!empty($storeResult['errors'])) {
return $response->withStatus(500)->withJson(['errors' => '[storeResource] ' . $storeResult['errors']]);
}
$data['template_path'] = $storeResult['destination_dir'];
$data['template_file_name'] = $storeResult['file_destination_name'];
} else {
return $response->withStatus(400)->withJson(['errors' => 'Template file is missing']);
} }
$data['template_path'] = $storeResult['destination_dir'];
$data['template_file_name'] = $storeResult['file_destination_name'];
} }
$id = TemplateModel::create($data); $id = TemplateModel::create($data);
...@@ -134,15 +138,7 @@ class TemplateController ...@@ -134,15 +138,7 @@ class TemplateController
} }
$data = $request->getParams(); $data = $request->getParams();
if (!TemplateController::checkData(['data' => $data])) {
$check = Validator::stringType()->notEmpty()->validate($data['template_label']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['template_comment']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['template_content']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['template_type']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['template_datasource']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['template_target']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['template_attachment_type']);
if (!$check) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
} }
...@@ -151,6 +147,26 @@ class TemplateController ...@@ -151,6 +147,26 @@ class TemplateController
return $response->withStatus(400)->withJson(['errors' => 'Template does not exist']); return $response->withStatus(400)->withJson(['errors' => 'Template does not exist']);
} }
if ($data['template_type'] == 'OFFICE') {
if (!empty($data['userUniqueId'])) {
$explodeStyle = explode(':', $data['template_style']);
$fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['userUniqueId']}." . strtolower($explodeStyle[0]);
$storeResult = DocserverController::storeResourceOnDocServer([
'collId' => 'templates',
'docserverTypeId' => 'TEMPLATES',
'fileInfos' => [
'tmpDir' => CoreConfigModel::getTmpPath(),
'tmpFileName' => $fileOnTmp,
]
]);
if (!empty($storeResult['errors'])) {
return $response->withStatus(500)->withJson(['errors' => '[storeResource] ' . $storeResult['errors']]);
}
$data['template_path'] = $storeResult['destination_dir'];
$data['template_file_name'] = $storeResult['file_destination_name'];
}
}
if (!empty($data['entities']) && is_array($data['entities'])) { if (!empty($data['entities']) && is_array($data['entities'])) {
TemplateAssociationModel::delete(['where' => ['template_id = ?'], 'data' => [$aArgs['id']]]); TemplateAssociationModel::delete(['where' => ['template_id = ?'], 'data' => [$aArgs['id']]]);
foreach ($data['entities'] as $entity) { foreach ($data['entities'] as $entity) {
...@@ -338,7 +354,6 @@ class TemplateController ...@@ -338,7 +354,6 @@ class TemplateController
if ($data['template_type'] == 'HTML' || $data['template_type'] == 'TXT') { if ($data['template_type'] == 'HTML' || $data['template_type'] == 'TXT') {
$check = $check && Validator::stringType()->notEmpty()->validate($data['template_content']); $check = $check && Validator::stringType()->notEmpty()->validate($data['template_content']);
} else { } else {
$check = $check && Validator::stringType()->notEmpty()->validate($data['userUniqueId']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['template_style']); $check = $check && Validator::stringType()->notEmpty()->validate($data['template_style']);
} }
......
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