mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-18 16:24:24 +00:00
41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Chill\PersonBundle\Controller;
|
|
|
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
|
use Chill\MainBundle\Serializer\Model\Collection;
|
|
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
|
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
|
use Chill\PersonBundle\Repository\SocialWork\GoalRepository;
|
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class SocialWorkGoalApiController extends ApiController
|
|
{
|
|
private GoalRepository $goalRepository;
|
|
|
|
private PaginatorFactory $paginator;
|
|
|
|
|
|
public function __construct(GoalRepository $goalRepository, PaginatorFactory $paginator)
|
|
{
|
|
$this->goalRepository = $goalRepository;
|
|
$this->paginator = $paginator;
|
|
}
|
|
|
|
public function listBySocialAction(Request $request, SocialAction $action): Response
|
|
{
|
|
$totalItems = $this->goalRepository->countBySocialActionWithDescendants($action);
|
|
$paginator = $this->getPaginatorFactory()->create($totalItems);
|
|
|
|
$entities = $this->goalRepository->findBySocialActionWithDescendants($action, ["id" => "ASC"],
|
|
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
|
|
|
$model = new Collection($entities, $paginator);
|
|
|
|
return $this->json($model, Response::HTTP_OK, [], [ "groups" => [ "read" ]]);
|
|
}
|
|
|
|
}
|