Styling refactoring

This commit is contained in:
Marc Ducobu 2021-08-19 18:24:20 +02:00
parent 237476dc28
commit 4184a74e7e

View File

@ -56,63 +56,63 @@ class DocGeneratorTemplateController extends AbstractController
public function generateDocFromTemplateAction(
TempUrlOpenstackGenerator $tempUrlGenerator,
DocGeneratorTemplate $template, string $entityClassName, int $entityId): Response
{
$getUrlGen = $tempUrlGenerator->generate(
'GET',
$template->getFile());
{
$getUrlGen = $tempUrlGenerator->generate(
'GET',
$template->getFile());
$tmpfname = tempnam(sys_get_temp_dir(), 'DOC_TEMPLATE');
file_put_contents($tmpfname, file_get_contents($getUrlGen->{"url"}));
$tmpfname = tempnam(sys_get_temp_dir(), 'DOC_TEMPLATE');
file_put_contents($tmpfname, file_get_contents($getUrlGen->{"url"}));
$entity = $this->getDoctrine()->getRepository($entityClassName)->find($entityId);
$entity = $this->getDoctrine()->getRepository($entityClassName)->find($entityId);
if ($template->getContext() == HouseholdMemberSelectionContext::class) {
$context = new HouseholdMemberSelectionContext();
// $datas = $context->getData($entity);
$datas = [];
} else {
throw new \Exception("Not implemented", 1);
}
if ($template->getContext() == HouseholdMemberSelectionContext::class) {
$context = new HouseholdMemberSelectionContext();
// $datas = $context->getData($entity);
$datas = [];
} else {
throw new \Exception("Not implemented", 1);
}
$templateProcessor = new TemplateProcessor($tmpfname);
$templateProcessor->setValues(array('firstname' => 'John', 'lastname' => 'Doe'));
$templateProcessor = new TemplateProcessor($tmpfname);
$templateProcessor->setValues(array('firstname' => 'John', 'lastname' => 'Doe'));
$tmpfname2 = tempnam(sys_get_temp_dir(), 'DOC_GENERATED');
$templateProcessor->saveAs($tmpfname2);
$tmpfname2 = tempnam(sys_get_temp_dir(), 'DOC_GENERATED');
$templateProcessor->saveAs($tmpfname2);
unlink($tmpfname);
unlink($tmpfname);
$fileContent = fopen($tmpfname2, 'r'); // the generated file content
$fileContent = fopen($tmpfname2, 'r'); // the generated file content
$genDocName = 'doc_'.sprintf( '%010d', rand()).'.docx';
$genDocName = 'doc_'.sprintf( '%010d', rand()).'.docx';
$getUrlGen = $tempUrlGenerator->generate(
'PUT',
$genDocName);
$getUrlGen = $tempUrlGenerator->generate(
'PUT',
$genDocName);
unlink($tmpfname2);
unlink($tmpfname2);
$client = new Client();
$client = new Client();
$putResponse = $client->request('PUT', $getUrlGen->{'url'}, [
'body' => $fileContent
]);
if ($putResponse->getStatusCode() == 201) {
return new JsonResponse(
array(
"msg" => "Document créé",
"id" => $genDocName,
"response" => array(
"reasonPhrase" => $putResponse->getReasonPhrase(),
"statusCode" => $putResponse->getStatusCode())));
}
$putResponse = $client->request('PUT', $getUrlGen->{'url'}, [
'body' => $fileContent
]);
if ($putResponse->getStatusCode() == 201) {
return new JsonResponse(
array(
"msg" => "PBM",
"msg" => "Document créé",
"id" => $genDocName,
"response" => array(
"reasonPhrase" => $putResponse->getReasonPhrase(),
"statusCode" => $putResponse->getStatusCode())));
}
return new JsonResponse(
array(
"msg" => "PBM",
"response" => array(
"reasonPhrase" => $putResponse->getReasonPhrase(),
"statusCode" => $putResponse->getStatusCode())));
}
}