mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
fix deprecation: no more passing of type instances
This commit is contained in:
parent
68febabd95
commit
f7631af1fd
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* Chill is a software for social workers
|
* Chill is a software for social workers
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||||
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
@ -34,148 +34,148 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
class AccompanyingPeriodController extends Controller
|
class AccompanyingPeriodController extends Controller
|
||||||
{
|
{
|
||||||
public function listAction($person_id){
|
public function listAction($person_id){
|
||||||
|
|
||||||
$person = $this->_getPerson($person_id);
|
$person = $this->_getPerson($person_id);
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig',
|
||||||
array('accompanying_periods' => $person->getAccompanyingPeriodsOrdered(),
|
array('accompanying_periods' => $person->getAccompanyingPeriodsOrdered(),
|
||||||
'person' => $person));
|
'person' => $person));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createAction($person_id) {
|
public function createAction($person_id) {
|
||||||
$person = $this->_getPerson($person_id);
|
$person = $this->_getPerson($person_id);
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
|
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
|
||||||
'You are not allowed to update this person');
|
'You are not allowed to update this person');
|
||||||
|
|
||||||
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
|
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
|
||||||
$accompanyingPeriod->setClosingDate(new \DateTime());
|
$accompanyingPeriod->setClosingDate(new \DateTime());
|
||||||
|
|
||||||
$person->addAccompanyingPeriod(
|
$person->addAccompanyingPeriod(
|
||||||
$accompanyingPeriod);
|
$accompanyingPeriod);
|
||||||
|
|
||||||
$form = $this->createForm(new AccompanyingPeriodType(),
|
$form = $this->createForm(AccompanyingPeriodType::class,
|
||||||
$accompanyingPeriod, array('period_action' => 'create'));
|
$accompanyingPeriod, array('period_action' => 'create'));
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
if ($request->getMethod() === 'POST') {
|
if ($request->getMethod() === 'POST') {
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
$errors = $this->_validatePerson($person);
|
$errors = $this->_validatePerson($person);
|
||||||
$flashBag = $this->get('session')->getFlashBag();
|
$flashBag = $this->get('session')->getFlashBag();
|
||||||
|
|
||||||
if ($form->isValid(array('Default', 'closed'))
|
if ($form->isValid(array('Default', 'closed'))
|
||||||
&& count($errors) === 0) {
|
&& count($errors) === 0) {
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$em->persist($accompanyingPeriod);
|
$em->persist($accompanyingPeriod);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
$flashBag->add('success',
|
$flashBag->add('success',
|
||||||
$this->get('translator')->trans(
|
$this->get('translator')->trans(
|
||||||
'A period has been created.'));
|
'A period has been created.'));
|
||||||
|
|
||||||
return $this->redirect($this->generateUrl('chill_person_accompanying_period_list',
|
return $this->redirect($this->generateUrl('chill_person_accompanying_period_list',
|
||||||
array('person_id' => $person->getId())));
|
array('person_id' => $person->getId())));
|
||||||
} else {
|
} else {
|
||||||
$flashBag->add('error', $this->get('translator')
|
$flashBag->add('error', $this->get('translator')
|
||||||
->trans('Error! Period not created!'));
|
->trans('Error! Period not created!'));
|
||||||
|
|
||||||
foreach($errors as $error) {
|
foreach($errors as $error) {
|
||||||
$flashBag->add('info', $error->getMessage());
|
$flashBag->add('info', $error->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
||||||
array(
|
array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'person' => $person,
|
'person' => $person,
|
||||||
'accompanying_period' => $accompanyingPeriod
|
'accompanying_period' => $accompanyingPeriod
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateAction($person_id, $period_id){
|
public function updateAction($person_id, $period_id){
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
$accompanyingPeriod = $em->getRepository('ChillPersonBundle:AccompanyingPeriod')
|
$accompanyingPeriod = $em->getRepository('ChillPersonBundle:AccompanyingPeriod')
|
||||||
->find($period_id);
|
->find($period_id);
|
||||||
|
|
||||||
if ($accompanyingPeriod === null) {
|
if ($accompanyingPeriod === null) {
|
||||||
return $this->createNotFoundException("Period with id ".$period_id.
|
return $this->createNotFoundException("Period with id ".$period_id.
|
||||||
" is not found");
|
" is not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
$person = $accompanyingPeriod->getPerson();
|
$person = $accompanyingPeriod->getPerson();
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
|
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
|
||||||
'You are not allowed to update this person');
|
'You are not allowed to update this person');
|
||||||
|
|
||||||
$form = $this->createForm(new AccompanyingPeriodType(),
|
$form = $this->createForm(AccompanyingPeriodType::class,
|
||||||
$accompanyingPeriod, array('period_action' => 'update'));
|
$accompanyingPeriod, array('period_action' => 'update'));
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
if ($request->getMethod() === 'POST') {
|
if ($request->getMethod() === 'POST') {
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
$errors = $this->_validatePerson($person);
|
$errors = $this->_validatePerson($person);
|
||||||
$flashBag = $this->get('session')->getFlashBag();
|
$flashBag = $this->get('session')->getFlashBag();
|
||||||
|
|
||||||
if ($form->isValid(array('Default', 'closed'))
|
if ($form->isValid(array('Default', 'closed'))
|
||||||
&& count($errors) === 0) {
|
&& count($errors) === 0) {
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
$flashBag->add('success',
|
$flashBag->add('success',
|
||||||
$this->get('translator')->trans(
|
$this->get('translator')->trans(
|
||||||
'An accompanying period has been updated.'));
|
'An accompanying period has been updated.'));
|
||||||
|
|
||||||
return $this->redirect($this->generateUrl('chill_person_accompanying_period_list',
|
return $this->redirect($this->generateUrl('chill_person_accompanying_period_list',
|
||||||
array('person_id' => $person->getId())));
|
array('person_id' => $person->getId())));
|
||||||
} else {
|
} else {
|
||||||
$flashBag->add('error', $this->get('translator')
|
$flashBag->add('error', $this->get('translator')
|
||||||
->trans('Error when updating the period'));
|
->trans('Error when updating the period'));
|
||||||
|
|
||||||
foreach($errors as $error) {
|
foreach($errors as $error) {
|
||||||
$flashBag->add('info', $error->getMessage());
|
$flashBag->add('info', $error->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
||||||
array(
|
array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'person' => $person,
|
'person' => $person,
|
||||||
'accompanying_period' => $accompanyingPeriod
|
'accompanying_period' => $accompanyingPeriod
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function closeAction($person_id) {
|
public function closeAction($person_id) {
|
||||||
$person = $this->_getPerson($person_id);
|
$person = $this->_getPerson($person_id);
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
|
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
|
||||||
'You are not allowed to update this person');
|
'You are not allowed to update this person');
|
||||||
|
|
||||||
if ($person->isOpen() === false) {
|
if ($person->isOpen() === false) {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('error', $this->get('translator')
|
->add('error', $this->get('translator')
|
||||||
->trans('Beware period is closed',
|
->trans('Beware period is closed',
|
||||||
array('%name%' => $person->__toString())));
|
array('%name%' => $person->__toString())));
|
||||||
|
|
||||||
return $this->redirect(
|
return $this->redirect(
|
||||||
$this->generateUrl('chill_person_accompanying_period_list', array(
|
$this->generateUrl('chill_person_accompanying_period_list', array(
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$current = $person->getCurrentAccompanyingPeriod();
|
$current = $person->getCurrentAccompanyingPeriod();
|
||||||
$form = $this->createForm(new AccompanyingPeriodType(), $current, array(
|
$form = $this->createForm(AccompanyingPeriodType::class, $current, array(
|
||||||
'period_action' => 'close'
|
'period_action' => 'close'
|
||||||
));
|
));
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
if ($request->getMethod() === 'POST') {
|
if ($request->getMethod() === 'POST') {
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isValid()){
|
if ($form->isValid()){
|
||||||
$person->close($current);
|
$person->close($current);
|
||||||
$errors = $this->_validatePerson($person);
|
$errors = $this->_validatePerson($person);
|
||||||
@ -197,7 +197,7 @@ class AccompanyingPeriodController extends Controller
|
|||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('error', $this->get('translator')
|
->add('error', $this->get('translator')
|
||||||
->trans('Error! Period not closed!'));
|
->trans('Error! Period not closed!'));
|
||||||
|
|
||||||
foreach ($errors as $error) {
|
foreach ($errors as $error) {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('info', $error->getMessage());
|
->add('info', $error->getMessage());
|
||||||
@ -209,14 +209,14 @@ class AccompanyingPeriodController extends Controller
|
|||||||
$this->get('translator')
|
$this->get('translator')
|
||||||
->trans('Pediod closing form is not valid')
|
->trans('Pediod closing form is not valid')
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($form->getErrors() as $error) {
|
foreach ($form->getErrors() as $error) {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('info', $error->getMessage());
|
->add('info', $error->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
||||||
array(
|
array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
@ -224,9 +224,9 @@ class AccompanyingPeriodController extends Controller
|
|||||||
'accompanying_period' => $current
|
'accompanying_period' => $current
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param Chill\PersonBundle\Entity\Person $person
|
* @param Chill\PersonBundle\Entity\Person $person
|
||||||
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
|
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
|
||||||
*/
|
*/
|
||||||
@ -235,30 +235,30 @@ class AccompanyingPeriodController extends Controller
|
|||||||
array('Default'));
|
array('Default'));
|
||||||
$errors_accompanying_period = $this->get('validator')->validate($person,
|
$errors_accompanying_period = $this->get('validator')->validate($person,
|
||||||
array('accompanying_period_consistent'));
|
array('accompanying_period_consistent'));
|
||||||
|
|
||||||
foreach($errors_accompanying_period as $error ) {
|
foreach($errors_accompanying_period as $error ) {
|
||||||
$errors->add($error);
|
$errors->add($error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function openAction($person_id) {
|
public function openAction($person_id) {
|
||||||
$person = $this->_getPerson($person_id);
|
$person = $this->_getPerson($person_id);
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
|
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
|
||||||
'You are not allowed to update this person');
|
'You are not allowed to update this person');
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
//in case the person is already open
|
//in case the person is already open
|
||||||
if ($person->isOpen()) {
|
if ($person->isOpen()) {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('error', $this->get('translator')
|
->add('error', $this->get('translator')
|
||||||
->trans('Error! Period %name% is not closed ; it can be open',
|
->trans('Error! Period %name% is not closed ; it can be open',
|
||||||
array('%name%' => $person->__toString())));
|
array('%name%' => $person->__toString())));
|
||||||
|
|
||||||
return $this->redirect(
|
return $this->redirect(
|
||||||
$this->generateUrl('chill_person_accompanying_period_list', array(
|
$this->generateUrl('chill_person_accompanying_period_list', array(
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
@ -267,21 +267,21 @@ class AccompanyingPeriodController extends Controller
|
|||||||
|
|
||||||
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
|
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
|
||||||
|
|
||||||
$form = $this->createForm(new AccompanyingPeriodType(),
|
$form = $this->createForm(AccompanyingPeriodType::class,
|
||||||
$accompanyingPeriod, array('period_action' => 'open'));
|
$accompanyingPeriod, array('period_action' => 'open'));
|
||||||
|
|
||||||
if ($request->getMethod() === 'POST') {
|
if ($request->getMethod() === 'POST') {
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isValid()) {
|
if ($form->isValid()) {
|
||||||
$person->open($accompanyingPeriod);
|
$person->open($accompanyingPeriod);
|
||||||
|
|
||||||
$errors = $this->_validatePerson($person);
|
$errors = $this->_validatePerson($person);
|
||||||
|
|
||||||
if (count($errors) <= 0) {
|
if (count($errors) <= 0) {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('success', $this->get('translator')
|
->add('success', $this->get('translator')
|
||||||
->trans('An accompanying period has been opened.',
|
->trans('An accompanying period has been opened.',
|
||||||
array('%name%' => $person->__toString())));
|
array('%name%' => $person->__toString())));
|
||||||
|
|
||||||
$this->getDoctrine()->getManager()->flush();
|
$this->getDoctrine()->getManager()->flush();
|
||||||
@ -294,7 +294,7 @@ class AccompanyingPeriodController extends Controller
|
|||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('error', $this->get('translator')
|
->add('error', $this->get('translator')
|
||||||
->trans('Period not opened'));
|
->trans('Period not opened'));
|
||||||
|
|
||||||
foreach ($errors as $error) {
|
foreach ($errors as $error) {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('info', $error->getMessage());
|
->add('info', $error->getMessage());
|
||||||
@ -306,42 +306,42 @@ class AccompanyingPeriodController extends Controller
|
|||||||
->trans('Period not opened : form is invalid'));
|
->trans('Period not opened : form is invalid'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
||||||
array('form' => $form->createView(),
|
array('form' => $form->createView(),
|
||||||
'person' => $person,
|
'person' => $person,
|
||||||
'accompanying_period' => $accompanyingPeriod));
|
'accompanying_period' => $accompanyingPeriod));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reOpenAction($person_id, $period_id, Request $request)
|
public function reOpenAction($person_id, $period_id, Request $request)
|
||||||
{
|
{
|
||||||
$person = $this->_getPerson($person_id);
|
$person = $this->_getPerson($person_id);
|
||||||
|
|
||||||
$criteria = Criteria::create();
|
$criteria = Criteria::create();
|
||||||
$criteria->where($criteria->expr()->eq('id', $period_id));
|
$criteria->where($criteria->expr()->eq('id', $period_id));
|
||||||
|
|
||||||
/* @var $period AccompanyingPeriod */
|
/* @var $period AccompanyingPeriod */
|
||||||
$period = $person->getAccompanyingPeriods()
|
$period = $person->getAccompanyingPeriods()
|
||||||
->matching($criteria)
|
->matching($criteria)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($period === NULL) {
|
if ($period === NULL) {
|
||||||
throw $this->createNotFoundException('period not found');
|
throw $this->createNotFoundException('period not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$confirm = $request->query->getBoolean('confirm', false);
|
$confirm = $request->query->getBoolean('confirm', false);
|
||||||
|
|
||||||
if ($confirm === true && $period->canBeReOpened()) {
|
if ($confirm === true && $period->canBeReOpened()) {
|
||||||
$period->reOpen();
|
$period->reOpen();
|
||||||
|
|
||||||
$this->_validatePerson($person);
|
$this->_validatePerson($person);
|
||||||
|
|
||||||
$this->getDoctrine()->getManager()->flush();
|
$this->getDoctrine()->getManager()->flush();
|
||||||
|
|
||||||
$this->addFlash('success', $this->get('translator')->trans(
|
$this->addFlash('success', $this->get('translator')->trans(
|
||||||
'The period has been re-opened'));
|
'The period has been re-opened'));
|
||||||
|
|
||||||
return $this->redirectToRoute('chill_person_accompanying_period_list',
|
return $this->redirectToRoute('chill_person_accompanying_period_list',
|
||||||
array('person_id' => $person->getId()));
|
array('person_id' => $person->getId()));
|
||||||
} elseif ($confirm === false && $period->canBeReOpened()) {
|
} elseif ($confirm === false && $period->canBeReOpened()) {
|
||||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:re_open.html.twig', array(
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:re_open.html.twig', array(
|
||||||
@ -354,9 +354,9 @@ class AccompanyingPeriodController extends Controller
|
|||||||
->setContent("You cannot re-open this period");
|
->setContent("You cannot re-open this period");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return Person
|
* @return Person
|
||||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the person is not found
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the person is not found
|
||||||
@ -364,14 +364,14 @@ class AccompanyingPeriodController extends Controller
|
|||||||
private function _getPerson($id) {
|
private function _getPerson($id) {
|
||||||
$person = $this->getDoctrine()->getManager()
|
$person = $this->getDoctrine()->getManager()
|
||||||
->getRepository('ChillPersonBundle:Person')->find($id);
|
->getRepository('ChillPersonBundle:Person')->find($id);
|
||||||
|
|
||||||
if ($person === null) {
|
if ($person === null) {
|
||||||
throw $this->createNotFoundException('Person not found');
|
throw $this->createNotFoundException('Person not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person,
|
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person,
|
||||||
"You are not allowed to see this person");
|
"You are not allowed to see this person");
|
||||||
|
|
||||||
return $person;
|
return $person;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user