mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
docgen: improve listing for templates
This commit is contained in:
@@ -14,6 +14,8 @@ use Chill\DocGeneratorBundle\Context\HouseholdMemberSelectionContext;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
|
||||
@@ -22,15 +24,25 @@ 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 Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
|
||||
class DocGeneratorTemplateController extends AbstractController
|
||||
{
|
||||
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
|
||||
|
||||
private PaginatorFactory $paginatorFactory;
|
||||
|
||||
public function __construct(DocGeneratorTemplateRepository $docGeneratorTemplateRepository, PaginatorFactory $paginatorFactory)
|
||||
{
|
||||
$this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository;
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/doc/gen/generate/from/{template}/for/{entityClassName}/{entityId}",
|
||||
@@ -130,26 +142,25 @@ class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/doc/gen/templates/for/{entityClassName}",
|
||||
* "/api/1.0/docgen/templates/by-entity/{entityClassName}",
|
||||
* name="chill_docgenerator_templates_for_entity_api"
|
||||
* )
|
||||
*/
|
||||
public function listTemplateApiAction(
|
||||
string $entityClassName,
|
||||
DocGeneratorTemplateRepository $templateRepository
|
||||
): Response {
|
||||
$entities = $templateRepository->findByEntity($entityClassName);
|
||||
public function listTemplateApiAction(string $entityClassName): Response
|
||||
{
|
||||
$nb = $this->docGeneratorTemplateRepository->countByEntity($entityClassName);
|
||||
$paginator = $this->paginatorFactory->create($nb);
|
||||
$entities = $this->docGeneratorTemplateRepository->findByEntity(
|
||||
$entityClassName,
|
||||
$paginator->getCurrentPageFirstItemNumber(),
|
||||
$paginator->getItemsPerPage()
|
||||
);
|
||||
|
||||
$ret = [];
|
||||
|
||||
foreach ($entities as $entity) {
|
||||
$ret[] = [
|
||||
'id' => $entity->getId(),
|
||||
'name' => $entity->getName(),
|
||||
'description' => $entity->getDescription(),
|
||||
];
|
||||
}
|
||||
|
||||
return new JsonResponse(['results' => $ret]);
|
||||
return $this->json(
|
||||
new Collection($entities, $paginator),
|
||||
Response::HTTP_OK,
|
||||
[],
|
||||
[AbstractNormalizer::GROUPS => ['read']]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user