mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
adapting vuejs form for accompanyingPeriodWork: include template for
specific evaluation
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\MainBundle\Serializer\Normalizer\CollectionNormalizer;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
class AccompanyingPeriodWorkEvaluationApiController
|
||||
{
|
||||
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
private PaginatorFactory $paginatorFactory;
|
||||
|
||||
public function __construct(
|
||||
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
|
||||
SerializerInterface $serializer,
|
||||
PaginatorFactory $paginatorFactory
|
||||
) {
|
||||
$this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository;
|
||||
$this->serializer = $serializer;
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/api/1.0/person/docgen/template/by-evaluation/{id}.{_format}",
|
||||
* requirements={"format": "json"})
|
||||
*/
|
||||
public function listTemplateByEvaluation(Evaluation $evaluation, string $_format): JsonResponse
|
||||
{
|
||||
if ('json' !== $_format) {
|
||||
throw new BadRequestHttpException("format not supported");
|
||||
}
|
||||
|
||||
$evaluations =
|
||||
array_filter(
|
||||
$this->docGeneratorTemplateRepository
|
||||
->findByEntity(AccompanyingPeriodWorkEvaluation::class),
|
||||
function (DocGeneratorTemplate $t) use ($evaluation) {
|
||||
$ids = $t->getOptions()['evaluations'] ?? [];
|
||||
return in_array($evaluation->getId(), $ids);
|
||||
}
|
||||
);
|
||||
|
||||
$paginator = $this->paginatorFactory->create(count($evaluations));
|
||||
$paginator->setItemsPerPage(count($evaluations));
|
||||
|
||||
return new JsonResponse($this->serializer->serialize(
|
||||
new Collection($evaluations, $paginator), 'json', [
|
||||
AbstractNormalizer::GROUPS => ['read']
|
||||
]
|
||||
), JsonResponse::HTTP_OK, [], true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user