mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
@@ -26,6 +26,10 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Form\AccompanyingPeriodType;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class AccompanyingPeriodController extends Controller
|
||||
{
|
||||
@@ -40,6 +44,9 @@ class AccompanyingPeriodController extends Controller
|
||||
|
||||
public function createAction($person_id) {
|
||||
$person = $this->_getPerson($person_id);
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
|
||||
'You are not allowed to update this person');
|
||||
|
||||
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
|
||||
$accompanyingPeriod->setClosingDate(new \DateTime());
|
||||
@@ -48,7 +55,7 @@ class AccompanyingPeriodController extends Controller
|
||||
$accompanyingPeriod);
|
||||
|
||||
$form = $this->createForm(new AccompanyingPeriodType(),
|
||||
$accompanyingPeriod, array('period_action' => 'update'));
|
||||
$accompanyingPeriod, array('period_action' => 'create'));
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
@@ -65,7 +72,7 @@ class AccompanyingPeriodController extends Controller
|
||||
$em->flush();
|
||||
$flashBag->add('success',
|
||||
$this->get('translator')->trans(
|
||||
'Period created!'));
|
||||
'A period has been created.'));
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_person_accompanying_period_list',
|
||||
array('person_id' => $person->getId())));
|
||||
@@ -100,6 +107,10 @@ class AccompanyingPeriodController extends Controller
|
||||
}
|
||||
|
||||
$person = $accompanyingPeriod->getPerson();
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
|
||||
'You are not allowed to update this person');
|
||||
|
||||
$form = $this->createForm(new AccompanyingPeriodType(),
|
||||
$accompanyingPeriod, array('period_action' => 'update'));
|
||||
$request = $this->getRequest();
|
||||
@@ -115,7 +126,7 @@ class AccompanyingPeriodController extends Controller
|
||||
|
||||
$flashBag->add('success',
|
||||
$this->get('translator')->trans(
|
||||
'Period updating done'));
|
||||
'An accompanying period has been updated.'));
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_person_accompanying_period_list',
|
||||
array('person_id' => $person->getId())));
|
||||
@@ -140,6 +151,9 @@ class AccompanyingPeriodController extends Controller
|
||||
public function closeAction($person_id) {
|
||||
$person = $this->_getPerson($person_id);
|
||||
|
||||
$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')
|
||||
@@ -169,7 +183,7 @@ class AccompanyingPeriodController extends Controller
|
||||
if (count($errors) === 0) {
|
||||
$this->get('session')->getFlashBag()
|
||||
->add('success', $this->get('translator')
|
||||
->trans('Period closed!',
|
||||
->trans('An accompanying period has been closed.',
|
||||
array('%name%' => $person->__toString())));
|
||||
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
@@ -193,7 +207,7 @@ class AccompanyingPeriodController extends Controller
|
||||
$this->get('session')->getFlashBag()
|
||||
->add('error',
|
||||
$this->get('translator')
|
||||
->trans('Pediod closing form is not valide')
|
||||
->trans('Pediod closing form is not valid')
|
||||
);
|
||||
|
||||
foreach ($form->getErrors() as $error) {
|
||||
@@ -233,6 +247,9 @@ class AccompanyingPeriodController extends Controller
|
||||
public function openAction($person_id) {
|
||||
$person = $this->_getPerson($person_id);
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
|
||||
'You are not allowed to update this person');
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
//in case the person is already open
|
||||
@@ -264,7 +281,7 @@ class AccompanyingPeriodController extends Controller
|
||||
if (count($errors) <= 0) {
|
||||
$this->get('session')->getFlashBag()
|
||||
->add('success', $this->get('translator')
|
||||
->trans('Period %name% opened!',
|
||||
->trans('An accompanying period has been opened.',
|
||||
array('%name%' => $person->__toString())));
|
||||
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
@@ -296,6 +313,54 @@ class AccompanyingPeriodController extends Controller
|
||||
'accompanying_period' => $accompanyingPeriod));
|
||||
}
|
||||
|
||||
public function reOpenAction($person_id, $period_id, Request $request)
|
||||
{
|
||||
$person = $this->_getPerson($person_id);
|
||||
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where($criteria->expr()->eq('id', $period_id));
|
||||
|
||||
/* @var $period AccompanyingPeriod */
|
||||
$period = $person->getAccompanyingPeriods()
|
||||
->matching($criteria)
|
||||
->first();
|
||||
|
||||
if ($period === NULL) {
|
||||
throw $this->createNotFoundException('period not found');
|
||||
}
|
||||
|
||||
$confirm = $request->query->getBoolean('confirm', false);
|
||||
|
||||
if ($confirm === true && $period->canBeReOpened()) {
|
||||
$period->reOpen();
|
||||
|
||||
$this->_validatePerson($person);
|
||||
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$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()));
|
||||
} elseif ($confirm === false && $period->canBeReOpened()) {
|
||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:re_open.html.twig', array(
|
||||
'period' => $period,
|
||||
'person' => $person
|
||||
));
|
||||
} else {
|
||||
return (new Response())
|
||||
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
||||
->setContent("You cannot re-open this period");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $id
|
||||
* @return Person
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the person is not found
|
||||
*/
|
||||
private function _getPerson($id) {
|
||||
$person = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillPersonBundle:Person')->find($id);
|
||||
@@ -304,6 +369,9 @@ class AccompanyingPeriodController extends Controller
|
||||
throw $this->createNotFoundException('Person not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person,
|
||||
"You are not allowed to see this person");
|
||||
|
||||
return $person;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user