mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
list of "my evaluation near end"
This commit is contained in:
parent
1faa9812db
commit
6ab8f95f7d
@ -17,9 +17,14 @@ use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationRepository;
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
@ -28,20 +33,28 @@ use function in_array;
|
||||
|
||||
class AccompanyingPeriodWorkEvaluationApiController
|
||||
{
|
||||
private AccompanyingPeriodWorkEvaluationRepository $accompanyingPeriodWorkEvaluationRepository;
|
||||
|
||||
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
|
||||
|
||||
private PaginatorFactory $paginatorFactory;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(
|
||||
AccompanyingPeriodWorkEvaluationRepository $accompanyingPeriodWorkEvaluationRepository,
|
||||
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
|
||||
SerializerInterface $serializer,
|
||||
PaginatorFactory $paginatorFactory
|
||||
PaginatorFactory $paginatorFactory,
|
||||
Security $security
|
||||
) {
|
||||
$this->accompanyingPeriodWorkEvaluationRepository = $accompanyingPeriodWorkEvaluationRepository;
|
||||
$this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository;
|
||||
$this->serializer = $serializer;
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,4 +89,28 @@ class AccompanyingPeriodWorkEvaluationApiController
|
||||
]
|
||||
), JsonResponse::HTTP_OK, [], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/api/1.0/person/accompanying-period/work/evaluation/my-near-end")
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function myWorksNearEndDate(Request $request): JsonResponse
|
||||
{
|
||||
$total = $this->accompanyingPeriodWorkEvaluationRepository
|
||||
->countNearMaxDateByUser($this->security->getUser());
|
||||
$paginator = $this->paginatorFactory->create($total);
|
||||
$works = $this->accompanyingPeriodWorkEvaluationRepository
|
||||
->findNearMaxDateByUser($this->security->getUser(),
|
||||
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||
|
||||
$collection = new Collection($works, $paginator);
|
||||
|
||||
return new JsonResponse(
|
||||
$this->serializer->serialize($collection, 'json', ['groups' => 'read']),
|
||||
JsonResponse::HTTP_OK,
|
||||
[],
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Repository\AccompanyingPeriod;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class AccompanyingPeriodWorkEvaluationRepository implements ObjectRepository
|
||||
{
|
||||
private EntityRepository $repository;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->repository = $entityManager->getRepository(AccompanyingPeriodWorkEvaluation::class);
|
||||
}
|
||||
|
||||
public function find($id): ?AccompanyingPeriodWorkEvaluation
|
||||
{
|
||||
return $this->repository->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|object[]|AccompanyingPeriodWorkEvaluation[]
|
||||
*/
|
||||
public function findAll(): array
|
||||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $criteria
|
||||
* @param array|null $orderBy
|
||||
* @param int $limit
|
||||
* @param int $offset
|
||||
* @return array|AccompanyingPeriodWorkEvaluation[]|object[]
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria): ?AccompanyingPeriodWorkEvaluation
|
||||
{
|
||||
return $this->repository->findOneBy($criteria);
|
||||
}
|
||||
|
||||
public function getClassName(): string
|
||||
{
|
||||
return AccompanyingPeriodWorkEvaluation::class;
|
||||
}
|
||||
|
||||
public function countNearMaxDateByUser(User $user): int
|
||||
{
|
||||
return $this->buildQueryNearMaxDateByUser($user)
|
||||
->select('count(e)')->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function findNearMaxDateByUser(User $user, int $limit = 20, int $offset = 0): array
|
||||
{
|
||||
return $this->buildQueryNearMaxDateByUser($user)
|
||||
->select('e')
|
||||
->setFirstResult($offset)
|
||||
->setMaxResults($limit)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
private function buildQueryNearMaxDateByUser(User $user): QueryBuilder
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('e');
|
||||
|
||||
$qb
|
||||
->join('e.accompanyingPeriodWork', 'work')
|
||||
->join('work.accompanyingPeriod', 'period')
|
||||
->where(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->eq('period.user', ':user'),
|
||||
$qb->expr()->isNull('e.endDate'),
|
||||
$qb->expr()->gte(':now', $qb->expr()->diff('e.maxDate', 'e.warningInterval'))
|
||||
)
|
||||
)
|
||||
->setParameters([
|
||||
'user' => $user,
|
||||
'now' => new \DateTimeImmutable('now')
|
||||
]);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@ final class AccompanyingPeriodWorkRepository implements ObjectRepository
|
||||
$this->repository = $entityManager->getRepository(AccompanyingPeriodWork::class);
|
||||
}
|
||||
|
||||
public function buildQueryNearEndDateByUser(User $user, DateTimeImmutable $since, DateTimeImmutable $until): QueryBuilder
|
||||
private function buildQueryNearEndDateByUser(User $user, DateTimeImmutable $since, DateTimeImmutable $until): QueryBuilder
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('w');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user