Merge remote-tracking branch 'origin/master' into issue230_person

This commit is contained in:
nobohan
2022-01-04 13:50:27 +01:00
611 changed files with 13079 additions and 4316 deletions

View File

@@ -34,8 +34,11 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Exception\RuntimeException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Workflow\Registry;
use function array_values;
use function count;
@@ -294,4 +297,17 @@ final class AccompanyingCourseApiController extends ApiController
return null;
}
protected function validate(string $action, Request $request, string $_format, $entity, array $more = []): ConstraintViolationListInterface
{
if ('work' !== $action) {
return parent::validate($action, $request, $_format, $entity, $more);
}
if (Request::METHOD_POST === $request->getMethod()) {
return $this->getValidator()->validate($more[0], null);
}
return new ConstraintViolationList([]);
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Controller;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Form\AccompanyingCourseCommentType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use function array_key_exists;
class AccompanyingCourseCommentController extends AbstractController
{
/**
* Comments page of Accompanying Course section.
*
* @Route("/{_locale}/parcours/{accompanying_period_id}/comments", name="chill_person_accompanying_period_comment_list")
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
*/
public function commentAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response
{
$newComment = new AccompanyingPeriod\Comment();
$newComment->setAccompanyingPeriod($accompanyingCourse);
$form = $this->createCommentForm($newComment, 'new');
$editForm = null;
if ($request->query->has('edit')) {
foreach ($accompanyingCourse->getComments() as $comment) {
if ($comment->getId() === $request->query->getInt('edit')) {
$editForm = $this->createCommentForm($comment, 'edit');
$commentEditId = $comment->getId();
}
}
$pinnedComment = $accompanyingCourse->getPinnedComment();
if ($pinnedComment->getId() === $request->query->getInt('edit')) {
$editForm = $this->createCommentForm($pinnedComment, 'edit');
$commentEditId = $pinnedComment->getId();
}
}
if (null === $editForm) {
throw new NotFoundHttpException('Unable to find an edit form.');
}
if ($request->getMethod() === Request::METHOD_POST) {
$currentForm = $editForm->handleRequest($request);
if (array_key_exists('edit', $request->request->all()[$editForm->getName()])) {
$isEditingNew = false;
} else {
$isEditingNew = true;
}
if ($currentForm->isSubmitted() && $currentForm->isValid()) {
$em = $this->getDoctrine()->getManager();
if ($isEditingNew) {
$em->persist($newComment);
}
$em->flush();
}
return $this->redirectToRoute('chill_person_accompanying_period_comment_list', [
'accompanying_period_id' => $accompanyingCourse->getId(),
]);
}
return $this->render('@ChillPerson/AccompanyingCourse/comment_list.html.twig', [
'accompanyingCourse' => $accompanyingCourse,
'form' => $form->createView(),
'edit_form' => null !== $editForm ? $editForm->createView() : null,
'commentEditId' => $commentEditId ?? null,
]);
}
private function createCommentForm(AccompanyingPeriod\Comment $comment, string $step): FormInterface
{
$form = $this->createForm(AccompanyingCourseCommentType::class, $comment);
if ('edit' === $step) {
$form->add('edit', HiddenType::class, ['mapped' => false]);
}
return $form;
}
}

View File

@@ -30,6 +30,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Workflow\Registry;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function is_array;
/**

View File

@@ -67,7 +67,7 @@ class AccompanyingCourseWorkController extends AbstractController
'error',
$this->trans->trans(
'accompanying_work.You must add at least ' .
'one social issue on accompanying period'
'one social issue on accompanying period'
)
);

View File

@@ -27,6 +27,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function array_filter;
use function count;
@@ -170,8 +171,10 @@ class AccompanyingPeriodController extends AbstractController
$errors = $this->_validatePerson($person);
$flashBag = $this->get('session')->getFlashBag();
if ($form->isValid(['Default', 'closed'])
&& count($errors) === 0) {
if (
$form->isValid(['Default', 'closed'])
&& count($errors) === 0
) {
$em = $this->getDoctrine()->getManager();
$em->persist($accompanyingPeriod);
$em->flush();
@@ -405,8 +408,10 @@ class AccompanyingPeriodController extends AbstractController
$errors = $this->_validatePerson($person);
$flashBag = $this->get('session')->getFlashBag();
if ($form->isValid(['Default', 'closed'])
&& count($errors) === 0) {
if (
$form->isValid(['Default', 'closed'])
&& count($errors) === 0
) {
$em->flush();
$flashBag->add(

View File

@@ -0,0 +1,79 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Controller;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Serializer\Model\Collection;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
use function count;
use function in_array;
class AccompanyingPeriodWorkEvaluationApiController
{
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
private PaginatorFactory $paginatorFactory;
private SerializerInterface $serializer;
public function __construct(
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
SerializerInterface $serializer,
PaginatorFactory $paginatorFactory
) {
$this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository;
$this->serializer = $serializer;
$this->paginatorFactory = $paginatorFactory;
}
/**
* @Route("/api/1.0/person/docgen/template/by-evaluation/{id}.{_format}",
* requirements={"format": "json"})
*/
public function listTemplateByEvaluation(Evaluation $evaluation, string $_format): JsonResponse
{
if ('json' !== $_format) {
throw new BadRequestHttpException('format not supported');
}
$evaluations =
array_filter(
$this->docGeneratorTemplateRepository
->findByEntity(AccompanyingPeriodWorkEvaluation::class),
static function (DocGeneratorTemplate $t) use ($evaluation) {
$ids = $t->getOptions()['evaluations'] ?? [];
return in_array($evaluation->getId(), $ids, true);
}
);
$paginator = $this->paginatorFactory->create(count($evaluations));
$paginator->setItemsPerPage(count($evaluations));
return new JsonResponse($this->serializer->serialize(
new Collection($evaluations, $paginator),
'json',
[
AbstractNormalizer::GROUPS => ['read'],
]
), JsonResponse::HTTP_OK, [], true);
}
}

