This commit is contained in:
Mathieu Jaumotte 2021-03-26 21:44:59 +01:00
parent ff5c1c1b5a
commit 813ecb0201

View File

@ -63,15 +63,16 @@ class AccompanyingPeriodController extends AbstractController
$person = $this->_getPerson($person_id);
$event = new PrivacyEvent($person, array(
$event = new PrivacyEvent($person, [
'element_class' => AccompanyingPeriod::class,
'action' => 'list'
));
]);
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig',
array('accompanying_periods' => $person->getAccompanyingPeriodsOrdered(),
'person' => $person));
return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig', [
'accompanying_periods' => $person->getAccompanyingPeriodsOrdered(),
'person' => $person
]);
}
/**
@ -95,8 +96,7 @@ class AccompanyingPeriodController extends AbstractController
$form = $this->createForm(
AccompanyingPeriodType::class,
$accompanyingPeriod,
[
$accompanyingPeriod, [
'period_action' => 'create',
'center' => $person->getCenter()
]);
@ -106,7 +106,7 @@ class AccompanyingPeriodController extends AbstractController
$errors = $this->_validatePerson($person);
$flashBag = $this->get('session')->getFlashBag();
if ($form->isValid(array('Default', 'closed'))
if ($form->isValid(['Default', 'closed'])
&& count($errors) === 0) {
$em = $this->getDoctrine()->getManager();
@ -116,8 +116,11 @@ class AccompanyingPeriodController extends AbstractController
$this->get('translator')->trans(
'A period has been created.'));
return $this->redirect($this->generateUrl('chill_person_accompanying_period_list',
array('person_id' => $person->getId())));
return $this->redirect(
$this->generateUrl('chill_person_accompanying_period_list', [
'person_id' => $person->getId()
]));
} else {
$flashBag->add('error', $this->get('translator')
->trans('Error! Period not created!'));
@ -128,13 +131,11 @@ class AccompanyingPeriodController extends AbstractController
}
}
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
array(
'form' => $form->createView(),
'person' => $person,
'accompanying_period' => $accompanyingPeriod
)
);
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig', [
'form' => $form->createView(),
'person' => $person,
'accompanying_period' => $accompanyingPeriod
]);
}
/**
@ -160,25 +161,31 @@ class AccompanyingPeriodController extends AbstractController
'You are not allowed to update this person');
$form = $this->createForm(AccompanyingPeriodType::class,
$accompanyingPeriod, array('period_action' => 'update',
'center' => $person->getCenter()));
$accompanyingPeriod, [
'period_action' => 'update',
'center' => $person->getCenter()
]);
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
$errors = $this->_validatePerson($person);
$flashBag = $this->get('session')->getFlashBag();
if ($form->isValid(array('Default', 'closed'))
if ($form->isValid(['Default', 'closed'])
&& count($errors) === 0) {
$em->flush();
$flashBag->add('success',
$this->get('translator')->trans(
'An accompanying period has been updated.'));
$this->get('translator')->trans('An accompanying period has been updated.'));
return $this->redirect($this->generateUrl('chill_person_accompanying_period_list',
array('person_id' => $person->getId())));
return $this->redirect(
$this->generateUrl('chill_person_accompanying_period_list', [
'person_id' => $person->getId()
]));
} else {
$flashBag->add('error', $this->get('translator')
->trans('Error when updating the period'));
@ -188,12 +195,11 @@ class AccompanyingPeriodController extends AbstractController
}
}
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
array(
'form' => $form->createView(),
'person' => $person,
'accompanying_period' => $accompanyingPeriod
) );
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig', [
'form' => $form->createView(),
'person' => $person,
'accompanying_period' => $accompanyingPeriod
]);
}
/**
@ -207,27 +213,27 @@ class AccompanyingPeriodController extends AbstractController
$person = $this->_getPerson($person_id);
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
'You are not allowed to update this person');
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person, 'You are not allowed to update this person');
if ($person->isOpen() === false) {
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
->trans('Beware period is closed',
array('%name%' => $person->__toString())));
->trans('Beware period is closed', ['%name%' => $person->__toString()]
));
return $this->redirect(
$this->generateUrl('chill_person_accompanying_period_list', array(
'person_id' => $person->getId()
)));
$this->generateUrl('chill_person_accompanying_period_list', [
'person_id' => $person->getId()
]));
}
$current = $person->getCurrentAccompanyingPeriod();
$form = $this->createForm(AccompanyingPeriodType::class, $current, array(
$form = $this->createForm(AccompanyingPeriodType::class, $current, [
'period_action' => 'close',
'center' => $person->getCenter()
));
]);
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
@ -239,16 +245,18 @@ class AccompanyingPeriodController extends AbstractController
if (count($errors) === 0) {
$this->get('session')->getFlashBag()
->add('success', $this->get('translator')
->trans('An accompanying period has been closed.',
array('%name%' => $person->__toString())));
->trans('An accompanying period has been closed.', [
'%name%' => $person->__toString()
]));
$this->getDoctrine()->getManager()->flush();
return $this->redirect(
$this->generateUrl('chill_person_accompanying_period_list', array(
'person_id' => $person->getId()
))
);
$this->generateUrl('chill_person_accompanying_period_list', [
'person_id' => $person->getId()
])
);
} else {
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
@ -259,6 +267,7 @@ class AccompanyingPeriodController extends AbstractController
->add('info', $error->getMessage());
}
}
} else { //if form is not valid
$this->get('session')->getFlashBag()
->add('error',
@ -273,12 +282,11 @@ class AccompanyingPeriodController extends AbstractController
}
}
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
array(
'form' => $form->createView(),
'person' => $person,
'accompanying_period' => $current
));
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig', [
'form' => $form->createView(),
'person' => $person,
'accompanying_period' => $current
]);
}
/**
@ -287,9 +295,9 @@ class AccompanyingPeriodController extends AbstractController
*/
private function _validatePerson(Person $person) {
$errors = $this->get('validator')->validate($person, null,
array('Default'));
['Default']);
$errors_accompanying_period = $this->get('validator')->validate($person, null,
array('accompanying_period_consistent'));
['accompanying_period_consistent']);
foreach($errors_accompanying_period as $error ) {
$errors->add($error);
@ -314,19 +322,22 @@ class AccompanyingPeriodController extends AbstractController
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
->trans('Error! Period %name% is not closed ; it can be open',
array('%name%' => $person->__toString())));
['%name%' => $person->__toString()]
));
return $this->redirect(
$this->generateUrl('chill_person_accompanying_period_list', array(
'person_id' => $person->getId()
)));
$this->generateUrl('chill_person_accompanying_period_list', [
'person_id' => $person->getId()
]));
}
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
$form = $this->createForm(AccompanyingPeriodType::class,
$accompanyingPeriod, array('period_action' => 'open',
'center' => $person->getCenter()));
$accompanyingPeriod, [
'period_action' => 'open',
'center' => $person->getCenter()
]);
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
@ -338,16 +349,18 @@ class AccompanyingPeriodController extends AbstractController
if (count($errors) <= 0) {
$this->get('session')->getFlashBag()
->add('success', $this->get('translator')
->trans('An accompanying period has been opened.',
array('%name%' => $person->__toString())));
->add('success', $this->get('translator')
->trans('An accompanying period has been opened.',
['%name%' => $person->__toString()]
));
$this->getDoctrine()->getManager()->flush();
return $this->redirect(
$this->generateUrl('chill_person_accompanying_period_list', array(
$this->generateUrl('chill_person_accompanying_period_list', [
'person_id' => $person->getId()
)));
]));
} else {
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
@ -358,17 +371,20 @@ class AccompanyingPeriodController extends AbstractController
->add('info', $error->getMessage());
}
}
} else { // if errors in forms
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
->trans('Period not opened : form is invalid'));
->add('error', $this->get('translator')
->trans('Period not opened : form is invalid')
);
}
}
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
array('form' => $form->createView(),
'person' => $person,
'accompanying_period' => $accompanyingPeriod));
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig', [
'form' => $form->createView(),
'person' => $person,
'accompanying_period' => $accompanyingPeriod
]);
}
/**
@ -405,13 +421,16 @@ class AccompanyingPeriodController extends AbstractController
$this->addFlash('success', $this->get('translator')->trans(
'The period has been re-opened'));
return $this->redirectToRoute('chill_person_accompanying_period_list',
array('person_id' => $person->getId()));
return $this->redirectToRoute('chill_person_accompanying_period_list', [
'person_id' => $person->getId()
]);
} elseif ($confirm === false && $period->canBeReOpened()) {
return $this->render('ChillPersonBundle:AccompanyingPeriod:re_open.html.twig', array(
return $this->render('ChillPersonBundle:AccompanyingPeriod:re_open.html.twig', [
'period' => $period,
'person' => $person
));
]);
} else {
return (new Response())
->setStatusCode(Response::HTTP_BAD_REQUEST)