mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
list referral for an accompanying period
This commit is contained in:
parent
94c91d5825
commit
c8762d2bc2
@ -48,6 +48,24 @@ final class UserRepository implements ObjectRepository
|
|||||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function countBy(array $criteria): int
|
||||||
|
{
|
||||||
|
return $this->repository->count($criteria);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function countByActive(): int
|
||||||
|
{
|
||||||
|
return $this->countBy(['enabled' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return User[]|array
|
||||||
|
*/
|
||||||
|
public function findByActive(array $orderBy = null, int $limit = null, int $offset = null): array
|
||||||
|
{
|
||||||
|
return $this->findBy(['enabled' => true], $orderBy, $limit, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
public function getClassName() {
|
public function getClassName() {
|
||||||
return User::class;
|
return User::class;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\AccompanyingPeriod\Suggestion;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Repository\UserRepository;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
|
||||||
|
final class ReferralAvailable implements ReferralAvailableInterface
|
||||||
|
{
|
||||||
|
protected UserRepository $userRepository;
|
||||||
|
|
||||||
|
public function __construct(UserRepository $userRepository)
|
||||||
|
{
|
||||||
|
$this->userRepository = $userRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function countReferralAvailable(AccompanyingPeriod $period, ?array $options = []): int
|
||||||
|
{
|
||||||
|
return $this->userRepository->countByActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param AccompanyingPeriod $period
|
||||||
|
* @return array|User[]
|
||||||
|
*/
|
||||||
|
public function findReferralAvailable(AccompanyingPeriod $period, int $limit = 50, int $start = 0): array
|
||||||
|
{
|
||||||
|
return $this->userRepository->findByActive();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\AccompanyingPeriod\Suggestion;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the suggestion of referral for a given accompanying period
|
||||||
|
*/
|
||||||
|
interface ReferralAvailableInterface
|
||||||
|
{
|
||||||
|
public function countReferralAvailable(AccompanyingPeriod $period, ?array $options = []): int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array|User[]
|
||||||
|
*/
|
||||||
|
public function findReferralAvailable(AccompanyingPeriod $period, int $limit = 50, int $start = 0): array;
|
||||||
|
|
||||||
|
}
|
@ -3,12 +3,18 @@
|
|||||||
namespace Chill\PersonBundle\Controller;
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
|
use Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralAvailableInterface;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Chill\PersonBundle\Privacy\AccompanyingPeriodPrivacyEvent;
|
use Chill\PersonBundle\Privacy\AccompanyingPeriodPrivacyEvent;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
@ -28,19 +34,23 @@ class AccompanyingCourseApiController extends ApiController
|
|||||||
|
|
||||||
private Registry $registry;
|
private Registry $registry;
|
||||||
|
|
||||||
|
private ReferralAvailableInterface $referralAvailable;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
EventDispatcherInterface $eventDispatcher,
|
EventDispatcherInterface $eventDispatcher,
|
||||||
ValidatorInterface $validator,
|
ValidatorInterface $validator,
|
||||||
Registry $registry
|
Registry $registry,
|
||||||
|
ReferralAvailableInterface $referralAvailable
|
||||||
) {
|
) {
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
$this->registry = $registry;
|
$this->registry = $registry;
|
||||||
|
$this->referralAvailable = $referralAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function confirmApi($id, Request $request, $_format): Response
|
public function confirmApi($id, Request $request, $_format): Response
|
||||||
{
|
{
|
||||||
/** @var AccompanyingPeriod $accompanyingPeriod */
|
/** @var AccompanyingPeriod $accompanyingPeriod */
|
||||||
$accompanyingPeriod = $this->getEntity('participation', $id, $request);
|
$accompanyingPeriod = $this->getEntity('participation', $id, $request);
|
||||||
|
|
||||||
$this->checkACL('confirm', $request, $_format, $accompanyingPeriod);
|
$this->checkACL('confirm', $request, $_format, $accompanyingPeriod);
|
||||||
@ -58,10 +68,10 @@ $workflow = $this->registry->get($accompanyingPeriod);
|
|||||||
'groups' => [ 'read' ]
|
'groups' => [ 'read' ]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function participationApi($id, Request $request, $_format)
|
public function participationApi($id, Request $request, $_format)
|
||||||
{
|
{
|
||||||
/** @var AccompanyingPeriod $accompanyingPeriod */
|
/** @var AccompanyingPeriod $accompanyingPeriod */
|
||||||
$accompanyingPeriod = $this->getEntity('participation', $id, $request);
|
$accompanyingPeriod = $this->getEntity('participation', $id, $request);
|
||||||
$person = $this->getSerializer()
|
$person = $this->getSerializer()
|
||||||
->deserialize($request->getContent(), Person::class, $_format, []);
|
->deserialize($request->getContent(), Person::class, $_format, []);
|
||||||
@ -152,7 +162,7 @@ $workflow = $this->registry->get($accompanyingPeriod);
|
|||||||
->deserialize($request->getContent(), $class, $_format, []);
|
->deserialize($request->getContent(), $class, $_format, []);
|
||||||
} catch (RuntimeException $e) {
|
} catch (RuntimeException $e) {
|
||||||
$exceptions[] = $e;
|
$exceptions[] = $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($requestor === null) {
|
if ($requestor === null) {
|
||||||
throw new BadRequestException('Could not find any person or requestor', 0, $exceptions[0]);
|
throw new BadRequestException('Could not find any person or requestor', 0, $exceptions[0]);
|
||||||
@ -187,4 +197,24 @@ $workflow = $this->registry->get($accompanyingPeriod);
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/api/1.0/person/accompanying-course/{id}/referral-availables.{_format}",
|
||||||
|
* requirements={ "_format"="json"},
|
||||||
|
* name="chill_api_person_accompanying_period_referral_available")
|
||||||
|
* @param AccompanyingPeriod $period
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function userReferral(AccompanyingPeriod $period, string $_format = 'json'): JsonResponse
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $period);
|
||||||
|
|
||||||
|
$total = $this->referralAvailable->countReferralAvailable($period);
|
||||||
|
$paginator = $this->getPaginatorFactory()->create($total);
|
||||||
|
$users = $this->referralAvailable->findReferralAvailable($period, $paginator->getItemsPerPage(),
|
||||||
|
$paginator->getCurrentPageFirstItemNumber());
|
||||||
|
|
||||||
|
return $this->json(new Collection($users, $paginator), Response::HTTP_OK,
|
||||||
|
[], [ AbstractNormalizer::GROUPS => [ 'read' ]]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,6 +325,19 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
|||||||
$this->period = $period;
|
$this->period = $period;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataGenerateRandomAccompanyingCourse
|
||||||
|
*/
|
||||||
|
public function testReferralAvailable(int $personId, int $periodId)
|
||||||
|
{
|
||||||
|
$this->client->request(
|
||||||
|
Request::METHOD_POST,
|
||||||
|
sprintf('/api/1.0/person/accompanying-course/%d/referral-availables.json', $periodId)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @dataProvider dataGenerateRandomAccompanyingCourse
|
* @dataProvider dataGenerateRandomAccompanyingCourse
|
||||||
|
@ -445,7 +445,7 @@ paths:
|
|||||||
/1.0/person/accompanying-course/{id}.json:
|
/1.0/person/accompanying-course/{id}.json:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Return the description for an accompanying course (accompanying period)"
|
summary: "Return the description for an accompanying course (accompanying period)"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -532,7 +532,7 @@ paths:
|
|||||||
/1.0/person/accompanying-course/{id}/requestor.json:
|
/1.0/person/accompanying-course/{id}/requestor.json:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Add a requestor to the accompanying course"
|
summary: "Add a requestor to the accompanying course"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -574,7 +574,7 @@ paths:
|
|||||||
description: "object with validation errors"
|
description: "object with validation errors"
|
||||||
delete:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Remove the requestor for the accompanying course"
|
summary: "Remove the requestor for the accompanying course"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -598,7 +598,7 @@ paths:
|
|||||||
/1.0/person/accompanying-course/{id}/participation.json:
|
/1.0/person/accompanying-course/{id}/participation.json:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Add a participant to the accompanying course"
|
summary: "Add a participant to the accompanying course"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -627,7 +627,7 @@ paths:
|
|||||||
description: "object with validation errors"
|
description: "object with validation errors"
|
||||||
delete:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Remove the participant for the accompanying course"
|
summary: "Remove the participant for the accompanying course"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -658,7 +658,7 @@ paths:
|
|||||||
/1.0/person/accompanying-course/{id}/resource.json:
|
/1.0/person/accompanying-course/{id}/resource.json:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Add a resource to the accompanying course"
|
summary: "Add a resource to the accompanying course"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -703,7 +703,7 @@ paths:
|
|||||||
description: "object with validation errors"
|
description: "object with validation errors"
|
||||||
delete:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Remove the resource"
|
summary: "Remove the resource"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -734,7 +734,7 @@ paths:
|
|||||||
/1.0/person/accompanying-course/{id}/comment.json:
|
/1.0/person/accompanying-course/{id}/comment.json:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Add a comment to the accompanying course"
|
summary: "Add a comment to the accompanying course"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -772,7 +772,7 @@ paths:
|
|||||||
description: "object with validation errors"
|
description: "object with validation errors"
|
||||||
delete:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Remove the comment"
|
summary: "Remove the comment"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -803,7 +803,7 @@ paths:
|
|||||||
/1.0/person/accompanying-course/{id}/scope.json:
|
/1.0/person/accompanying-course/{id}/scope.json:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Add a scope to the accompanying course"
|
summary: "Add a scope to the accompanying course"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -837,7 +837,7 @@ paths:
|
|||||||
description: "object with validation errors"
|
description: "object with validation errors"
|
||||||
delete:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Remove the scope"
|
summary: "Remove the scope"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -868,7 +868,7 @@ paths:
|
|||||||
/1.0/person/accompanying-course/{id}/socialissue.json:
|
/1.0/person/accompanying-course/{id}/socialissue.json:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Add a social issue to the accompanying course"
|
summary: "Add a social issue to the accompanying course"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -902,7 +902,7 @@ paths:
|
|||||||
description: "object with validation errors"
|
description: "object with validation errors"
|
||||||
delete:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- person
|
- accompanying-course
|
||||||
summary: "Remove the social issue"
|
summary: "Remove the social issue"
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
@ -929,11 +929,31 @@ paths:
|
|||||||
description: "OK"
|
description: "OK"
|
||||||
422:
|
422:
|
||||||
description: "object with validation errors"
|
description: "object with validation errors"
|
||||||
|
/1.0/person/accompanying-course/{id}/referral-availables.json:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- accompanying-course
|
||||||
|
summary: "get a list of available referral for a given accompanying cours"
|
||||||
|
parameters:
|
||||||
|
- name: id
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: The accompanying period's id
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: integer
|
||||||
|
minimum: 1
|
||||||
|
responses:
|
||||||
|
401:
|
||||||
|
description: "Unauthorized"
|
||||||
|
404:
|
||||||
|
description: "Not found"
|
||||||
|
200:
|
||||||
|
description: "OK"
|
||||||
|
|
||||||
/1.0/person/accompanying-course/{id}/work.json:
|
/1.0/person/accompanying-course/{id}/work.json:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- person
|
|
||||||
- accompanying-course-work
|
- accompanying-course-work
|
||||||
summary: "Add a work (AccompanyingPeriodwork) to the accompanying course"
|
summary: "Add a work (AccompanyingPeriodwork) to the accompanying course"
|
||||||
parameters:
|
parameters:
|
||||||
|
@ -16,5 +16,5 @@ module.exports = function(encore, entries)
|
|||||||
encore.addEntry('page_household_edit_metadata', __dirname + '/Resources/public/page/household_edit_metadata/index.js');
|
encore.addEntry('page_household_edit_metadata', __dirname + '/Resources/public/page/household_edit_metadata/index.js');
|
||||||
encore.addEntry('page_person', __dirname + '/Resources/public/page/person/index.js');
|
encore.addEntry('page_person', __dirname + '/Resources/public/page/person/index.js');
|
||||||
encore.addEntry('page_accompanying_course_index_person_locate', __dirname + '/Resources/public/page/accompanying_course_index/person_locate.js');
|
encore.addEntry('page_accompanying_course_index_person_locate', __dirname + '/Resources/public/page/accompanying_course_index/person_locate.js');
|
||||||
encore.addEntry('page_vis', __dirname + '/Resources/public/page/vis/index.js');
|
//encore.addEntry('page_vis', __dirname + '/Resources/public/page/vis/index.js');
|
||||||
};
|
};
|
||||||
|
@ -13,3 +13,10 @@ services:
|
|||||||
entity: 'Chill\PersonBundle\Entity\AccompanyingPeriod'
|
entity: 'Chill\PersonBundle\Entity\AccompanyingPeriod'
|
||||||
lazy: true
|
lazy: true
|
||||||
method: preUpdateAccompanyingPeriod
|
method: preUpdateAccompanyingPeriod
|
||||||
|
|
||||||
|
Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralAvailable:
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
|
||||||
|
Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralAvailableInterface: '@Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralAvailable'
|
||||||
|
|
||||||
|
@ -41,10 +41,8 @@ services:
|
|||||||
tags: ['controller.service_arguments']
|
tags: ['controller.service_arguments']
|
||||||
|
|
||||||
Chill\PersonBundle\Controller\AccompanyingCourseApiController:
|
Chill\PersonBundle\Controller\AccompanyingCourseApiController:
|
||||||
arguments:
|
autoconfigure: true
|
||||||
$eventDispatcher: '@Symfony\Contracts\EventDispatcher\EventDispatcherInterface'
|
autowire: true
|
||||||
$validator: '@Symfony\Component\Validator\Validator\ValidatorInterface'
|
|
||||||
$registry: '@Symfony\Component\Workflow\Registry'
|
|
||||||
tags: ['controller.service_arguments']
|
tags: ['controller.service_arguments']
|
||||||
|
|
||||||
Chill\PersonBundle\Controller\PersonApiController:
|
Chill\PersonBundle\Controller\PersonApiController:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user