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
$entities[$key]['selected'] = true;
}
}
$template['entities'] = $entities;
$attachmentModelsTmp = AttachmentModel::getAttachmentsTypesByXML();
$attachmentTypes = [];
......@@ -73,10 +72,11 @@ class TemplateController
}
return $response->withJson([
'template' => $template,
'templatesModels' => TemplateController::getModels(),
'attachmentTypes' => $attachmentTypes,
'datasources' => TemplateModel::getDatasources()
'template' => $template,
'templatesModels' => TemplateController::getModels(),
'attachmentTypes' => $attachmentTypes,
'datasources' => TemplateModel::getDatasources(),
'entities' => $entities
]);
}
......@@ -92,21 +92,25 @@ class TemplateController
}
if ($data['template_type'] == 'OFFICE') {
$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']]);
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'];
} 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);
......@@ -134,15 +138,7 @@ class TemplateController
}
$data = $request->getParams();
$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) {
if (!TemplateController::checkData(['data' => $data])) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
}
......@@ -151,6 +147,26 @@ class TemplateController
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'])) {
TemplateAssociationModel::delete(['where' => ['template_id = ?'], 'data' => [$aArgs['id']]]);
foreach ($data['entities'] as $entity) {
......@@ -338,7 +354,6 @@ class TemplateController
if ($data['template_type'] == 'HTML' || $data['template_type'] == 'TXT') {
$check = $check && Validator::stringType()->notEmpty()->validate($data['template_content']);
} else {
$check = $check && Validator::stringType()->notEmpty()->validate($data['userUniqueId']);
$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