mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add api for getting goal and results by social action and goal
This commit is contained in:
parent
34d6452286
commit
b53f6af8d8
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class AccompanyingCourseWorkApiController extends ApiController
|
||||
{
|
||||
protected function getContextForSerialization(string $action, Request $request, string $_format, $entity): array
|
||||
{
|
||||
switch($action) {
|
||||
case '_entity':
|
||||
switch ($request->getMethod()) {
|
||||
case Request::METHOD_PUT:
|
||||
return [ 'groups' => [ 'accompanying_period_work:edit' ] ];
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getContextForSerialization($action, $request, $_format, $entity);
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@ -27,7 +28,7 @@ class AccompanyingCourseWorkController extends AbstractController
|
||||
* methods={"GET", "POST"}
|
||||
* )
|
||||
*/
|
||||
public function createWork(AccompanyingPeriod $period)
|
||||
public function createWork(AccompanyingPeriod $period): Response
|
||||
{
|
||||
// TODO ACL
|
||||
|
||||
@ -49,4 +50,10 @@ class AccompanyingCourseWorkController extends AbstractController
|
||||
'json' => $json
|
||||
]);
|
||||
}
|
||||
|
||||
public function editWork(AccompanyingPeriodWork $work): Response
|
||||
{
|
||||
// TODO ACL
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?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" ]]);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||
use Chill\PersonBundle\Repository\SocialWork\ResultRepository;
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SocialWorkResultApiController extends ApiController
|
||||
{
|
||||
private ResultRepository $resultRepository;
|
||||
|
||||
public function __construct(ResultRepository $resultRepository)
|
||||
{
|
||||
$this->resultRepository = $resultRepository;
|
||||
}
|
||||
|
||||
public function listBySocialAction(Request $request, SocialAction $action): Response
|
||||
{
|
||||
$totalItems = $this->resultRepository->countBySocialActionWithDescendants($action);
|
||||
$paginator = $this->getPaginatorFactory()->create($totalItems);
|
||||
|
||||
$entities = $this->resultRepository->findBySocialActionWithDescendants($action, ["id" => "ASC"],
|
||||
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||
|
||||
$model = new Collection($entities, $paginator);
|
||||
|
||||
return $this->json($model, Response::HTTP_OK, [], [ "groups" => [ "read" ]]);
|
||||
}
|
||||
|
||||
public function listByGoal(Request $request, Goal $goal): Response
|
||||
{
|
||||
$totalItems = $this->resultRepository->countByGoal($goal);
|
||||
$paginator = $this->getPaginatorFactory()->create($totalItems);
|
||||
|
||||
$entities = $this->resultRepository->findByGoal($goal, ["id" => "ASC"],
|
||||
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||
|
||||
$model = new Collection($entities, $paginator);
|
||||
|
||||
return $this->json($model, Response::HTTP_OK, [], [ "groups" => [ "read" ]]);
|
||||
}
|
||||
}
|
@ -688,6 +688,48 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'class' => \Chill\PersonBundle\Entity\SocialWork\Goal::class,
|
||||
'controller' => \Chill\PersonBundle\Controller\SocialWorkGoalApiController::class,
|
||||
'name' => 'social_work_goal',
|
||||
'base_path' => '/api/1.0/person/social-work/goal',
|
||||
'base_role' => 'ROLE_USER',
|
||||
'actions' => [
|
||||
'_entity' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
'roles' => [
|
||||
Request::METHOD_GET => 'ROLE_USER',
|
||||
Request::METHOD_HEAD => 'ROLE_USER',
|
||||
]
|
||||
],
|
||||
'_index' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
'roles' => [
|
||||
Request::METHOD_GET => 'ROLE_USER',
|
||||
Request::METHOD_HEAD => 'ROLE_USER',
|
||||
]
|
||||
],
|
||||
'by-social-action' => [
|
||||
'single-collection' => 'collection',
|
||||
'path' => '/by-social-action/{id}.{_format}',
|
||||
'controller_action' => 'listBySocialAction',
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
'roles' => [
|
||||
Request::METHOD_GET => 'ROLE_USER',
|
||||
Request::METHOD_HEAD => 'ROLE_USER',
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
@ -38,13 +38,12 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Serializer\Groups({"read", "accompanying_period_work:edit"})
|
||||
*/
|
||||
private string $note = "";
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class)
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private ?AccompanyingPeriod $accompanyingPeriod = null;
|
||||
|
||||
@ -83,13 +82,16 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable")
|
||||
* @Serializer\Groups({"accompanying_period_work:create"})
|
||||
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private \DateTimeImmutable $startDate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable", nullable=true, options={"default":null})
|
||||
* @Serializer\Groups({"accompanying_period_work:create", "read"})
|
||||
* @Serializer\Groups({"accompanying_period_work:create"})
|
||||
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Assert\GreaterThan(propertyPath="startDate",
|
||||
* message="accompanying_course_work.The endDate should be greater than the start date"
|
||||
* )
|
||||
@ -99,6 +101,8 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=ThirdParty::class)
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Serializer\Groups({"accompanying_period_work:create"})
|
||||
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||
*
|
||||
* In schema : traitant
|
||||
*/
|
||||
@ -115,13 +119,22 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
private string $createdAutomaticallyReason = "";
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity=AccompanyingPeriodWorkGoal::class, mappedBy="accompanyingPeriodWork")
|
||||
* @ORM\OneToMany(
|
||||
* targetEntity=AccompanyingPeriodWorkGoal::class,
|
||||
* mappedBy="accompanyingPeriodWork",
|
||||
* cascade={"persist"},
|
||||
* orphanRemoval=true
|
||||
* )
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||
*/
|
||||
private Collection $goals;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorks")
|
||||
* @ORM\JoinTable(name="chill_person_accompanying_period_work_result")
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||
*/
|
||||
private Collection $results;
|
||||
|
||||
@ -130,6 +143,8 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
* @ORM\JoinTable(name="chill_person_accompanying_period_work_third_party")
|
||||
*
|
||||
* In schema : intervenants
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||
*/
|
||||
private Collection $thirdParties;
|
||||
|
||||
@ -255,7 +270,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
return $this->endDate;
|
||||
}
|
||||
|
||||
public function setEndDate(\DateTimeInterface $endDate): self
|
||||
public function setEndDate(?\DateTimeInterface $endDate = null): self
|
||||
{
|
||||
$this->endDate = $endDate;
|
||||
|
||||
@ -310,7 +325,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
{
|
||||
if (!$this->goals->contains($goal)) {
|
||||
$this->goals[] = $goal;
|
||||
$goal->setAccompanyingPeriodWork2($this);
|
||||
$goal->setAccompanyingPeriodWork($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -318,10 +333,10 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
public function removeGoal(AccompanyingPeriodWorkGoal $goal): self
|
||||
{
|
||||
if ($this->goals->removeElement($goal)) {
|
||||
if ($this->goals->removeElement($goal)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($goal->getAccompanyingPeriodWork2() === $this) {
|
||||
$goal->setAccompanyingPeriodWork2(null);
|
||||
if ($goal->getAccompanyingPeriodWork() === $this) {
|
||||
$goal->setAccompanyingPeriodWork(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,10 +7,17 @@ use Chill\PersonBundle\Entity\SocialWork\Result;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="chill_person_accompanying_period_work_goal")
|
||||
* @Serializer\DiscriminatorMap(
|
||||
* typeProperty="type",
|
||||
* mapping={
|
||||
* "accompanying_period_work_goal":AccompanyingPeriodWorkGoal::class
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class AccompanyingPeriodWorkGoal
|
||||
{
|
||||
@ -18,11 +25,14 @@ class AccompanyingPeriodWorkGoal
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private $note;
|
||||
|
||||
@ -33,12 +43,16 @@ class AccompanyingPeriodWorkGoal
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=Goal::class)
|
||||
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private $goal;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorkGoals")
|
||||
* @ORM\JoinTable(name="chill_person_accompanying_period_work_goal_result")
|
||||
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private $results;
|
||||
|
||||
@ -71,6 +85,13 @@ class AccompanyingPeriodWorkGoal
|
||||
|
||||
public function setAccompanyingPeriodWork(?AccompanyingPeriodWork $accompanyingPeriodWork): self
|
||||
{
|
||||
if ($this->accompanyingPeriodWork instanceof AccompanyingPeriodWork
|
||||
&& $accompanyingPeriodWork !== $this->accompanyingPeriodWork
|
||||
&& $accompanyingPeriodWork !== null
|
||||
) {
|
||||
throw new \LogicException("Change accompanying period work is not allowed");
|
||||
}
|
||||
|
||||
$this->accompanyingPeriodWork = $accompanyingPeriodWork;
|
||||
|
||||
return $this;
|
||||
|
@ -5,10 +5,17 @@ namespace Chill\PersonBundle\Entity\SocialWork;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="chill_person_social_work_goal")
|
||||
* @Serializer\DiscriminatorMap(
|
||||
* typeProperty="type",
|
||||
* mapping={
|
||||
* "social_work_goal":Goal::class
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class Goal
|
||||
{
|
||||
@ -16,11 +23,13 @@ class Goal
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private $title = [];
|
||||
|
||||
@ -46,6 +55,11 @@ class Goal
|
||||
$this->results = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getTitle(): array
|
||||
{
|
||||
return $this->title;
|
||||
|
@ -7,10 +7,17 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="chill_person_social_work_result")
|
||||
* @Serializer\DiscriminatorMap(
|
||||
* typeProperty="type",
|
||||
* mapping={
|
||||
* "social_work_result":Result::class
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class Result
|
||||
{
|
||||
@ -18,11 +25,13 @@ class Result
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private $title = [];
|
||||
|
||||
|
@ -3,10 +3,13 @@
|
||||
namespace Chill\PersonBundle\Repository\SocialWork;
|
||||
|
||||
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
final class GoalRepository
|
||||
final class GoalRepository implements ObjectRepository
|
||||
{
|
||||
private EntityRepository $repository;
|
||||
|
||||
@ -14,4 +17,78 @@ final class GoalRepository
|
||||
{
|
||||
$this->repository = $entityManager->getRepository(Goal::class);
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
{
|
||||
return $this->repository->find($id);
|
||||
}
|
||||
|
||||
public function findAll()
|
||||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria)
|
||||
{
|
||||
return $this->findOneBy($criteria);
|
||||
}
|
||||
|
||||
public function getClassName()
|
||||
{
|
||||
return Goal::class;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Goal[]
|
||||
*/
|
||||
public function findBySocialActionWithDescendants(SocialAction $action, $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
$qb = $this->buildQueryBySocialActionWithDescendants($action);
|
||||
$qb->select('g');
|
||||
|
||||
foreach ($orderBy as $sort => $order) {
|
||||
$qb->addOrderBy('g.'.$sort, $order);
|
||||
}
|
||||
|
||||
return $qb
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function countBySocialActionWithDescendants(SocialAction $action): int
|
||||
{
|
||||
$qb = $this->buildQueryBySocialActionWithDescendants($action);
|
||||
$qb->select('COUNT(g)');
|
||||
|
||||
return $qb
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
|
||||
protected function buildQueryBySocialActionWithDescendants(SocialAction $action): QueryBuilder
|
||||
{
|
||||
$actions = $action->getDescendantsWithThis();
|
||||
|
||||
$qb = $this->repository->createQueryBuilder('g');
|
||||
|
||||
$orx = $qb->expr()->orX();
|
||||
$i = 0;
|
||||
foreach ($actions as $action) {
|
||||
$orx->add(":action_{$i} MEMBER OF g.socialActions");
|
||||
$qb->setParameter("action_{$i}", $action);
|
||||
}
|
||||
$qb->where($orx);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,14 @@
|
||||
namespace Chill\PersonBundle\Repository\SocialWork;
|
||||
|
||||
use Chill\PersonBundle\Entity\SocialWork\Result;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
final class ResultRepository
|
||||
final class ResultRepository implements ObjectRepository
|
||||
{
|
||||
private EntityRepository $repository;
|
||||
|
||||
@ -14,4 +18,120 @@ final class ResultRepository
|
||||
{
|
||||
$this->repository = $entityManager->getRepository(Result::class);
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
{
|
||||
return $this->repository->find($id);
|
||||
}
|
||||
|
||||
public function findAll()
|
||||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria)
|
||||
{
|
||||
return $this->findOneBy($criteria);
|
||||
}
|
||||
|
||||
public function getClassName()
|
||||
{
|
||||
return Result::class;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Result[]
|
||||
*/
|
||||
public function findBySocialActionWithDescendants(SocialAction $action, $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
$qb = $this->buildQueryBySocialActionWithDescendants($action);
|
||||
$qb->select('r');
|
||||
|
||||
foreach ($orderBy as $sort => $order) {
|
||||
$qb->addOrderBy('r.'.$sort, $order);
|
||||
}
|
||||
|
||||
return $qb
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function countBySocialActionWithDescendants(SocialAction $action): int
|
||||
{
|
||||
$qb = $this->buildQueryBySocialActionWithDescendants($action);
|
||||
$qb->select('COUNT(r)');
|
||||
|
||||
return $qb
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
|
||||
protected function buildQueryBySocialActionWithDescendants(SocialAction $action): QueryBuilder
|
||||
{
|
||||
$actions = $action->getDescendantsWithThis();
|
||||
|
||||
$qb = $this->repository->createQueryBuilder('r');
|
||||
|
||||
$orx = $qb->expr()->orX();
|
||||
$i = 0;
|
||||
foreach ($actions as $action) {
|
||||
$orx->add(":action_{$i} MEMBER OF r.socialActions");
|
||||
$qb->setParameter("action_{$i}", $action);
|
||||
}
|
||||
$qb->where($orx);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
protected function buildQueryByGoal(Goal $goal): QueryBuilder
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('r');
|
||||
|
||||
$qb->where(":goal MEMBER OF r.goals")
|
||||
->setParameter('goal', $goal)
|
||||
;
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Result[]
|
||||
*/
|
||||
public function findByGoal(Goal $goal, $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
$qb = $this->buildQueryByGoal($goal);
|
||||
|
||||
foreach ($orderBy as $sort => $order) {
|
||||
$qb->addOrderBy('r.'.$sort, $order);
|
||||
}
|
||||
|
||||
return $qb
|
||||
->select('r')
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function countByGoal(Goal $goal): int
|
||||
{
|
||||
$qb = $this->buildQueryByGoal($goal);
|
||||
$qb->select('COUNT(r)');
|
||||
|
||||
return $qb
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,67 @@ components:
|
||||
type: string
|
||||
enum:
|
||||
- 'household_position'
|
||||
AccompanyingCourseWork:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
type:
|
||||
type: string
|
||||
enum:
|
||||
- 'accompanying_period_work'
|
||||
note:
|
||||
type: string
|
||||
startDate:
|
||||
$ref: "#/components/schemas/Date"
|
||||
endDate:
|
||||
$ref: "#/components/schemas/Date"
|
||||
handlingThirdParty:
|
||||
$ref: "#/components/schemas/ThirdPartyById"
|
||||
goals:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/AccompanyingCourseWorkGoal"
|
||||
results:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/SocialWorkResultById"
|
||||
AccompanyingCourseWorkGoal:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
type:
|
||||
type: string
|
||||
enum:
|
||||
- 'accompanying_period_work_goal'
|
||||
note:
|
||||
type: string
|
||||
goal:
|
||||
$ref: '#/components/schemas/SocialWorkGoalById'
|
||||
results:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/SocialWorkGoalById'
|
||||
|
||||
SocialWorkResultById:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
type:
|
||||
type: string
|
||||
enum:
|
||||
- 'social_work_result'
|
||||
SocialWorkGoalById:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
type:
|
||||
type: string
|
||||
enum:
|
||||
- 'social_work_goal'
|
||||
|
||||
paths:
|
||||
/1.0/person/person/{id}.json:
|
||||
@ -802,6 +862,7 @@ paths:
|
||||
post:
|
||||
tags:
|
||||
- person
|
||||
- accompanying-course-work
|
||||
summary: "Add a work (AccompanyingPeriodwork) to the accompanying course"
|
||||
parameters:
|
||||
- name: id
|
||||
@ -1026,3 +1087,199 @@ paths:
|
||||
description: "Unprocessable entity (validation errors)"
|
||||
400:
|
||||
description: "transition cannot be applyed"
|
||||
|
||||
|
||||
|
||||
/1.0/person/accompanying-course/work/{id}.json:
|
||||
get:
|
||||
tags:
|
||||
- accompanying-course-work
|
||||
summary: edit an existing accompanying course work
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
description: The accompanying course social work's id
|
||||
schema:
|
||||
type: integer
|
||||
format: integer
|
||||
minimum: 1
|
||||
responses:
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
404:
|
||||
description: "Not found"
|
||||
200:
|
||||
description: "OK"
|
||||
400:
|
||||
description: "Bad Request"
|
||||
|
||||
put:
|
||||
tags:
|
||||
- accompanying-course-work
|
||||
summary: edit an existing accompanying course work
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
description: The accompanying course social work's id
|
||||
schema:
|
||||
type: integer
|
||||
format: integer
|
||||
minimum: 1
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/AccompanyingCourseWork'
|
||||
responses:
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
404:
|
||||
description: "Not found"
|
||||
200:
|
||||
description: "OK"
|
||||
422:
|
||||
description: "Unprocessable entity (validation errors)"
|
||||
400:
|
||||
description: "Bad Request"
|
||||
|
||||
/1.0/person/social-work/result.json:
|
||||
get:
|
||||
tags:
|
||||
- accompanying-course-work
|
||||
summary: get a list of social work result
|
||||
responses:
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
200:
|
||||
description: "OK"
|
||||
|
||||
/1.0/person/social-work/result/{id}.json:
|
||||
get:
|
||||
tags:
|
||||
- accompanying-course-work
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
description: The result's id
|
||||
schema:
|
||||
type: integer
|
||||
format: integer
|
||||
minimum: 1
|
||||
responses:
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
404:
|
||||
description: "Not found"
|
||||
200:
|
||||
description: "OK"
|
||||
400:
|
||||
description: "Bad Request"
|
||||
|
||||
|
||||
/1.0/person/social-work/result/by-goal/{id}.json:
|
||||
get:
|
||||
tags:
|
||||
- accompanying-course-work
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
description: The goal's id
|
||||
schema:
|
||||
type: integer
|
||||
format: integer
|
||||
minimum: 1
|
||||
responses:
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
404:
|
||||
description: "Not found"
|
||||
200:
|
||||
description: "OK"
|
||||
400:
|
||||
description: "Bad Request"
|
||||
|
||||
/1.0/person/social-work/result/by-social-action/{id}.json:
|
||||
get:
|
||||
tags:
|
||||
- accompanying-course-work
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
description: The social action's id
|
||||
schema:
|
||||
type: integer
|
||||
format: integer
|
||||
minimum: 1
|
||||
responses:
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
404:
|
||||
description: "Not found"
|
||||
200:
|
||||
description: "OK"
|
||||
400:
|
||||
description: "Bad Request"
|
||||
|
||||
/1.0/person/social-work/goal.json:
|
||||
get:
|
||||
tags:
|
||||
- accompanying-course-work
|
||||
summary: get a list of social work goal
|
||||
responses:
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
200:
|
||||
description: "OK"
|
||||
|
||||
/1.0/person/social-work/goal/{id}.json:
|
||||
get:
|
||||
tags:
|
||||
- accompanying-course-work
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
description: The goal's id
|
||||
schema:
|
||||
type: integer
|
||||
format: integer
|
||||
minimum: 1
|
||||
responses:
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
404:
|
||||
description: "Not found"
|
||||
200:
|
||||
description: "OK"
|
||||
400:
|
||||
description: "Bad Request"
|
||||
|
||||
|
||||
/1.0/person/social-work/goal/by-social-action/{id}.json:
|
||||
get:
|
||||
tags:
|
||||
- accompanying-course-work
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
description: The social action's id
|
||||
schema:
|
||||
type: integer
|
||||
format: integer
|
||||
minimum: 1
|
||||
responses:
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
404:
|
||||
description: "Not found"
|
||||
200:
|
||||
description: "OK"
|
||||
400:
|
||||
description: "Bad Request"
|
||||
|
@ -70,6 +70,7 @@ services:
|
||||
|
||||
Chill\PersonBundle\Controller\:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
resource: '../Controller/'
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
|
@ -60,3 +60,18 @@ services:
|
||||
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
Chill\PersonBundle\Controller\AccompanyingCourseWorkApiController:
|
||||
autowire: true
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
Chill\PersonBundle\Controller\SocialWorkResultApiController:
|
||||
autowire: true
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
Chill\PersonBundle\Controller\SocialWorkGoalApiController:
|
||||
autowire: true
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
Chill\PersonBundle\Controller\HouseholdApiController:
|
||||
autowire: true
|
||||
tags: ['controller.service_arguments']
|
||||
|
Loading…
x
Reference in New Issue
Block a user