mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
Merge remote-tracking branch 'origin/master' into homepage/rewrite
This commit is contained in:
@@ -81,7 +81,7 @@ class AccompanyingPeriodWorkEvaluationApiController
|
||||
$paginator->setItemsPerPage(count($evaluations));
|
||||
|
||||
return new JsonResponse($this->serializer->serialize(
|
||||
new Collection($evaluations, $paginator),
|
||||
new Collection(array_values($evaluations), $paginator),
|
||||
'json',
|
||||
[
|
||||
AbstractNormalizer::GROUPS => ['read'],
|
||||
|
@@ -0,0 +1,176 @@
|
||||
<?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\Person\PersonResource;
|
||||
use Chill\PersonBundle\Form\PersonResourceType;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\PersonBundle\Repository\PersonResourceRepository;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
final class PersonResourceController extends AbstractController
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private PersonRepository $personRepository;
|
||||
|
||||
private PersonResourceRepository $personResourceRepository;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
PersonResourceRepository $personResourceRepository,
|
||||
PersonRepository $personRepository,
|
||||
EntityManagerInterface $em,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->personResourceRepository = $personResourceRepository;
|
||||
$this->personRepository = $personRepository;
|
||||
$this->em = $em;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function deleteAction(Request $request, $person_id, $resource_id): Response
|
||||
{
|
||||
$personOwner = $this->personRepository->find($person_id);
|
||||
$resource = $this->personResourceRepository->find($resource_id);
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $personOwner);
|
||||
|
||||
if (null === $resource) {
|
||||
throw $this->createNotFoundException('Unable to find Resource entity.');
|
||||
}
|
||||
|
||||
$form = $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('chill_person_resource_delete', [
|
||||
'resource_id' => $resource_id,
|
||||
'person_id' => $person_id,
|
||||
]))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, ['label' => 'Delete'])
|
||||
->getForm();
|
||||
|
||||
if ($request->getMethod() === Request::METHOD_DELETE) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$this->em->remove($resource);
|
||||
$this->em->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator
|
||||
->trans('The resource has been successfully removed.'));
|
||||
|
||||
return $this->redirectToRoute('chill_person_resource_list', [
|
||||
'person_id' => $personOwner->getId(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'ChillPersonBundle:PersonResource:delete.html.twig',
|
||||
[
|
||||
'person' => $personOwner,
|
||||
'resource' => $resource,
|
||||
'form' => $form->createView(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function editAction(Request $request, $resource_id, $person_id): Response
|
||||
{
|
||||
$resource = $this->personResourceRepository->find($resource_id);
|
||||
$personOwner = $this->personRepository->find($person_id);
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $personOwner);
|
||||
|
||||
if (null === $resource) {
|
||||
throw $this->createNotFoundException('Unable to find Resource entity.');
|
||||
}
|
||||
|
||||
$form = $this->createForm(PersonResourceType::class, $resource);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->em->persist($resource);
|
||||
$this->em->flush();
|
||||
|
||||
return $this->redirectToRoute('chill_person_resource_list', [
|
||||
'person_id' => $personOwner->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'ChillPersonBundle:PersonResource:edit.html.twig',
|
||||
[
|
||||
'person' => $personOwner,
|
||||
'resource' => $resource,
|
||||
'form' => $form->createView(),
|
||||
'action' => 'edit',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function listAction(Request $request, $person_id)
|
||||
{
|
||||
$personOwner = $this->personRepository->find($person_id);
|
||||
$this->denyAccessUnlessGranted(PersonVoter::SEE, $personOwner);
|
||||
|
||||
$personResources = [];
|
||||
$personResources = $this->personResourceRepository->findBy(['personOwner' => $personOwner->getId()]);
|
||||
|
||||
$form = $this->createForm(PersonResourceType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->denyAccessUnlessGranted(PersonVoter::CREATE, $personOwner);
|
||||
|
||||
$personResource = new PersonResource();
|
||||
|
||||
$person = $form['person']->getData();
|
||||
$thirdparty = $form['thirdparty']->getData();
|
||||
$freetext = $form['freetext']->getData();
|
||||
$comment = $form['comment']->getData();
|
||||
$kind = $form['kind']->getData();
|
||||
|
||||
$personResource->setKind($kind);
|
||||
$personResource->setPerson($person);
|
||||
$personResource->setThirdParty($thirdparty);
|
||||
$personResource->setFreeText($freetext);
|
||||
$personResource->setComment($comment);
|
||||
|
||||
$personResource->setPersonOwner($personOwner);
|
||||
|
||||
$this->em->persist($personResource);
|
||||
$this->em->flush();
|
||||
|
||||
return $this->redirectToRoute('chill_person_resource_list', [
|
||||
'person_id' => $personOwner->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'ChillPersonBundle:PersonResource:list.html.twig',
|
||||
[
|
||||
'person' => $personOwner,
|
||||
'personResources' => $personResources,
|
||||
'form' => $form->createView(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,161 @@
|
||||
<?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\MainBundle\Entity\ResidentialAddress;
|
||||
use Chill\MainBundle\Form\Type\ResidentialAddressType;
|
||||
use Chill\MainBundle\Repository\ResidentialAddressRepository;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
final class ResidentialAddressController extends AbstractController
|
||||
{
|
||||
private UrlGeneratorInterface $generator;
|
||||
|
||||
private ResidentialAddressRepository $residentialAddressRepository;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
UrlGeneratorInterface $generator,
|
||||
TranslatorInterface $translator,
|
||||
ResidentialAddressRepository $residentialAddressRepository
|
||||
) {
|
||||
$this->generator = $generator;
|
||||
$this->translator = $translator;
|
||||
$this->residentialAddressRepository = $residentialAddressRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/person/residential-address/{id}/delete", name="chill_person_residential_address_delete")
|
||||
*/
|
||||
public function deleteAction(Request $request, ResidentialAddress $residentialAddress): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $residentialAddress->getPerson());
|
||||
|
||||
$form = $this->createForm(FormType::class);
|
||||
$form->add('submit', SubmitType::class, ['label' => 'Delete']);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove($residentialAddress);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans('Residential address had been deleted'));
|
||||
|
||||
return $this->redirectToRoute('chill_person_residential_address_list', ['id' => $residentialAddress->getPerson()->getId()]);
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/ResidentialAddress/delete.html.twig', [
|
||||
'person' => $residentialAddress->getPerson(),
|
||||
'residentialAddress' => $residentialAddress,
|
||||
'delete_form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/person/residential-address/{id}/edit", name="chill_person_residential_address_edit")
|
||||
*/
|
||||
public function editAction(Request $request, ResidentialAddress $residentialAddress): Response
|
||||
{
|
||||
if ($request->query->has('kind')) {
|
||||
$kind = $request->query->getAlpha('kind', '');
|
||||
} else {
|
||||
$kind = null;
|
||||
}
|
||||
|
||||
$person = $residentialAddress->getPerson();
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person);
|
||||
|
||||
$form = $this->createForm(ResidentialAddressType::class, $residentialAddress, ['kind' => $kind]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator
|
||||
->trans('The residential address was updated successfully'));
|
||||
|
||||
return $this->redirect(
|
||||
$request->get('returnPath', null) ??
|
||||
$this->generator->generate('chill_person_residential_address_list', ['id' => $person->getId()])
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/ResidentialAddress/edit.html.twig', [
|
||||
'residentialAddress' => $residentialAddress,
|
||||
'person' => $person,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/person/{id}/residential-address/list", name="chill_person_residential_address_list")
|
||||
*/
|
||||
public function listAction(Request $request, Person $person): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person);
|
||||
|
||||
$residentialAddresses = $this->residentialAddressRepository->findBy(['person' => $person], ['startDate' => 'DESC']);
|
||||
|
||||
return $this->render('@ChillPerson/ResidentialAddress/list.html.twig', [
|
||||
'person' => $person,
|
||||
'addresses' => $residentialAddresses,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/person/{id}/residential-address/new", name="chill_person_residential_address_new")
|
||||
*/
|
||||
public function newAction(Request $request, Person $person): Response
|
||||
{
|
||||
$residentialAddress = new ResidentialAddress();
|
||||
$residentialAddress->setPerson($person);
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person);
|
||||
|
||||
if (!$request->query->has('kind')) {
|
||||
return $this->render('@ChillPerson/ResidentialAddress/new_pick_kind.html.twig', ['person' => $person]);
|
||||
}
|
||||
$kind = $request->query->getAlpha('kind', '');
|
||||
|
||||
$form = $this->createForm(ResidentialAddressType::class, $residentialAddress, ['kind' => $kind]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->getDoctrine()->getManager()->persist($residentialAddress);
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator
|
||||
->trans('The new residential address was created successfully'));
|
||||
|
||||
return $this->redirect(
|
||||
$request->get('returnPath', null) ??
|
||||
$this->generator->generate('chill_person_residential_address_list', ['id' => $residentialAddress->getPerson()->getId()])
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/ResidentialAddress/new.html.twig', [
|
||||
'person' => $person,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user