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( public function generateDocFromTemplateAction(
TempUrlOpenstackGenerator $tempUrlGenerator, TempUrlOpenstackGenerator $tempUrlGenerator,
DocGeneratorTemplate $template, string $entityClassName, int $entityId): Response DocGeneratorTemplate $template, string $entityClassName, int $entityId): Response
{ {
$getUrlGen = $tempUrlGenerator->generate( $getUrlGen = $tempUrlGenerator->generate(
'GET', 'GET',
$template->getFile()); $template->getFile());
$tmpfname = tempnam(sys_get_temp_dir(), 'DOC_TEMPLATE'); $tmpfname = tempnam(sys_get_temp_dir(), 'DOC_TEMPLATE');
file_put_contents($tmpfname, file_get_contents($getUrlGen->{"url"})); 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) { if ($template->getContext() == HouseholdMemberSelectionContext::class) {
$context = new HouseholdMemberSelectionContext(); $context = new HouseholdMemberSelectionContext();
// $datas = $context->getData($entity); // $datas = $context->getData($entity);
$datas = []; $datas = [];
} else { } else {
throw new \Exception("Not implemented", 1); throw new \Exception("Not implemented", 1);
} }
$templateProcessor = new TemplateProcessor($tmpfname); $templateProcessor = new TemplateProcessor($tmpfname);
$templateProcessor->setValues(array('firstname' => 'John', 'lastname' => 'Doe')); $templateProcessor->setValues(array('firstname' => 'John', 'lastname' => 'Doe'));
$tmpfname2 = tempnam(sys_get_temp_dir(), 'DOC_GENERATED'); $tmpfname2 = tempnam(sys_get_temp_dir(), 'DOC_GENERATED');
$templateProcessor->saveAs($tmpfname2); $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( $getUrlGen = $tempUrlGenerator->generate(
'PUT', 'PUT',
$genDocName); $genDocName);
unlink($tmpfname2); unlink($tmpfname2);
$client = new Client(); $client = new Client();
$putResponse = $client->request('PUT', $getUrlGen->{'url'}, [ $putResponse = $client->request('PUT', $getUrlGen->{'url'}, [
'body' => $fileContent 'body' => $fileContent
]); ]);
if ($putResponse->getStatusCode() == 201) {
return new JsonResponse(
array(
"msg" => "Document créé",
"id" => $genDocName,
"response" => array(
"reasonPhrase" => $putResponse->getReasonPhrase(),
"statusCode" => $putResponse->getStatusCode())));
}
if ($putResponse->getStatusCode() == 201) {
return new JsonResponse( return new JsonResponse(
array( array(
"msg" => "PBM", "msg" => "Document créé",
"id" => $genDocName,
"response" => array( "response" => array(
"reasonPhrase" => $putResponse->getReasonPhrase(), "reasonPhrase" => $putResponse->getReasonPhrase(),
"statusCode" => $putResponse->getStatusCode()))); "statusCode" => $putResponse->getStatusCode())));
} }
return new JsonResponse(
array(
"msg" => "PBM",
"response" => array(
"reasonPhrase" => $putResponse->getReasonPhrase(),
"statusCode" => $putResponse->getStatusCode())));
}
} }