View File

@@ -24,6 +24,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use function array_filter;
use function array_values;
@@ -93,8 +94,10 @@ class HouseholdApiController extends ApiController
$addresses[$a->getId()] = $a;
}
if (null !== $personLocation = $participation
->getAccompanyingPeriod()->getPersonLocation()) {
if (
null !== $personLocation = $participation
->getAccompanyingPeriod()->getPersonLocation()
) {
$a = $personLocation->getCurrentHouseholdAddress();
if (null !== $a) {

View File

@@ -25,6 +25,7 @@ use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use function array_key_exists;
use function count;

View File

@@ -27,6 +27,7 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Serializer\Exception;
use Symfony\Component\Translation\TranslatorInterface;
use function count;
class HouseholdMemberController extends ApiController

View File

@@ -18,6 +18,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function count;
/**

View File

@@ -21,7 +21,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Role\Role;
use function array_filter;
use function array_values;
@@ -76,14 +76,6 @@ class PersonApiController extends ApiController
return $this->json(array_values($addresses), Response::HTTP_OK, [], ['groups' => ['read']]);
}
protected function createEntity(string $action, Request $request): object
{
return parent::createEntity($action, $request);
// TODO temporary hack to allow creation of person with fake center
/* $centers = $this->authorizationHelper->getReachableCenters($this->getUser(),
new Role(PersonVoter::CREATE));
$person->setCenter($centers[0]); */
}
/**
* @Route("/api/1.0/person/config/alt_names.{_format}",
@@ -120,17 +112,4 @@ class PersonApiController extends ApiController
return $this->json($configAltNames, Response::HTTP_OK, [], ['groups' => ['read']]);
}
protected function getValidationGroups(string $action, Request $request, string $_format, $entity): ?array
{
if ($action === '_entity'){
if ($request->getMethod() === Request::METHOD_POST){
return ["creation"];
}
if (($request->getMethod() === Request::METHOD_PATCH) || ($request->getMethod() === Request::METHOD_PUT)){
return ["general"];
}
};
return parent::getValidationGroups($action, $request, $_format, $entity);
}
}

View File

@@ -32,6 +32,7 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function count;
use function hash;
use function implode;
@@ -131,6 +132,8 @@ final class PersonController extends AbstractController
->getFlashBag()->add('error', $this->translator
->trans('This form contains errors'));
} elseif ($form->isSubmitted() && $form->isValid()) {
$this->em->flush();
$this->get('session')->getFlashBag()
->add(
'success',
@@ -138,8 +141,6 @@ final class PersonController extends AbstractController
->trans('The person data has been updated')
);
$this->em->flush();
return $this->redirectToRoute('chill_person_view', [
'person_id' => $person->getId(),
]);
@@ -207,8 +208,10 @@ final class PersonController extends AbstractController
{
$person = new Person();
if (1 === count($this->security->getUser()
->getGroupCenters())) {
if (
1 === count($this->security->getUser()
->getGroupCenters())
) {
$person->setCenter(
$this->security->getUser()
->getGroupCenters()[0]
@@ -216,22 +219,21 @@ final class PersonController extends AbstractController
);
}
$form = $this->createForm(CreationPersonType::class, $person, [
'validation_groups' => ['create'],
])->add('editPerson', SubmitType::class, [
'label' => 'Add the person',
])->add('createPeriod', SubmitType::class, [
'label' => 'Add the person and create an accompanying period',
])->add('createHousehold', SubmitType::class, [
'label' => 'Add the person and create an household',
]); // TODO createHousehold form action
$form = $this->createForm(CreationPersonType::class, $person)
->add('editPerson', SubmitType::class, [
'label' => 'Add the person',
])->add('createPeriod', SubmitType::class, [
'label' => 'Add the person and create an accompanying period',
]);
$form->handleRequest($request);
if ($request->getMethod() === Request::METHOD_GET) {
$this->lastPostDataReset();
} elseif ($request->getMethod() === Request::METHOD_POST
&& $form->isValid()) {
} elseif (
$request->getMethod() === Request::METHOD_POST
&& $form->isValid()
) {
$alternatePersons = $this->similarPersonMatcher
->matchPerson($person);

View File

@@ -29,6 +29,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Translation\TranslatorInterface;
use function count;
class PersonDuplicateController extends Controller

View File

@@ -14,10 +14,10 @@ namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Repository\Relationships\RelationshipRepository;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function array_values;
class RelationshipApiController extends ApiController
{
@@ -36,9 +36,10 @@ class RelationshipApiController extends ApiController
*/
public function getRelationshipsByPerson(Person $person)
{
//TODO: add permissions? (voter?)
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person);
$relationships = $this->repository->findByPerson($person);
return $this->json(array_values($relationships), Response::HTTP_OK, [], ['groups' => ['read']]);
return $this->json($relationships, Response::HTTP_OK, [], ['groups' => ['read']]);
}
}

View File

@@ -17,6 +17,7 @@ use Chill\MainBundle\Serializer\Model\Collection;
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use function count;
class SocialWorkSocialActionApiController extends ApiController