mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[person] order social issues: remove custom controller and order only by 'ordering'
This commit is contained in:
parent
bb93cb23a7
commit
ce1d213082
@ -25,7 +25,7 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
use Symfony\Component\Serializer\SerializerInterface;
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
|
|
||||||
//class SocialIssueApiController extends ApiController
|
//class SocialIssueApiController extends ApiController
|
||||||
class SocialIssueApiController extends AbstractController
|
class SocialIssueApiController extends ApiController
|
||||||
{
|
{
|
||||||
|
|
||||||
private SerializerInterface $serializer;
|
private SerializerInterface $serializer;
|
||||||
@ -36,77 +36,22 @@ class SocialIssueApiController extends AbstractController
|
|||||||
$this->serializer = $serializer;
|
$this->serializer = $serializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// protected function customizeQuery(string $action, Request $request, $query): void
|
protected function customizeQuery(string $action, Request $request, $query): void
|
||||||
// {
|
|
||||||
// $query->where(
|
|
||||||
// $query->expr()->orX(
|
|
||||||
// $query->expr()->gt('e.desactivationDate', ':now'),
|
|
||||||
// $query->expr()->isNull('e.desactivationDate')
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// $query->setParameter('now', new DateTimeImmutable());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// protected function getQueryResult(string $action, Request $request, string $_format, int $totalItems, PaginatorInterface $paginator, $query)
|
|
||||||
// {
|
|
||||||
// // In order to work, this hydrator only works with
|
|
||||||
// // entities having the field "children" set up.
|
|
||||||
// return $query
|
|
||||||
// ->getQuery()
|
|
||||||
// ->setHint(Query::HINT_INCLUDE_META_COLUMNS, true)
|
|
||||||
// ->getResult(FlatHierarchyEntityHydrator::LIST);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// protected function onPostIndexBuildQuery(string $action, Request $request, string $_format, int $totalItems, PaginatorInterface $paginator, $query): ?Response
|
|
||||||
// {
|
|
||||||
// $query
|
|
||||||
// ->orderBy('GET_JSON_FIELD_BY_KEY(e.title, :locale)', 'ASC')
|
|
||||||
// ->setParameter(':locale', $request->getLocale());
|
|
||||||
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator, $_format)
|
|
||||||
// {
|
|
||||||
// $query->addOrderBy('ordering', 'ASC');
|
|
||||||
// return $query;
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @Route("/api/1.0/person/social-work/social-issue.json", name="social_work_social_issue")
|
|
||||||
*/
|
|
||||||
public function indexAction(Request $request): JsonResponse
|
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('ROLE_USER');
|
$query->where(
|
||||||
|
$query->expr()->orX(
|
||||||
$qb = $this->getDoctrine()->getManager()->createQueryBuilder();
|
$query->expr()->gt('e.desactivationDate', ':now'),
|
||||||
|
$query->expr()->isNull('e.desactivationDate')
|
||||||
$qb->select('si')->from(SocialIssue::class, 'si');
|
|
||||||
|
|
||||||
$qb->where(
|
|
||||||
$qb->expr()->orX(
|
|
||||||
$qb->expr()->gt('si.desactivationDate', ':now'),
|
|
||||||
$qb->expr()->isNull('si.desactivationDate')
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$qb->setParameter('now', new DateTimeImmutable());
|
$query->setParameter('now', new DateTimeImmutable());
|
||||||
$qb->addOrderBy('si.ordering', 'ASC');
|
|
||||||
|
|
||||||
$qb->getQuery()
|
|
||||||
->setHint(Query::HINT_INCLUDE_META_COLUMNS, true)
|
|
||||||
->getResult(FlatHierarchyEntityHydrator::LIST);
|
|
||||||
|
|
||||||
$qb->addOrderBy('GET_JSON_FIELD_BY_KEY(si.title, :locale)', 'ASC')
|
|
||||||
->setParameter(':locale', $request->getLocale());
|
|
||||||
|
|
||||||
$socialIssues = $qb->getQuery()->getResult();
|
|
||||||
|
|
||||||
return new JsonResponse(
|
|
||||||
$this->serializer->serialize(['count' => count($socialIssues), 'results' => $socialIssues], 'json', ['groups' => ['read']]),
|
|
||||||
JsonResponse::HTTP_OK,
|
|
||||||
[],
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator, $_format)
|
||||||
|
{
|
||||||
|
$query->addOrderBy('ordering', 'ASC');
|
||||||
|
return $query;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -455,27 +455,27 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
// [
|
[
|
||||||
// 'class' => \Chill\PersonBundle\Entity\SocialWork\SocialIssue::class,
|
'class' => \Chill\PersonBundle\Entity\SocialWork\SocialIssue::class,
|
||||||
// 'name' => 'social_work_social_issue',
|
'name' => 'social_work_social_issue',
|
||||||
// 'controller' => \Chill\PersonBundle\Controller\SocialIssueApiController::class,
|
'controller' => \Chill\PersonBundle\Controller\SocialIssueApiController::class,
|
||||||
// 'base_path' => '/api/1.0/person/social-work/social-issue',
|
'base_path' => '/api/1.0/person/social-work/social-issue',
|
||||||
// 'base_role' => 'ROLE_USER',
|
'base_role' => 'ROLE_USER',
|
||||||
// 'actions' => [
|
'actions' => [
|
||||||
// '_index' => [
|
'_index' => [
|
||||||
// 'methods' => [
|
'methods' => [
|
||||||
// Request::METHOD_GET => true,
|
Request::METHOD_GET => true,
|
||||||
// Request::METHOD_HEAD => true,
|
Request::METHOD_HEAD => true,
|
||||||
// ],
|
],
|
||||||
// ],
|
],
|
||||||
// '_entity' => [
|
'_entity' => [
|
||||||
// 'methods' => [
|
'methods' => [
|
||||||
// Request::METHOD_GET => true,
|
Request::METHOD_GET => true,
|
||||||
// Request::METHOD_HEAD => true,
|
Request::METHOD_HEAD => true,
|
||||||
// ],
|
],
|
||||||
// ],
|
],
|
||||||
// ],
|
],
|
||||||
// ],
|
],
|
||||||
[
|
[
|
||||||
'class' => \Chill\PersonBundle\Entity\Person::class,
|
'class' => \Chill\PersonBundle\Entity\Person::class,
|
||||||
'name' => 'person',
|
'name' => 'person',
|
||||||
|
@ -199,7 +199,3 @@ chill_person_social_result_admin:
|
|||||||
chill_person_controllers:
|
chill_person_controllers:
|
||||||
resource: "@ChillPersonBundle/Controller"
|
resource: "@ChillPersonBundle/Controller"
|
||||||
type: annotation
|
type: annotation
|
||||||
|
|
||||||
social_work_social_issue:
|
|
||||||
path: "/api/1.0/person/social-work/social-issue.json"
|
|
||||||
controller: Chill\PersonBundle\Controller\SocialIssueApiController::indexAction
|
|
@ -67,6 +67,3 @@ services:
|
|||||||
autowire: true
|
autowire: true
|
||||||
tags: ['controller.service_arguments']
|
tags: ['controller.service_arguments']
|
||||||
|
|
||||||
Chill\PersonBundle\Controller\SocialIssueApiController:
|
|
||||||
autowire: true
|
|
||||||
autoconfigure: true
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user