mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
cleaning
This commit is contained in:
parent
ff5c1c1b5a
commit
813ecb0201
@ -63,15 +63,16 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
|
|
||||||
$person = $this->_getPerson($person_id);
|
$person = $this->_getPerson($person_id);
|
||||||
|
|
||||||
$event = new PrivacyEvent($person, array(
|
$event = new PrivacyEvent($person, [
|
||||||
'element_class' => AccompanyingPeriod::class,
|
'element_class' => AccompanyingPeriod::class,
|
||||||
'action' => 'list'
|
'action' => 'list'
|
||||||
));
|
]);
|
||||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig', [
|
||||||
array('accompanying_periods' => $person->getAccompanyingPeriodsOrdered(),
|
'accompanying_periods' => $person->getAccompanyingPeriodsOrdered(),
|
||||||
'person' => $person));
|
'person' => $person
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,8 +96,7 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
|
|
||||||
$form = $this->createForm(
|
$form = $this->createForm(
|
||||||
AccompanyingPeriodType::class,
|
AccompanyingPeriodType::class,
|
||||||
$accompanyingPeriod,
|
$accompanyingPeriod, [
|
||||||
[
|
|
||||||
'period_action' => 'create',
|
'period_action' => 'create',
|
||||||
'center' => $person->getCenter()
|
'center' => $person->getCenter()
|
||||||
]);
|
]);
|
||||||
@ -106,7 +106,7 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
$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(['Default', 'closed'])
|
||||||
&& count($errors) === 0) {
|
&& count($errors) === 0) {
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
@ -116,8 +116,11 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
$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(
|
||||||
array('person_id' => $person->getId())));
|
$this->generateUrl('chill_person_accompanying_period_list', [
|
||||||
|
'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!'));
|
||||||
@ -128,13 +131,11 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig', [
|
||||||
array(
|
'form' => $form->createView(),
|
||||||
'form' => $form->createView(),
|
'person' => $person,
|
||||||
'person' => $person,
|
'accompanying_period' => $accompanyingPeriod
|
||||||
'accompanying_period' => $accompanyingPeriod
|
]);
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,25 +161,31 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
'You are not allowed to update this person');
|
'You are not allowed to update this person');
|
||||||
|
|
||||||
$form = $this->createForm(AccompanyingPeriodType::class,
|
$form = $this->createForm(AccompanyingPeriodType::class,
|
||||||
$accompanyingPeriod, array('period_action' => 'update',
|
$accompanyingPeriod, [
|
||||||
'center' => $person->getCenter()));
|
'period_action' => 'update',
|
||||||
|
'center' => $person->getCenter()
|
||||||
|
]);
|
||||||
|
|
||||||
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(['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(
|
||||||
array('person_id' => $person->getId())));
|
$this->generateUrl('chill_person_accompanying_period_list', [
|
||||||
|
'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'));
|
||||||
|
|
||||||
@ -188,12 +195,11 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig', [
|
||||||
array(
|
'form' => $form->createView(),
|
||||||
'form' => $form->createView(),
|
'person' => $person,
|
||||||
'person' => $person,
|
'accompanying_period' => $accompanyingPeriod
|
||||||
'accompanying_period' => $accompanyingPeriod
|
]);
|
||||||
) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -207,27 +213,27 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
|
|
||||||
$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', ['%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', [
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
)));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$current = $person->getCurrentAccompanyingPeriod();
|
$current = $person->getCurrentAccompanyingPeriod();
|
||||||
|
|
||||||
$form = $this->createForm(AccompanyingPeriodType::class, $current, array(
|
$form = $this->createForm(AccompanyingPeriodType::class, $current, [
|
||||||
'period_action' => 'close',
|
'period_action' => 'close',
|
||||||
'center' => $person->getCenter()
|
'center' => $person->getCenter()
|
||||||
));
|
]);
|
||||||
|
|
||||||
if ($request->getMethod() === 'POST') {
|
if ($request->getMethod() === 'POST') {
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
@ -239,16 +245,18 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
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 closed.',
|
->trans('An accompanying period has been closed.', [
|
||||||
array('%name%' => $person->__toString())));
|
'%name%' => $person->__toString()
|
||||||
|
]));
|
||||||
|
|
||||||
$this->getDoctrine()->getManager()->flush();
|
$this->getDoctrine()->getManager()->flush();
|
||||||
|
|
||||||
return $this->redirect(
|
return $this->redirect(
|
||||||
$this->generateUrl('chill_person_accompanying_period_list', array(
|
$this->generateUrl('chill_person_accompanying_period_list', [
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
))
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('error', $this->get('translator')
|
->add('error', $this->get('translator')
|
||||||
@ -259,6 +267,7 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
->add('info', $error->getMessage());
|
->add('info', $error->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { //if form is not valid
|
} else { //if form is not valid
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('error',
|
->add('error',
|
||||||
@ -273,12 +282,11 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig', [
|
||||||
array(
|
'form' => $form->createView(),
|
||||||
'form' => $form->createView(),
|
'person' => $person,
|
||||||
'person' => $person,
|
'accompanying_period' => $current
|
||||||
'accompanying_period' => $current
|
]);
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -287,9 +295,9 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
private function _validatePerson(Person $person) {
|
private function _validatePerson(Person $person) {
|
||||||
$errors = $this->get('validator')->validate($person, null,
|
$errors = $this->get('validator')->validate($person, null,
|
||||||
array('Default'));
|
['Default']);
|
||||||
$errors_accompanying_period = $this->get('validator')->validate($person, null,
|
$errors_accompanying_period = $this->get('validator')->validate($person, null,
|
||||||
array('accompanying_period_consistent'));
|
['accompanying_period_consistent']);
|
||||||
|
|
||||||
foreach($errors_accompanying_period as $error ) {
|
foreach($errors_accompanying_period as $error ) {
|
||||||
$errors->add($error);
|
$errors->add($error);
|
||||||
@ -314,19 +322,22 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
$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())));
|
['%name%' => $person->__toString()]
|
||||||
|
));
|
||||||
|
|
||||||
return $this->redirect(
|
return $this->redirect(
|
||||||
$this->generateUrl('chill_person_accompanying_period_list', array(
|
$this->generateUrl('chill_person_accompanying_period_list', [
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
)));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
|
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
|
||||||
|
|
||||||
$form = $this->createForm(AccompanyingPeriodType::class,
|
$form = $this->createForm(AccompanyingPeriodType::class,
|
||||||
$accompanyingPeriod, array('period_action' => 'open',
|
$accompanyingPeriod, [
|
||||||
'center' => $person->getCenter()));
|
'period_action' => 'open',
|
||||||
|
'center' => $person->getCenter()
|
||||||
|
]);
|
||||||
|
|
||||||
if ($request->getMethod() === 'POST') {
|
if ($request->getMethod() === 'POST') {
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
@ -338,16 +349,18 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
|
|
||||||
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())));
|
['%name%' => $person->__toString()]
|
||||||
|
));
|
||||||
|
|
||||||
$this->getDoctrine()->getManager()->flush();
|
$this->getDoctrine()->getManager()->flush();
|
||||||
|
|
||||||
return $this->redirect(
|
return $this->redirect(
|
||||||
$this->generateUrl('chill_person_accompanying_period_list', array(
|
$this->generateUrl('chill_person_accompanying_period_list', [
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
)));
|
]));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('error', $this->get('translator')
|
->add('error', $this->get('translator')
|
||||||
@ -358,17 +371,20 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
->add('info', $error->getMessage());
|
->add('info', $error->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // if errors in forms
|
} else { // if errors in forms
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('error', $this->get('translator')
|
->add('error', $this->get('translator')
|
||||||
->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(),
|
'form' => $form->createView(),
|
||||||
'person' => $person,
|
'person' => $person,
|
||||||
'accompanying_period' => $accompanyingPeriod));
|
'accompanying_period' => $accompanyingPeriod
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -405,13 +421,16 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
$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()));
|
'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', [
|
||||||
'period' => $period,
|
'period' => $period,
|
||||||
'person' => $person
|
'person' => $person
|
||||||
));
|
]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return (new Response())
|
return (new Response())
|
||||||
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user