mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
various improvements
This commit is contained in:
@@ -15,7 +15,6 @@ 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;
|
||||
@@ -23,15 +22,17 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use function count;
|
||||
use function in_array;
|
||||
|
||||
class AccompanyingPeriodWorkEvaluationApiController
|
||||
{
|
||||
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
private PaginatorFactory $paginatorFactory;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
public function __construct(
|
||||
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
|
||||
SerializerInterface $serializer,
|
||||
@@ -44,21 +45,22 @@ class AccompanyingPeriodWorkEvaluationApiController
|
||||
|
||||
/**
|
||||
* @Route("/api/1.0/person/docgen/template/by-evaluation/{id}.{_format}",
|
||||
* requirements={"format": "json"})
|
||||
* requirements={"format": "json"})
|
||||
*/
|
||||
public function listTemplateByEvaluation(Evaluation $evaluation, string $_format): JsonResponse
|
||||
{
|
||||
if ('json' !== $_format) {
|
||||
throw new BadRequestHttpException("format not supported");
|
||||
throw new BadRequestHttpException('format not supported');
|
||||
}
|
||||
|
||||
$evaluations =
|
||||
array_filter(
|
||||
$this->docGeneratorTemplateRepository
|
||||
->findByEntity(AccompanyingPeriodWorkEvaluation::class),
|
||||
function (DocGeneratorTemplate $t) use ($evaluation) {
|
||||
static function (DocGeneratorTemplate $t) use ($evaluation) {
|
||||
$ids = $t->getOptions()['evaluations'] ?? [];
|
||||
return in_array($evaluation->getId(), $ids);
|
||||
|
||||
return in_array($evaluation->getId(), $ids, true);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -66,8 +68,10 @@ class AccompanyingPeriodWorkEvaluationApiController
|
||||
$paginator->setItemsPerPage(count($evaluations));
|
||||
|
||||
return new JsonResponse($this->serializer->serialize(
|
||||
new Collection($evaluations, $paginator), 'json', [
|
||||
AbstractNormalizer::GROUPS => ['read']
|
||||
new Collection($evaluations, $paginator),
|
||||
'json',
|
||||
[
|
||||
AbstractNormalizer::GROUPS => ['read'],
|
||||
]
|
||||
), JsonResponse::HTTP_OK, [], true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user