mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,54 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Controller;
|
||||
|
||||
use ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface;
|
||||
use Chill\DocGeneratorBundle\Context\HouseholdMemberSelectionContext;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
|
||||
use GuzzleHttp\Exception\TransferException;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\HeaderUtils;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlOpenstackGenerator;
|
||||
use PhpOffice\PhpWord\TemplateProcessor;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\TransferException;
|
||||
use PhpOffice\PhpWord\TemplateProcessor;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
// TODO à mettre dans services
|
||||
use Chill\DocGeneratorBundle\Context\HouseholdMemberSelectionContext;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class DocGeneratorTemplateController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/doc/gen/templates/for/{entityClassName}",
|
||||
* name="chill_docgenerator_templates_for_entity_api"
|
||||
* )
|
||||
*/
|
||||
public function listTemplateApiAction(
|
||||
string $entityClassName, DocGeneratorTemplateRepository $templateRepository): Response
|
||||
{
|
||||
$entities = $templateRepository->findByEntity($entityClassName);
|
||||
|
||||
$ret = [];
|
||||
|
||||
foreach ($entities as $entity) {
|
||||
$ret[] = [
|
||||
'id' => $entity->getId(),
|
||||
'name' => $entity->getName(),
|
||||
'description' => $entity->getDescription()
|
||||
];
|
||||
}
|
||||
|
||||
return new JsonResponse(['results' => $ret]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/doc/gen/generate/from/{template}/for/{entityClassName}/{entityId}",
|
||||
@@ -64,7 +46,8 @@ class DocGeneratorTemplateController extends AbstractController
|
||||
): Response {
|
||||
$getUrlGen = $tempUrlGenerator->generate(
|
||||
'GET',
|
||||
$template->getFile());
|
||||
$template->getFile()
|
||||
);
|
||||
|
||||
$tmpfname = tempnam(sys_get_temp_dir(), 'DOC_TEMPLATE');
|
||||
file_put_contents($tmpfname, file_get_contents($getUrlGen->url));
|
||||
@@ -75,7 +58,7 @@ class DocGeneratorTemplateController extends AbstractController
|
||||
$context = new HouseholdMemberSelectionContext();
|
||||
$datas = $context->getData($entity);
|
||||
} else {
|
||||
throw new \Exception('Not implemented', 1);
|
||||
throw new Exception('Not implemented', 1);
|
||||
}
|
||||
|
||||
$templateProcessor = new TemplateProcessor($tmpfname);
|
||||
@@ -99,7 +82,8 @@ class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
$getUrlGen = $tempUrlGenerator->generate(
|
||||
'PUT',
|
||||
$genDocName);
|
||||
$genDocName
|
||||
);
|
||||
|
||||
unlink($tmpfname2);
|
||||
|
||||
@@ -107,7 +91,7 @@ class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
try {
|
||||
$putResponse = $client->request('PUT', $getUrlGen->url, [
|
||||
'body' => $fileContent
|
||||
'body' => $fileContent,
|
||||
]);
|
||||
|
||||
if ($putResponse->getStatusCode() == 201) {
|
||||
@@ -125,8 +109,7 @@ class DocGeneratorTemplateController extends AbstractController
|
||||
$doc = new AccompanyingPeriodWorkEvaluationDocument();
|
||||
$doc
|
||||
->setStoredObject($storedObject)
|
||||
->setTemplate($template)
|
||||
;
|
||||
->setTemplate($template);
|
||||
$entity->addDocument($doc);
|
||||
$em->persist($doc);
|
||||
}
|
||||
@@ -135,13 +118,39 @@ class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
return $this->redirectToRoute('chill_wopi_file_edit', [
|
||||
'fileId' => $storedObject->getUuid(),
|
||||
'returnPath' => $request->query->get('returnPath', "/")
|
||||
'returnPath' => $request->query->get('returnPath', '/'),
|
||||
]);
|
||||
}
|
||||
} catch (TransferException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
throw new \Exception('Unable to generate document.');
|
||||
throw new Exception('Unable to generate document.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/doc/gen/templates/for/{entityClassName}",
|
||||
* name="chill_docgenerator_templates_for_entity_api"
|
||||
* )
|
||||
*/
|
||||
public function listTemplateApiAction(
|
||||
string $entityClassName,
|
||||
DocGeneratorTemplateRepository $templateRepository
|
||||
): Response
|
||||
{
|
||||
$entities = $templateRepository->findByEntity($entityClassName);
|
||||
|
||||
$ret = [];
|
||||
|
||||
foreach ($entities as $entity) {
|
||||
$ret[] = [
|
||||
'id' => $entity->getId(),
|
||||
'name' => $entity->getName(),
|
||||
'description' => $entity->getDescription(),
|
||||
];
|
||||
}
|
||||
|
||||
return new JsonResponse(['results' => $ret]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user