make new relation many-to-many between Person and AccompagnyingPeriod

This commit is contained in:
2021-03-26 21:54:58 +01:00
parent 813ecb0201
commit f6801c0c4f
6 changed files with 196 additions and 96 deletions

View File

@@ -3,7 +3,7 @@
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* Copyright (C) 2014-2021, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
@@ -23,6 +23,7 @@
namespace Chill\PersonBundle\Controller;
use Chill\PersonBundle\Privacy\PrivacyEvent;
use Doctrine\DBAL\Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Form\AccompanyingPeriodType;
@@ -56,10 +57,10 @@ class AccompanyingPeriodController extends AbstractController
}
/**
* @param $person_id
* @return Response
*/
public function listAction($person_id){
public function listAction(int $person_id)
{
$person = $this->_getPerson($person_id);
@@ -76,11 +77,9 @@ class AccompanyingPeriodController extends AbstractController
}
/**
* @param $person_id
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function createAction($person_id, Request $request)
public function createAction(int $person_id, Request $request)
{
$person = $this->_getPerson($person_id);
@@ -139,23 +138,24 @@ class AccompanyingPeriodController extends AbstractController
}
/**
* @param $person_id
* @param $period_id
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response|\Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function updateAction($person_id, $period_id, Request $request){
public function updateAction(int $person_id, int $period_id, Request $request){
$em = $this->getDoctrine()->getManager();
$accompanyingPeriod = $em->getRepository('ChillPersonBundle:AccompanyingPeriod')
->find($period_id);
/** @var AccompanyingPeriod $accompanyingPeriod */
$accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($period_id);
if ($accompanyingPeriod === null) {
return $this->createNotFoundException("Period with id ".$period_id.
" is not found");
throw $this->createNotFoundException("Period with id " . $period_id . " is not found");
}
$person = $accompanyingPeriod->getPerson();
/** @var Person $person */
$person = $em->getRepository(Person::class)->find($person_id);
if (! $accompanyingPeriod->containsPerson($person)) {
throw new Exception("Accompanying period " . $period_id . " does not contain person " . $person_id);
}
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
'You are not allowed to update this person');
@@ -203,12 +203,10 @@ class AccompanyingPeriodController extends AbstractController
}
/**
* @param $person_id
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
* @throws \Exception
*/
public function closeAction($person_id, Request $request)
public function closeAction(int $person_id, Request $request)
{
$person = $this->_getPerson($person_id);
@@ -290,7 +288,6 @@ class AccompanyingPeriodController extends AbstractController
}
/**
* @param Person $person
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
*/
private function _validatePerson(Person $person) {
@@ -307,8 +304,6 @@ class AccompanyingPeriodController extends AbstractController
}
/**
* @param $person_id
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function openAction($person_id, Request $request) {
@@ -388,13 +383,11 @@ class AccompanyingPeriodController extends AbstractController
}
/**
* @param $person_id
* @param $period_id
* @param Request $request
* @return object|\Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function reOpenAction($person_id, $period_id, Request $request)
public function reOpenAction(int $person_id, int $period_id, Request $request)
{
/** @var Person $person */
$person = $this->_getPerson($person_id);
$criteria = Criteria::create();
@@ -411,7 +404,7 @@ class AccompanyingPeriodController extends AbstractController
$confirm = $request->query->getBoolean('confirm', false);
if ($confirm === true && $period->canBeReOpened()) {
if ($confirm === true && $period->canBeReOpened($person)) {
$period->reOpen();
$this->_validatePerson($person);
@@ -425,7 +418,7 @@ class AccompanyingPeriodController extends AbstractController
'person_id' => $person->getId()
]);
} elseif ($confirm === false && $period->canBeReOpened()) {
} elseif ($confirm === false && $period->canBeReOpened($person)) {
return $this->render('ChillPersonBundle:AccompanyingPeriod:re_open.html.twig', [
'period' => $period,
'person' => $person
@@ -439,12 +432,10 @@ class AccompanyingPeriodController extends AbstractController
}
/**
*
* @param int $id
* @return Person
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the person is not found
*/
private function _getPerson($id) {
private function _getPerson(int $id) : Person
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')->find($id);