Commit 2a096431 authored by Julien Fastré's avatar Julien Fastré

Merge remote-tracking branch 'origin/upgrade-sf3' into upgrade-sf3

parents 4b0499cf 3459755d
Pipeline #46300 failed with stages
in 5 minutes and 48 seconds
......@@ -3,7 +3,7 @@
/*
* 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>
*
* 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
{
public function listAction($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(),
'person' => $person));
}
public function createAction($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');
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
$accompanyingPeriod->setClosingDate(new \DateTime());
$person->addAccompanyingPeriod(
$accompanyingPeriod);
$form = $this->createForm(new AccompanyingPeriodType(),
$form = $this->createForm(AccompanyingPeriodType::class,
$accompanyingPeriod, array('period_action' => 'create'));
$request = $this->getRequest();
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(array('Default', 'closed'))
&& count($errors) === 0) {
$em = $this->getDoctrine()->getManager();
$em->persist($accompanyingPeriod);
$em->flush();
$flashBag->add('success',
$flashBag->add('success',
$this->get('translator')->trans(
'A period has been created.'));
return $this->redirect($this->generateUrl('chill_person_accompanying_period_list',
array('person_id' => $person->getId())));
} else {
$flashBag->add('error', $this->get('translator')
->trans('Error! Period not created!'));
foreach($errors as $error) {
$flashBag->add('info', $error->getMessage());
}
}
}
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
array(
'form' => $form->createView(),
'person' => $person,
'accompanying_period' => $accompanyingPeriod
)
)
);
}
public function updateAction($person_id, $period_id){
$em = $this->getDoctrine()->getManager();
$accompanyingPeriod = $em->getRepository('ChillPersonBundle:AccompanyingPeriod')
->find($period_id);
if ($accompanyingPeriod === null) {
return $this->createNotFoundException("Period with id ".$period_id.
" is not found");
}
$person = $accompanyingPeriod->getPerson();
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person,
'You are not allowed to update this person');
$form = $this->createForm(new AccompanyingPeriodType(),
$form = $this->createForm(AccompanyingPeriodType::class,
$accompanyingPeriod, array('period_action' => 'update'));
$request = $this->getRequest();
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(array('Default', 'closed'))
&& count($errors) === 0) {
$em->flush();
$flashBag->add('success',
$flashBag->add('success',
$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())));
} else {
$flashBag->add('error', $this->get('translator')
->trans('Error when updating the period'));
foreach($errors as $error) {
$flashBag->add('info', $error->getMessage());
}
}
}
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
array(
'form' => $form->createView(),
'person' => $person,
'accompanying_period' => $accompanyingPeriod
) );
}
public function closeAction($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');
if ($person->isOpen() === false) {
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
->trans('Beware period is closed',
->trans('Beware period is closed',
array('%name%' => $person->__toString())));
return $this->redirect(
$this->generateUrl('chill_person_accompanying_period_list', array(
'person_id' => $person->getId()
)));
}
$current = $person->getCurrentAccompanyingPeriod();
$form = $this->createForm(new AccompanyingPeriodType(), $current, array(
$current = $person->getCurrentAccompanyingPeriod();
$form = $this->createForm(AccompanyingPeriodType::class, $current, array(
'period_action' => 'close'
));
$request = $this->getRequest();
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
if ($form->isValid()){
$person->close($current);
$errors = $this->_validatePerson($person);
......@@ -197,7 +197,7 @@ class AccompanyingPeriodController extends Controller
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
->trans('Error! Period not closed!'));
foreach ($errors as $error) {
$this->get('session')->getFlashBag()
->add('info', $error->getMessage());
......@@ -209,14 +209,14 @@ class AccompanyingPeriodController extends Controller
$this->get('translator')
->trans('Pediod closing form is not valid')
);
foreach ($form->getErrors() as $error) {
$this->get('session')->getFlashBag()
->add('info', $error->getMessage());
}
}
}
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
array(
'form' => $form->createView(),
......@@ -224,9 +224,9 @@ class AccompanyingPeriodController extends Controller
'accompanying_period' => $current
));
}
/**
*
*
* @param Chill\PersonBundle\Entity\Person $person
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
*/
......@@ -235,30 +235,30 @@ class AccompanyingPeriodController extends Controller
array('Default'));
$errors_accompanying_period = $this->get('validator')->validate($person,
array('accompanying_period_consistent'));
foreach($errors_accompanying_period as $error ) {
$errors->add($error);
}
return $errors;
}
public function openAction($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');
$request = $this->getRequest();
//in case the person is already open
if ($person->isOpen()) {
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
->trans('Error! Period %name% is not closed ; it can be open',
array('%name%' => $person->__toString())));
return $this->redirect(
$this->generateUrl('chill_person_accompanying_period_list', array(
'person_id' => $person->getId()
......@@ -267,21 +267,21 @@ class AccompanyingPeriodController extends Controller
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
$form = $this->createForm(new AccompanyingPeriodType(),
$form = $this->createForm(AccompanyingPeriodType::class,
$accompanyingPeriod, array('period_action' => 'open'));
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
if ($form->isValid()) {
$person->open($accompanyingPeriod);
$errors = $this->_validatePerson($person);
if (count($errors) <= 0) {
$this->get('session')->getFlashBag()
->add('success', $this->get('translator')
->trans('An accompanying period has been opened.',
->trans('An accompanying period has been opened.',
array('%name%' => $person->__toString())));
$this->getDoctrine()->getManager()->flush();
......@@ -294,7 +294,7 @@ class AccompanyingPeriodController extends Controller
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
->trans('Period not opened'));
foreach ($errors as $error) {
$this->get('session')->getFlashBag()
->add('info', $error->getMessage());
......@@ -306,42 +306,42 @@ class AccompanyingPeriodController extends Controller
->trans('Period not opened : form is invalid'));
}
}
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
array('form' => $form->createView(),
'person' => $person,
'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);
$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',
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(
......@@ -354,9 +354,9 @@ class AccompanyingPeriodController extends Controller
->setContent("You cannot re-open this period");
}
}
/**
*
*
* @param int $id
* @return Person
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the person is not found
......@@ -364,14 +364,14 @@ class AccompanyingPeriodController extends Controller
private function _getPerson($id) {
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')->find($id);
if ($person === null) {
if ($person === null) {
throw $this->createNotFoundException('Person not found');
}
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person,
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person,
"You are not allowed to see this person");
return $person;
}
}
......@@ -27,14 +27,16 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Chill\MainBundle\Form\Type\CenterType;
use Chill\PersonBundle\Form\Type\GenderType;
use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer;
use Chill\PersonBundle\Form\CreationPersonType;
class CreationPersonType extends AbstractType
{
const NAME = 'chill_personbundle_person_creation';
const NAME = CreationPersonType::class;
const FORM_NOT_REVIEWED = 'not_reviewed';
const FORM_REVIEWED = 'reviewed' ;
......@@ -89,7 +91,7 @@ class CreationPersonType extends AbstractType
->add('birthdate', DateType::class, array('required' => false,
'widget' => 'single_text', 'format' => 'dd-MM-yyyy'))
->add('gender', GenderType::class, array(
'required' => true, 'empty_value' => null
'required' => true, 'placeholder' => null
))
->add('creation_date', DateType::class, array(
'required' => true,
......
......@@ -6,6 +6,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
/**
* A type to add a closing motive
......@@ -31,7 +32,7 @@ class ClosingMotiveType extends AbstractType
public function getParent()
{
return 'entity';
return EntityType::class;
}
public function configureOptions(OptionsResolver $resolver)
......@@ -45,8 +46,8 @@ class ClosingMotiveType extends AbstractType
$resolver->setDefaults(array(
'class' => 'ChillPersonBundle:AccompanyingPeriod\ClosingMotive',
'empty_data' => null,
'empty_value' => 'Choose a motive',
'property' => 'name['.$this->locale.']'
'placeholder' => 'Choose a motive',
'choice_label' => 'name['.$this->locale.']'
)
);
}
......
......@@ -28,9 +28,10 @@ class GenderType extends AbstractType {
$resolver->setDefaults(array(
'choices' => $a,
'choices_as_values' => true,
'expanded' => true,
'multiple' => false,
'empty_value' => null
'placeholder' => null
));
}
......
......@@ -75,7 +75,7 @@ class Select2MaritalStatusType extends AbstractType
$resolver->setDefaults(array(
'class' => 'Chill\PersonBundle\Entity\MaritalStatus',
'choices' => $choices
'choices' => array_combine(array_values($choices),array_keys($choices))
));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment