mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
PersonHistoryFile -> AccompanyingPeriod - refs #275
This commit is contained in:
parent
58d05123bb
commit
8d5d2189f1
@ -1,13 +1,33 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||||
|
* <http://www.champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Controller;
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Form\PersonHistoryFileType;
|
use Chill\PersonBundle\Form\AccompanyingPeriodType;
|
||||||
use Chill\PersonBundle\Entity\PersonHistoryFile;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
|
||||||
class HistoryController extends Controller
|
class AccompanyingPeriodController extends Controller
|
||||||
{
|
{
|
||||||
public function listAction($person_id){
|
public function listAction($person_id){
|
||||||
|
|
||||||
@ -17,8 +37,8 @@ class HistoryController extends Controller
|
|||||||
return $this->createNotFoundException('Person not found');
|
return $this->createNotFoundException('Person not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:History:list.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig',
|
||||||
array('histories' => $person->getHistoriesOrdered(),
|
array('accompanying_periods' => $person->getAccompanyingPeriodsOrdered(),
|
||||||
'person' => $person));
|
'person' => $person));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -30,14 +50,14 @@ class HistoryController extends Controller
|
|||||||
return $this->createNotFoundException('Person not found');
|
return $this->createNotFoundException('Person not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$history = new PersonHistoryFile(new \DateTime());
|
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
|
||||||
$history->setPerson($person)
|
$accompanyingPeriod->setPerson($person)
|
||||||
->setDateOpening(new \DateTime())
|
->setDateOpening(new \DateTime())
|
||||||
->setDateClosing(new \DateTime());
|
->setDateClosing(new \DateTime());
|
||||||
|
|
||||||
|
|
||||||
$form = $this->createForm(new PersonHistoryFileType(),
|
$form = $this->createForm(new AccompanyingPeriodType(),
|
||||||
$history, array('period_action' => 'update'));
|
$accompanyingPeriod, array('period_action' => 'update'));
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
@ -53,20 +73,20 @@ class HistoryController extends Controller
|
|||||||
&& count($errors) === 0) {
|
&& count($errors) === 0) {
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
$em->persist($history);
|
$em->persist($accompanyingPeriod);
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
$flashBag->add('success',
|
$flashBag->add('success',
|
||||||
$this->get('translator')->trans(
|
$this->get('translator')->trans(
|
||||||
'History created!'));
|
'Period created!'));
|
||||||
|
|
||||||
return $this->redirect($this->generateUrl('chill_person_history_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('danger', $this->get('translator')
|
$flashBag->add('danger', $this->get('translator')
|
||||||
->trans('Error! History 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());
|
||||||
@ -76,30 +96,30 @@ class HistoryController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:History:form.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
||||||
array(
|
array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'person' => $person,
|
'person' => $person,
|
||||||
'history' => $history
|
'accompanying_period' => $accompanyingPeriod
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateAction($history_id){
|
public function updateAction($person_id, $period_id){
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
$history = $em->getRepository('ChillPersonBundle:PersonHistoryFile')
|
$accompanyingPeriod = $em->getRepository('ChillPersonBundle:AccompanyingPeriod')
|
||||||
->find($history_id);
|
->find($period_id);
|
||||||
|
|
||||||
if ($history === null) {
|
if ($accompanyingPeriod === null) {
|
||||||
return $this->createNotFoundException("history with id ".$history_id.
|
return $this->createNotFoundException("Period with id ".$period_id.
|
||||||
" is not found");
|
" is not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
$person = $history->getPerson();
|
$person = $accompanyingPeriod->getPerson();
|
||||||
|
|
||||||
$form = $this->createForm(new PersonHistoryFileType(),
|
$form = $this->createForm(new AccompanyingPeriodType(),
|
||||||
$history, array('period_action' => 'update'));
|
$accompanyingPeriod, array('period_action' => 'update'));
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
@ -117,14 +137,14 @@ class HistoryController extends Controller
|
|||||||
|
|
||||||
$flashBag->add('success',
|
$flashBag->add('success',
|
||||||
$this->get('translator')->trans(
|
$this->get('translator')->trans(
|
||||||
'Updating history done'));
|
'Period updating done'));
|
||||||
|
|
||||||
return $this->redirect($this->generateUrl('chill_person_history_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('danger', $this->get('translator')
|
$flashBag->add('danger', $this->get('translator')
|
||||||
->trans('Error when updating history'));
|
->trans('Error when updating the period'));
|
||||||
|
|
||||||
foreach($errors as $error) {
|
foreach($errors as $error) {
|
||||||
$flashBag->add('info', $error->getMessage());
|
$flashBag->add('info', $error->getMessage());
|
||||||
@ -134,11 +154,11 @@ class HistoryController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:History:form.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
||||||
array(
|
array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'person' => $person,
|
'person' => $person,
|
||||||
'history' => $history
|
'accompanying_period' => $accompanyingPeriod
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,18 +172,18 @@ class HistoryController extends Controller
|
|||||||
if ($person->isOpen() === false) {
|
if ($person->isOpen() === false) {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('danger', $this->get('translator')
|
->add('danger', $this->get('translator')
|
||||||
->trans('Beware history 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_history_list', array(
|
$this->generateUrl('chill_person_accompanying_period_list', array(
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$current = $person->getCurrentHistory();
|
$current = $person->getCurrentAccompanyingPeriod();
|
||||||
|
|
||||||
$form = $this->createForm(new PersonHistoryFileType(), $current, array(
|
$form = $this->createForm(new AccompanyingPeriodType(), $current, array(
|
||||||
'period_action' => 'close'
|
'period_action' => 'close'
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -179,47 +199,38 @@ class HistoryController extends Controller
|
|||||||
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('History closed!',
|
->trans('Period closed!',
|
||||||
array('%name%' => $person->__toString())));
|
array('%name%' => $person->__toString())));
|
||||||
|
|
||||||
$this->getDoctrine()->getManager()->flush();
|
$this->getDoctrine()->getManager()->flush();
|
||||||
|
|
||||||
return $this->redirect(
|
return $this->redirect(
|
||||||
$this->generateUrl('chill_person_history_list', array(
|
$this->generateUrl('chill_person_accompanying_period_list', array(
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('danger', $this->get('translator')
|
->add('danger', $this->get('translator')
|
||||||
->trans('Error! History 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { //if form is not valid
|
} else { //if form is not valid
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('danger', $this->get('translator')
|
->add('danger', $this->get('translator')
|
||||||
->trans('History closing form is not valide'));
|
->trans('Pediod closing form is not valide'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:History:form.html.twig',
|
|
||||||
array(
|
array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'person' => $person,
|
'person' => $person,
|
||||||
'history' => $current
|
'accompanying_period' => $current
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,10 +242,10 @@ class HistoryController extends Controller
|
|||||||
private function _validatePerson(Person $person) {
|
private function _validatePerson(Person $person) {
|
||||||
$errors = $this->get('validator')->validate($person,
|
$errors = $this->get('validator')->validate($person,
|
||||||
array('Default'));
|
array('Default'));
|
||||||
$errors_history = $this->get('validator')->validate($person,
|
$errors_accompanying_period = $this->get('validator')->validate($person,
|
||||||
array('history_consistent'));
|
array('history_consistent'));
|
||||||
|
|
||||||
foreach($errors_history as $error ) {
|
foreach($errors_accompanying_period as $error ) {
|
||||||
$errors->add($error);
|
$errors->add($error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,45 +266,45 @@ class HistoryController extends Controller
|
|||||||
if ($person->isOpen() === true) {
|
if ($person->isOpen() === true) {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('danger', $this->get('translator')
|
->add('danger', $this->get('translator')
|
||||||
->trans('Error! History %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_history_list', array(
|
$this->generateUrl('chill_person_accompanying_period_list', array(
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$history = new PersonHistoryFile(new \DateTime());
|
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
|
||||||
|
|
||||||
$form = $this->createForm(new PersonHistoryFileType(), $history, array(
|
$form = $this->createForm(new AccompanyingPeriodType(),
|
||||||
'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($history);
|
$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('History %name% opened!',
|
->trans('Period %name% opened!',
|
||||||
array('%name%' => $person->__toString())));
|
array('%name%' => $person->__toString())));
|
||||||
|
|
||||||
$this->getDoctrine()->getManager()->flush();
|
$this->getDoctrine()->getManager()->flush();
|
||||||
|
|
||||||
return $this->redirect(
|
return $this->redirect(
|
||||||
$this->generateUrl('chill_person_history_list', array(
|
$this->generateUrl('chill_person_accompanying_period_list', array(
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('danger', $this->get('translator')
|
->add('danger', $this->get('translator')
|
||||||
->trans('History not opened'));
|
->trans('Period not opened'));
|
||||||
|
|
||||||
foreach ($errors as $error) {
|
foreach ($errors as $error) {
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
@ -304,16 +315,15 @@ class HistoryController extends Controller
|
|||||||
} else { // if errors in forms
|
} else { // if errors in forms
|
||||||
$this->get('session')->getFlashBag()
|
$this->get('session')->getFlashBag()
|
||||||
->add('danger', $this->get('translator')
|
->add('danger', $this->get('translator')
|
||||||
->trans('History not opened : form is invalid'));
|
->trans('Period not opened : form is invalid'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:History:form.html.twig',
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:form.html.twig',
|
||||||
array(
|
array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'person' => $person,
|
'person' => $person,
|
||||||
'history' => $history
|
'accompanying_period' => $accompanyingPeriod
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* Chill is a software for social workers
|
* Chill is a software for social workers
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, <http://www.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
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@ -223,20 +223,20 @@ class PersonController extends Controller
|
|||||||
* @param \Chill\PersonBundle\Entity\Person $person
|
* @param \Chill\PersonBundle\Entity\Person $person
|
||||||
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
|
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
|
||||||
*/
|
*/
|
||||||
private function _validatePersonAndHistory(Person $person)
|
private function _validatePersonAndAccompanyingPeriod(Person $person)
|
||||||
{
|
{
|
||||||
$errors = $this->get('validator')
|
$errors = $this->get('validator')
|
||||||
->validate($person, array('creation'));
|
->validate($person, array('creation'));
|
||||||
|
|
||||||
//validate history
|
//validate accompanying periods
|
||||||
$histories = $person->getHistories();
|
$periods = $person->getAccompanyingPeriods();
|
||||||
|
|
||||||
foreach ($histories as $history) {
|
foreach ($periods as $period) {
|
||||||
$errors_history = $this->get('validator')
|
$period_errors = $this->get('validator')
|
||||||
->validate($history);
|
->validate($period);
|
||||||
|
|
||||||
//group errors :
|
//group errors :
|
||||||
foreach($errors_history as $error) {
|
foreach($period_errors as $error) {
|
||||||
$errors->add($error);
|
$errors->add($error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ class PersonController extends Controller
|
|||||||
|
|
||||||
$person = $this->_bindCreationForm($form);
|
$person = $this->_bindCreationForm($form);
|
||||||
|
|
||||||
$errors = $this->_validatePersonAndHistory($person);
|
$errors = $this->_validatePersonAndAccompanyingPeriod($person);
|
||||||
|
|
||||||
if ( count($errors) > 0) {
|
if ( count($errors) > 0) {
|
||||||
$flashBag = $this->get('session')->getFlashBag();
|
$flashBag = $this->get('session')->getFlashBag();
|
||||||
@ -339,7 +339,7 @@ class PersonController extends Controller
|
|||||||
|
|
||||||
$person = $this->_bindCreationForm($form);
|
$person = $this->_bindCreationForm($form);
|
||||||
|
|
||||||
$errors = $this->_validatePersonAndHistory($person);
|
$errors = $this->_validatePersonAndAccompanyingPeriod($person);
|
||||||
|
|
||||||
if ($errors->count() === 0) {
|
if ($errors->count() === 0) {
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
@ -1,14 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||||
|
* <http://www.champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Entity;
|
namespace Chill\PersonBundle\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PersonHistoryFile
|
* AccompanyingPeriod
|
||||||
*/
|
*/
|
||||||
class PersonHistoryFile
|
class AccompanyingPeriod
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var integer
|
* @var integer
|
||||||
@ -44,7 +64,7 @@ class PersonHistoryFile
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param \DateTime $dateOpening
|
* @param \DateTime $dateOpening
|
||||||
* @uses PersonHistoryFile::setDateClosing()
|
* @uses AccompanyingPeriod::setDateClosing()
|
||||||
*/
|
*/
|
||||||
public function __construct(\DateTime $dateOpening) {
|
public function __construct(\DateTime $dateOpening) {
|
||||||
$this->setDateOpening($dateOpening);
|
$this->setDateOpening($dateOpening);
|
||||||
@ -65,7 +85,7 @@ class PersonHistoryFile
|
|||||||
* Set date_opening
|
* Set date_opening
|
||||||
*
|
*
|
||||||
* @param \DateTime $dateOpening
|
* @param \DateTime $dateOpening
|
||||||
* @return PersonHistoryFile
|
* @return AccompanyingPeriod
|
||||||
*/
|
*/
|
||||||
public function setDateOpening($dateOpening)
|
public function setDateOpening($dateOpening)
|
||||||
{
|
{
|
||||||
@ -90,7 +110,7 @@ class PersonHistoryFile
|
|||||||
* For closing a Person file, you should use Person::setClosed instead.
|
* For closing a Person file, you should use Person::setClosed instead.
|
||||||
*
|
*
|
||||||
* @param \DateTime $dateClosing
|
* @param \DateTime $dateClosing
|
||||||
* @return PersonHistoryFile
|
* @return AccompanyingPeriod
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function setDateClosing($dateClosing)
|
public function setDateClosing($dateClosing)
|
||||||
@ -126,7 +146,7 @@ class PersonHistoryFile
|
|||||||
* Set memo
|
* Set memo
|
||||||
*
|
*
|
||||||
* @param string $memo
|
* @param string $memo
|
||||||
* @return PersonHistoryFile
|
* @return AccompanyingPeriod
|
||||||
*/
|
*/
|
||||||
public function setMemo($memo)
|
public function setMemo($memo)
|
||||||
{
|
{
|
||||||
@ -152,11 +172,11 @@ class PersonHistoryFile
|
|||||||
/**
|
/**
|
||||||
* Set person.
|
* Set person.
|
||||||
*
|
*
|
||||||
* For consistency, you should use Person::addHistoryFile instead.
|
* For consistency, you should use Person::addAccompanyingPeriod instead.
|
||||||
*
|
*
|
||||||
* @param \Chill\PersonBundle\Entity\Person $person
|
* @param \Chill\PersonBundle\Entity\Person $person
|
||||||
* @return PersonHistoryFile
|
* @return AccompanyingPeriod
|
||||||
* @see Person::addHistoryFile
|
* @see Person::addAccompanyingPeriod
|
||||||
*/
|
*/
|
||||||
public function setPerson(\Chill\PersonBundle\Entity\Person $person = null)
|
public function setPerson(\Chill\PersonBundle\Entity\Person $person = null)
|
||||||
{
|
{
|
||||||
@ -196,19 +216,19 @@ class PersonHistoryFile
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isClosingAfterOpening() === false) {
|
if (! $this->isClosingAfterOpening()) {
|
||||||
$context->addViolationAt('dateClosing',
|
$context->addViolationAt('dateClosing',
|
||||||
'validation.PersonHistoryFile.constraint.dateOfClosing_before_dateOfOpening',
|
'validation.PersonHistoryFile.constraint.dateOfClosing_before_dateOfOpening',
|
||||||
array(), null);
|
array(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns true if the closing date is after the opening date.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isClosingAfterOpening() {
|
public function isClosingAfterOpening() {
|
||||||
|
|
||||||
$diff = $this->getDateOpening()->diff($this->getDateClosing());
|
$diff = $this->getDateOpening()->diff($this->getDateClosing());
|
||||||
|
|
||||||
if ($diff->invert === 0) {
|
if ($diff->invert === 0) {
|
||||||
@ -216,6 +236,5 @@ class PersonHistoryFile
|
|||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,12 +5,13 @@ namespace Chill\PersonBundle\Entity;
|
|||||||
/*
|
/*
|
||||||
* Chill is a software for social workers
|
* Chill is a software for social workers
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||||
|
* <http://www.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
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
* License, or (at your option) any later version.
|
* License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
@ -120,65 +121,65 @@ class Person {
|
|||||||
$opening = new \DateTime();
|
$opening = new \DateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->open(new PersonHistoryFile($opening));
|
$this->open(new AccompanyingPeriod($opening));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param \Chill\PersonBundle\Entity\PersonHistoryFile $history
|
* @param \Chill\PersonBundle\Entity\AccompanyingPeriod $period
|
||||||
* @uses PersonHistoryFile::setPerson
|
* @uses AccompanyingPeriod::setPerson
|
||||||
*/
|
*/
|
||||||
public function addHistoryFile(PersonHistoryFile $history) {
|
public function addAccompanyingPeriod(AccompanyingPeriod $period) {
|
||||||
$history->setPerson($this);
|
$period->setPerson($this);
|
||||||
$this->history->add($history);
|
$this->history->add($period);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the Person file as open at the given date.
|
* set the Person file as open at the given date.
|
||||||
*
|
*
|
||||||
* For updating a opening's date, you should update PersonHistoryFile instance
|
* For updating a opening's date, you should update AccompanyingPeriod instance
|
||||||
* directly.
|
* directly.
|
||||||
*
|
*
|
||||||
* For closing a file, @see this::close
|
* For closing a file, @see this::close
|
||||||
*
|
*
|
||||||
* To check if the Person and his history is consistent, use validation.
|
* To check if the Person and its accompanying period is consistent, use validation.
|
||||||
*
|
*
|
||||||
* @param \DateTime $date
|
* @param \Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod
|
||||||
*/
|
*/
|
||||||
public function open(PersonHistoryFile $accompanyingPeriod) {
|
public function open(AccompanyingPeriod $accompanyingPeriod) {
|
||||||
$this->proxyHistoryOpenState = true;
|
$this->proxyHistoryOpenState = true;
|
||||||
$this->addHistoryFile($accompanyingPeriod);
|
$this->addAccompanyingPeriod($accompanyingPeriod);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Set the Person file as closed at the given date.
|
* Set the Person file as closed at the given date.
|
||||||
*
|
*
|
||||||
* For update a closing date, you should update PersonHistoryFile instance
|
* For update a closing date, you should update AccompanyingPeriod instance
|
||||||
* directly.
|
* directly.
|
||||||
*
|
*
|
||||||
* To check if the Person and his history are consistent, use validation.
|
* To check if the Person and its accompanying period are consistent, use validation.
|
||||||
*
|
*
|
||||||
* @param PersonHistoryFile
|
* @param AccompanyingPeriod
|
||||||
* @throws \Exception if two lines of history are open.
|
* @throws \Exception if two lines of the accompanying period are open.
|
||||||
*/
|
*/
|
||||||
public function close(PersonHistoryFile $accompanyingPeriod)
|
public function close(AccompanyingPeriod $accompanyingPeriod)
|
||||||
{
|
{
|
||||||
$this->proxyHistoryOpenState = false;
|
$this->proxyHistoryOpenState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return null|PersonHistoryFile
|
* @return null|AccompanyingPeriod
|
||||||
*/
|
*/
|
||||||
public function getCurrentHistory() {
|
public function getCurrentAccompanyingPeriod() {
|
||||||
if ($this->proxyHistoryOpenState === false) {
|
if ($this->proxyHistoryOpenState === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->history as $history) {
|
foreach ($this->history as $period) {
|
||||||
if ($history->isOpen()) {
|
if ($period->isOpen()) {
|
||||||
return $history;
|
return $period;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,19 +188,19 @@ class Person {
|
|||||||
*
|
*
|
||||||
* @return \Doctrine\Common\Collections\ArrayCollection
|
* @return \Doctrine\Common\Collections\ArrayCollection
|
||||||
*/
|
*/
|
||||||
public function getHistories() {
|
public function getAccompanyingPeriods() {
|
||||||
return $this->history;
|
return $this->history;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return PersonHistoryFile[]
|
* @return AccompanyingPeriod[]
|
||||||
*/
|
*/
|
||||||
public function getHistoriesOrdered() {
|
public function getAccompanyingPeriodsOrdered() {
|
||||||
$histories = $this->getHistories()->toArray();
|
$periods = $this->getAccompanyingPeriods()->toArray();
|
||||||
|
|
||||||
//order by date :
|
//order by date :
|
||||||
usort($histories, function($a, $b) {
|
usort($periods, function($a, $b) {
|
||||||
|
|
||||||
$dateA = $a->getDateOpening();
|
$dateA = $a->getDateOpening();
|
||||||
$dateB = $b->getDateOpening();
|
$dateB = $b->getDateOpening();
|
||||||
@ -227,7 +228,7 @@ class Person {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return $histories;
|
return $periods;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isOpen() {
|
public function isOpen() {
|
||||||
@ -370,10 +371,11 @@ class Person {
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getGenreNumeric() {
|
public function getGenreNumeric() {
|
||||||
if ($this->getGenre() == self::GENRE_WOMAN)
|
if ($this->getGenre() == self::GENRE_WOMAN) {
|
||||||
return 1;
|
return 1;
|
||||||
else
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -390,11 +392,8 @@ class Person {
|
|||||||
|
|
||||||
if ($this->memo !== $memo) {
|
if ($this->memo !== $memo) {
|
||||||
$this->memo = $memo;
|
$this->memo = $memo;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,112 +559,96 @@ class Person {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// VALIDATION
|
// VALIDATION
|
||||||
public function isHistoryValid(ExecutionContextInterface $context) {
|
public function isAccompanyingPeriodValid(ExecutionContextInterface $context) {
|
||||||
$r = $this->checkHistoryIsNotCovering();
|
$r = $this->checkAccompanyingPeriodIsNotCovering();
|
||||||
|
|
||||||
|
|
||||||
if ($r !== true) {
|
if ($r !== true) {
|
||||||
|
|
||||||
if ($r['result'] === self::ERROR_OPENING_NOT_CLOSED_IS_BEFORE_NEW_LINE) {
|
if ($r['result'] === self::ERROR_OPENING_NOT_CLOSED_IS_BEFORE_NEW_LINE) {
|
||||||
$context->addViolationAt('history',
|
$context->addViolationAt('history',
|
||||||
'History not closed is before the new line',
|
'Accompanying period not closed is before the new line',
|
||||||
array() );
|
array() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$context->addViolationAt('history',
|
$context->addViolationAt('history', 'Periods are collapsing',
|
||||||
'Periods are collapsing',
|
array(
|
||||||
array(
|
'%dateOpening%' => $r['dateOpening']->format('d-m-Y'),
|
||||||
'%dateOpening%' => $r['dateOpening']->format('d-m-Y'),
|
'%dateClosing%' => $r['dateClosing']->format('d-m-Y'),
|
||||||
'%dateClosing%' => $r['dateClosing']->format('d-m-Y'),
|
'%date%' => $r['date']->format('d-m-Y')
|
||||||
'%date%' => $r['date']->format('d-m-Y')
|
)
|
||||||
)
|
);
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const ERROR_OPENING_IS_INSIDE_CLOSING = 1;
|
const ERROR_OPENING_IS_INSIDE_CLOSING = 1;
|
||||||
const ERROR_OPENING_NOT_CLOSED_IS_BEFORE_NEW_LINE = 2;
|
const ERROR_OPENING_NOT_CLOSED_IS_BEFORE_NEW_LINE = 2;
|
||||||
const ERROR_OPENING_NOT_CLOSE_IS_INSIDE_CLOSED_HISTORY_LINE = 3;
|
const ERROR_OPENING_NOT_CLOSE_IS_INSIDE_CLOSED_ACCOMPANYING_PERIOD_LINE = 3;
|
||||||
const ERROR_OPENING_IS_BEFORE_OTHER_LINE_AND_CLOSED_IS_AFTER_THIS_LINE = 4;
|
const ERROR_OPENING_IS_BEFORE_OTHER_LINE_AND_CLOSED_IS_AFTER_THIS_LINE = 4;
|
||||||
|
|
||||||
public function checkHistoryIsNotCovering() {
|
public function checkAccompanyingPeriodIsNotCovering()
|
||||||
|
{
|
||||||
|
$periods = $this->getAccompanyingPeriodsOrdered();
|
||||||
|
|
||||||
$histories = $this->getHistoriesOrdered();
|
$i = 0;
|
||||||
|
|
||||||
|
|
||||||
//check order :
|
|
||||||
$oldOpening = array();
|
|
||||||
$oldClosing = array();
|
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
foreach ($histories as $key => $history) {
|
foreach ($periods as $key => $period) {
|
||||||
//history is open : we must check the arent any history after
|
//accompanying period is open : we must check the arent any period after
|
||||||
if ($history->isOpen()) {
|
if ($period->isOpen()) {
|
||||||
foreach ($histories as $subKey => $against) {
|
foreach ($periods as $subKey => $against) {
|
||||||
//if we are checking the same, continue
|
//if we are checking the same, continue
|
||||||
if ($key === $subKey) {
|
if ($key === $subKey) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($history->getDateOpening() > $against->getDateOpening()
|
if ($period->getDateOpening() > $against->getDateOpening()
|
||||||
&& $history->getDateOpening() < $against->getDateOpening()) {
|
&& $period->getDateOpening() < $against->getDateOpening()) {
|
||||||
// the history date opening is inside another opening line
|
// the period date opening is inside another opening line
|
||||||
return array(
|
return array(
|
||||||
'result' => self::ERROR_OPENING_NOT_CLOSE_IS_INSIDE_CLOSED_HISTORY_LINE,
|
'result' => self::ERROR_OPENING_NOT_CLOSE_IS_INSIDE_CLOSED_ACCOMPANYING_PERIOD_LINE,
|
||||||
'dateOpening' => $against->getDateOpening(),
|
'dateOpening' => $against->getDateOpening(),
|
||||||
'dateClosing' => $against->getDateClosing(),
|
'dateClosing' => $against->getDateClosing(),
|
||||||
'date' => $history->getDateOpening()
|
'date' => $period->getDateOpening()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($history->getDateOpening() < $against->getDateOpening()
|
if ($period->getDateOpening() < $against->getDateOpening()
|
||||||
&& $history->getDateClosing() > $against->getDateClosing()) {
|
&& $period->getDateClosing() > $against->getDateClosing()) {
|
||||||
// the history date opening is inside another opening line
|
// the period date opening is inside another opening line
|
||||||
return array(
|
return array(
|
||||||
'result' => self::ERROR_OPENING_IS_BEFORE_OTHER_LINE_AND_CLOSED_IS_AFTER_THIS_LINE,
|
'result' => self::ERROR_OPENING_IS_BEFORE_OTHER_LINE_AND_CLOSED_IS_AFTER_THIS_LINE,
|
||||||
'dateOpening' => $against->getDateOpening(),
|
'dateOpening' => $against->getDateOpening(),
|
||||||
'dateClosing' => $against->getDateClosing(),
|
'dateClosing' => $against->getDateClosing(),
|
||||||
'date' => $history->getDateOpening()
|
'date' => $period->getDateOpening()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if we have an aopening later...
|
//if we have an aopening later...
|
||||||
if ($history->getDateOpening() < $against->getDateClosing()) {
|
if ($period->getDateOpening() < $against->getDateClosing()) {
|
||||||
return array( 'result' => self::ERROR_OPENING_NOT_CLOSED_IS_BEFORE_NEW_LINE,
|
return array( 'result' => self::ERROR_OPENING_NOT_CLOSED_IS_BEFORE_NEW_LINE,
|
||||||
'dateOpening' => $against->getDateOpening(),
|
'dateOpening' => $against->getDateOpening(),
|
||||||
'dateClosing' => $against->getDateClosing(),
|
'dateClosing' => $against->getDateClosing(),
|
||||||
'date' => $history->getDateOpening()
|
'date' => $period->getDateOpening()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
}
|
//we must check there is not covering lines
|
||||||
|
|
||||||
} else {
|
foreach ($periods as $subKey => $against) {
|
||||||
//we must check there is not covering lines
|
//check if dateOpening is inside an `against` line
|
||||||
|
if ($period->getDateOpening() > $against->getDateOpening()
|
||||||
foreach ($histories as $subKey => $against) {
|
&& $period->getDateOpening() < $against->getDateClosing()) {
|
||||||
//check if dateOpening is inside an `against` line
|
return array(
|
||||||
if ($history->getDateOpening() > $against->getDateOpening()
|
|
||||||
&& $history->getDateOpening() < $against->getDateClosing()) {
|
|
||||||
return array(
|
|
||||||
'result' => self::ERROR_OPENING_IS_INSIDE_CLOSING,
|
'result' => self::ERROR_OPENING_IS_INSIDE_CLOSING,
|
||||||
'dateOpening' => $against->getDateOpening(),
|
'dateOpening' => $against->getDateOpening(),
|
||||||
'dateClosing' => $against->getDateClosing(),
|
'dateClosing' => $against->getDateClosing(),
|
||||||
'date' => $history->getDateOpening()
|
'date' => $period->getDateOpening()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,17 +8,14 @@ use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
|||||||
use Symfony\Component\Form\FormEvents;
|
use Symfony\Component\Form\FormEvents;
|
||||||
use Symfony\Component\Form\FormEvent;
|
use Symfony\Component\Form\FormEvent;
|
||||||
|
|
||||||
class PersonHistoryFileType extends AbstractType
|
class AccompanyingPeriodType extends AbstractType
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param FormBuilderInterface $builder
|
* @param FormBuilderInterface $builder
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*/
|
*/
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
|
|
||||||
//if the period_action is close, date opening should not be seen
|
//if the period_action is close, date opening should not be seen
|
||||||
if ($options['period_action'] !== 'close') {
|
if ($options['period_action'] !== 'close') {
|
||||||
$builder
|
$builder
|
||||||
@ -39,7 +36,7 @@ class PersonHistoryFileType extends AbstractType
|
|||||||
($options['period_action'] === 'close')
|
($options['period_action'] === 'close')
|
||||||
OR
|
OR
|
||||||
($options['period_action'] === 'update' AND !$accompanyingPeriod->isOpen())
|
($options['period_action'] === 'update' AND !$accompanyingPeriod->isOpen())
|
||||||
){
|
) {
|
||||||
$form->add('date_closing', 'date', array('required' => true,
|
$form->add('date_closing', 'date', array('required' => true,
|
||||||
'widget' => 'single_text'));
|
'widget' => 'single_text'));
|
||||||
$form->add('closingMotive', 'closing_motive');
|
$form->add('closingMotive', 'closing_motive');
|
||||||
@ -58,15 +55,14 @@ class PersonHistoryFileType extends AbstractType
|
|||||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||||
{
|
{
|
||||||
$resolver->setDefaults(array(
|
$resolver->setDefaults(array(
|
||||||
'data_class' => 'Chill\PersonBundle\Entity\PersonHistoryFile'
|
'data_class' => 'Chill\PersonBundle\Entity\AccompanyingPeriod'
|
||||||
));
|
));
|
||||||
|
|
||||||
$resolver
|
$resolver
|
||||||
->setRequired(array('period_action'))
|
->setRequired(array('period_action'))
|
||||||
->addAllowedTypes(array('period_action' => 'string'))
|
->addAllowedTypes(array('period_action' => 'string'))
|
||||||
->addAllowedValues(array('period_action' => array(
|
->addAllowedValues(array('period_action' => array(
|
||||||
'update', 'open', 'close')))
|
'update', 'open', 'close')));
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,6 +70,6 @@ class PersonHistoryFileType extends AbstractType
|
|||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return 'cl_chill_personbundle_personhistoryfile';
|
return 'chill_personbundle_accompanyingperiod';
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
Chill\PersonBundle\Entity\PersonHistoryFile:
|
Chill\PersonBundle\Entity\AccompanyingPeriod:
|
||||||
type: entity
|
type: entity
|
||||||
table: person_history_file
|
table: person_history_file
|
||||||
id:
|
id:
|
@ -45,30 +45,30 @@ chill_person_search:
|
|||||||
order: 30
|
order: 30
|
||||||
label: Search within persons
|
label: Search within persons
|
||||||
|
|
||||||
chill_person_history_list:
|
chill_person_accompanying_period_list:
|
||||||
pattern: /{_locale}/person/{person_id}/history
|
pattern: /{_locale}/person/{person_id}/accompanying-period
|
||||||
defaults: { _controller: ChillPersonBundle:History:list }
|
defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:list }
|
||||||
# options:
|
# options:
|
||||||
# menus:
|
# menus:
|
||||||
# person:
|
# person:
|
||||||
# order: 100
|
# order: 100
|
||||||
# label: menu.person.history
|
# label: menu.person.history
|
||||||
|
|
||||||
chill_person_history_create:
|
chill_person_accompanying_period_create:
|
||||||
pattern: /{_locale}/person/{person_id}/history/create
|
pattern: /{_locale}/person/{person_id}/accompanying-period/create
|
||||||
defaults: { _controller: ChillPersonBundle:History:create }
|
defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:create }
|
||||||
|
|
||||||
chill_person_history_update:
|
chill_person_accompanying_period_update:
|
||||||
pattern: /{_locale}/person/history/{history_id}/update
|
pattern: /{_locale}/person/{person_id}/accompanying-period/{period_id}/update
|
||||||
defaults: { _controller: ChillPersonBundle:History:update }
|
defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:update }
|
||||||
|
|
||||||
chill_person_history_close:
|
chill_person_accompanying_period_close:
|
||||||
pattern: /{_locale}/person/{person_id}/history/close
|
pattern: /{_locale}/person/{person_id}/accompanying-period/close
|
||||||
defaults: { _controller: ChillPersonBundle:History:close }
|
defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:close }
|
||||||
|
|
||||||
chill_person_history_open:
|
chill_person_accompanying_period_open:
|
||||||
pattern: /{_locale}/person/{person_id}/history/open
|
pattern: /{_locale}/person/{person_id}/accompanying-period/open
|
||||||
defaults: { _controller: ChillPersonBundle:History:open }
|
defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:open }
|
||||||
|
|
||||||
chill_person_admin:
|
chill_person_admin:
|
||||||
pattern: /{_locale}/admin/person
|
pattern: /{_locale}/admin/person
|
||||||
|
@ -30,7 +30,7 @@ Chill\PersonBundle\Entity\Person:
|
|||||||
traverse: true
|
traverse: true
|
||||||
constraints:
|
constraints:
|
||||||
- Callback:
|
- Callback:
|
||||||
methods: [isHistoryValid]
|
methods: [isAccompanyingPeriodValid]
|
||||||
groups: [history_consistent]
|
groups: [history_consistent]
|
||||||
|
|
||||||
Chill\PersonBundle\Entity\PersonHistoryFile:
|
Chill\PersonBundle\Entity\PersonHistoryFile:
|
||||||
|
@ -57,24 +57,13 @@ Reset: 'Remise à zéro'
|
|||||||
'Search within persons': 'Recherche parmi les personnes'
|
'Search within persons': 'Recherche parmi les personnes'
|
||||||
'%total% persons matching the search %pattern%': '{0} Aucune personne ne correspond aux termes de recherche "%pattern%" | {1} Une personne a été trouvée par la recherche "%pattern%" | ]1,Inf] %total% personnes correspondent aux termes de recherche "%pattern%".'
|
'%total% persons matching the search %pattern%': '{0} Aucune personne ne correspond aux termes de recherche "%pattern%" | {1} Une personne a été trouvée par la recherche "%pattern%" | ]1,Inf] %total% personnes correspondent aux termes de recherche "%pattern%".'
|
||||||
'Last opening since %last_opening%': 'Dernière ouverture le %last_opening%.'
|
'Last opening since %last_opening%': 'Dernière ouverture le %last_opening%.'
|
||||||
'Close person history': Clotûrer
|
'Close person accompanying period': Clotûrer
|
||||||
'Person history - %name%': 'Historique du dossier - %name%'
|
'Person accompanying period - %name%': 'Historique du dossier - %name%'
|
||||||
'Opening date': 'Date d''ouverture'
|
'Opening date': 'Date d''ouverture'
|
||||||
'Closing date': 'Date de fermeture'
|
'Closing date': 'Date de fermeture'
|
||||||
'Still open': 'Toujours en cours'
|
'Still open': 'Toujours en cours'
|
||||||
'Close history': 'Clôre le dossier'
|
'Close accompanying period': 'Clôre le dossier'
|
||||||
'Open history': 'Ouvrir le dossier'
|
'Open accompanying period': 'Ouvrir le dossier'
|
||||||
'Create history': 'Nouvel ouverture-fermeture à une autre date'
|
'Create accompanying period': 'Nouvel ouverture-fermeture à une autre date'
|
||||||
'Closing motive': 'Motif de clôture'
|
'Closing motive': 'Motif de clôture'
|
||||||
'History created!': 'Bravo ! Le dossier est maintenant ouvert.'
|
|
||||||
'Error! History not created!': 'Erreur ! Le dossier n''a pas pu être ouvert.'
|
|
||||||
'Updating history done': 'Bravo ! La mise à jour de l''historique a réussi !'
|
|
||||||
'Error when updating history': 'Les données introduites ne sont pas valides. Veuillez vérifier les informations ci-dessous.'
|
|
||||||
'Beware history is closed': 'Attention le dossier est déjà fermé'
|
|
||||||
'History closed!': 'Bravo ! Le dossier de <em>%name%</em> a été clotûré.'
|
|
||||||
'Error! History not closed!': 'Les informations introduites ne sont pas valides. Le dossier n''a pu être clos.'
|
|
||||||
'History closing form is not valide': 'Le formulaire n''est pas valide.'
|
|
||||||
'Error! History %name% is not closed ; it can be open': 'Le dossier de <em>%name%</em> n''est pas fermé. Il ne peut donc être ouvert.'
|
|
||||||
'History %name% opened!': 'Bravo ! Le dossier de <em>%name</em> a été ouvert'
|
|
||||||
'History not opened': 'Les informations introduites ne sont pas valides. Le dossier n''a pu être ouvert.'
|
|
||||||
'Person details': 'Détails de la personne'
|
'Person details': 'Détails de la personne'
|
||||||
|
@ -58,12 +58,12 @@ Reset: Delete
|
|||||||
'%total% persons matching the search %pattern%': '{0} Geen personen stemmen met het gezocht "%pattern%" overeen. | {1} Één persoon stemd met het gezocht "%pattern%" overeen. | ]1,Inf] %total% personen stemmen met het gezocht "%pattern%" overeen.'
|
'%total% persons matching the search %pattern%': '{0} Geen personen stemmen met het gezocht "%pattern%" overeen. | {1} Één persoon stemd met het gezocht "%pattern%" overeen. | ]1,Inf] %total% personen stemmen met het gezocht "%pattern%" overeen.'
|
||||||
'Person details': 'Details van de persoon'
|
'Person details': 'Details van de persoon'
|
||||||
'Last opening since %last_opening%': '__Last opening since %last_opening%'
|
'Last opening since %last_opening%': '__Last opening since %last_opening%'
|
||||||
'Close person history': '__Close person history'
|
'Close person accompanying period ': '__Close person accompanying period '
|
||||||
'Person history - %name%': '__Person history - %name%'
|
'Person accompanying period - %name%': '__Person accompanying period - %name%'
|
||||||
'Opening date': '__Opening date'
|
'Opening date': '__Opening date'
|
||||||
'Closing date': '__Closing date'
|
'Closing date': '__Closing date'
|
||||||
'Still open': '__Still open'
|
'Still open': '__Still open'
|
||||||
'Create history': '__Create history'
|
'Create accompanying period': '__Create accompanying period'
|
||||||
'Close history': '__Close history'
|
'Close accompanying period ': '__Close accompanying period '
|
||||||
'Open history': '__Open history'
|
'Open accompanying period': '__Open accompanying period'
|
||||||
'Unknown spoken languages': 'Spreektalen onbekend'
|
'Unknown spoken languages': 'Spreektalen onbekend'
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
|
|
||||||
{{ 'Last opening since %last_opening%'|trans(
|
{{ 'Last opening since %last_opening%'|trans(
|
||||||
{ '%last_opening%' : history.dateOpening|localizeddate('long', 'none', app.request.locale) }) }}
|
{ '%last_opening%' : accompanying_period.dateOpening|localizeddate('long', 'none', app.request.locale) }) }}
|
||||||
|
|
||||||
{% if form.dateClosing is defined %}
|
{% if form.dateClosing is defined %}
|
||||||
{{ form_row(form.dateClosing, {'label' : 'Closing date'} ) }}
|
{{ form_row(form.dateClosing, {'label' : 'Closing date'} ) }}
|
||||||
@ -25,7 +25,7 @@
|
|||||||
{{ form_rest(form) }}
|
{{ form_rest(form) }}
|
||||||
|
|
||||||
<div class="medium btn danger icon-right entypo icon-lock">
|
<div class="medium btn danger icon-right entypo icon-lock">
|
||||||
<button type="submit">{{ 'Close person history'|trans }}</button>
|
<button type="submit">{{ 'Close person accompanying period'|trans }}</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ form_end(form) }}
|
{{ form_end(form) }}
|
@ -1,8 +1,8 @@
|
|||||||
{% extends "ChillPersonBundle::layout.html.twig" %}
|
{% extends "ChillPersonBundle::layout.html.twig" %}
|
||||||
|
|
||||||
{% set activeRouteKey = 'chill_person_history_list' %}
|
{% set activeRouteKey = 'chill_person_accompanying_period_list' %}
|
||||||
|
|
||||||
{% block title %}{{ 'Person history - %name%'|trans({ '%name%' : person.__toString}) }}{% endblock title %}
|
{% block title %}{{ 'Person accompanying period - %name%'|trans({ '%name%' : person.__toString}) }}{% endblock title %}
|
||||||
|
|
||||||
{% block personcontent %}
|
{% block personcontent %}
|
||||||
<table class="rounded">
|
<table class="rounded">
|
||||||
@ -16,28 +16,28 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% set i = 0 %}
|
{% set i = 0 %}
|
||||||
{% for history in histories %}
|
{% for accompanying_period in accompanying_periods %}
|
||||||
<tr class="{% if i is not even %}striped{% endif %}">
|
<tr class="{% if i is not even %}striped{% endif %}">
|
||||||
<td>{{ history.dateOpening|localizeddate('long', 'none', app.request.locale) }}</td>
|
<td>{{ accompanying_period.dateOpening|localizeddate('long', 'none', app.request.locale) }}</td>
|
||||||
<td>{% spaceless %}
|
<td>{% spaceless %}
|
||||||
{% if history.isOpen %}
|
{% if accompanying_period.isOpen %}
|
||||||
{{ 'Still open'|trans }}
|
{{ 'Still open'|trans }}
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ history.dateClosing|localizeddate('long', 'none', app.request.locale) }}
|
{{ accompanying_period.dateClosing|localizeddate('long', 'none', app.request.locale) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endspaceless %}</td>
|
{% endspaceless %}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="small warning btn icon-right entypo icon-pencil">
|
<div class="small warning btn icon-right entypo icon-pencil">
|
||||||
<a href="{{ path('chill_person_history_update', {'person_id' : person.id, 'history_id' : history.id } ) }}">{{ 'Edit'|trans }}</a>
|
<a href="{{ path('chill_person_accompanying_period_update', {'person_id' : person.id, 'period_id' : accompanying_period.id } ) }}">{{ 'Edit'|trans }}</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if history.memo is not empty %}
|
{% if accompanying_period.memo is not empty %}
|
||||||
<tr class="{% if i is not even %}striped{% endif %}">
|
<tr class="{% if i is not even %}striped{% endif %}">
|
||||||
<td colspan="3">
|
<td colspan="3">
|
||||||
<pre>{{ history.memo }}</pre>
|
<pre>{{ accompanying_period.memo }}</pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -49,8 +49,8 @@
|
|||||||
|
|
||||||
<div class="form_control">
|
<div class="form_control">
|
||||||
<div class="btn small warning icon-right entypo icon-plus">
|
<div class="btn small warning icon-right entypo icon-plus">
|
||||||
<a href="{{ path ('chill_person_history_create', {'person_id' : person.id } ) }}">
|
<a href="{{ path ('chill_person_accompanying_period_create', {'person_id' : person.id } ) }}">
|
||||||
{{ 'Create history'|trans }}
|
{{ 'Create accompanying period'|trans }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -63,12 +63,12 @@
|
|||||||
{% endif %}{% endspaceless %}">
|
{% endif %}{% endspaceless %}">
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
{% if person.isOpen == true %}
|
{% if person.isOpen == true %}
|
||||||
<a href="{{ path('chill_person_history_close', {'person_id' : person.id}) }}">
|
<a href="{{ path('chill_person_accompanying_period_close', {'person_id' : person.id}) }}">
|
||||||
{{'Close history'|trans }}
|
{{'Close accompanying period'|trans }}
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ path('chill_person_history_open', {'person_id' : person.id} ) }}">
|
<a href="{{ path('chill_person_accompanying_period_open', {'person_id' : person.id} ) }}">
|
||||||
{{'Open history'|trans }}
|
{{'Open accompanying period'|trans }}
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endspaceless %}
|
{% endspaceless %}
|
101
Tests/Entity/AccompanyingPeriodTest.php
Normal file
101
Tests/Entity/AccompanyingPeriodTest.php
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||||
|
* <http://www.champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Tests\Entity;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
|
||||||
|
class AccompanyingPeriodTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testClosingIsAfterOpeningConsistency()
|
||||||
|
{
|
||||||
|
$datetime1 = new \DateTime('now');
|
||||||
|
$datetime2 = new \DateTime('tomorrow');
|
||||||
|
|
||||||
|
$period = new AccompanyingPeriod($datetime1);
|
||||||
|
$period->setDateClosing($datetime2);
|
||||||
|
|
||||||
|
$r = $period->isClosingAfterOpening();
|
||||||
|
|
||||||
|
$this->assertTrue($r);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClosingIsBeforeOpeningConsistency() {
|
||||||
|
$datetime1 = new \DateTime('tomorrow');
|
||||||
|
$datetime2 = new \DateTime('now');
|
||||||
|
|
||||||
|
$period = new AccompanyingPeriod($datetime1);
|
||||||
|
$period->setDateClosing($datetime2);
|
||||||
|
|
||||||
|
$this->assertFalse($period->isClosingAfterOpening());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClosingEqualOpening() {
|
||||||
|
$datetime = new \DateTime('now');
|
||||||
|
|
||||||
|
$period = new AccompanyingPeriod($datetime);
|
||||||
|
$period->setDateClosing($datetime);
|
||||||
|
|
||||||
|
$this->assertTrue($period->isClosingAfterOpening());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsOpen() {
|
||||||
|
$period = new AccompanyingPeriod(new \DateTime());
|
||||||
|
|
||||||
|
$this->assertTrue($period->isOpen());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsClosed() {
|
||||||
|
$period = new AccompanyingPeriod(new \DateTime());
|
||||||
|
$period->setDateClosing(new \DateTime('tomorrow'));
|
||||||
|
|
||||||
|
$this->assertFalse($period->isOpen());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test seems only to test ordering datetime... Maybe delete ?
|
||||||
|
*/
|
||||||
|
public function testOrder() {
|
||||||
|
$d = new \DateTime(); $d->setDate(2013, 2, 1);
|
||||||
|
$g = new \DateTime(); $g->setDate(2013, 4, 1);
|
||||||
|
$f = new \DateTime(); $f->setDate(2013, 1, 1);
|
||||||
|
$e = new \DateTime(); $e->setDate(2013,3,1);
|
||||||
|
|
||||||
|
$a = array($d, $g, $f, $e);
|
||||||
|
|
||||||
|
usort($a, function($a, $b) {
|
||||||
|
if ($a === $b) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($a < $b) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$date = $a[0]->format('Y-m-d');
|
||||||
|
|
||||||
|
$this->assertEquals($date, '2013-01-01');
|
||||||
|
}
|
||||||
|
}
|
@ -1,103 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Tests\Entity;
|
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\PersonHistoryFile;
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
|
||||||
|
|
||||||
class HistoryFileTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
public function testClosingIsAfterOpeningConsistency()
|
|
||||||
{
|
|
||||||
$datetime1 = new \DateTime('now');
|
|
||||||
|
|
||||||
$history = new PersonHistoryFile($datetime1);
|
|
||||||
|
|
||||||
|
|
||||||
$datetime2 = new \DateTime('tomorrow');
|
|
||||||
|
|
||||||
$history->setDateClosing($datetime2);
|
|
||||||
|
|
||||||
|
|
||||||
$r = $history->isClosingAfterOpening();
|
|
||||||
|
|
||||||
$this->assertTrue($r);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testClosingIsBeforeOpeningConsistency() {
|
|
||||||
$datetime1 = new \DateTime('tomorrow');
|
|
||||||
|
|
||||||
|
|
||||||
$history = new PersonHistoryFile($datetime1);
|
|
||||||
|
|
||||||
|
|
||||||
$datetime2 = new \DateTime('now');
|
|
||||||
|
|
||||||
$history->setDateClosing($datetime2);
|
|
||||||
|
|
||||||
$this->assertFalse($history->isClosingAfterOpening());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testClosingEqualOpening() {
|
|
||||||
$datetime = new \DateTime('now');
|
|
||||||
|
|
||||||
$history = new PersonHistoryFile($datetime);
|
|
||||||
$history->setDateClosing($datetime);
|
|
||||||
|
|
||||||
$this->assertTrue($history->isClosingAfterOpening());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsOpen() {
|
|
||||||
$history = new PersonHistoryFile(new \DateTime());
|
|
||||||
|
|
||||||
$this->assertTrue($history->isOpen());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsClosed() {
|
|
||||||
$history = new PersonHistoryFile(new \DateTime());
|
|
||||||
|
|
||||||
$history->setDateClosing(new \DateTime('tomorrow'));
|
|
||||||
|
|
||||||
$this->assertFalse($history->isOpen());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This test seems only to test ordering datetime... Maybe delete ?
|
|
||||||
*/
|
|
||||||
public function testOrder() {
|
|
||||||
$d = new \DateTime(); $d->setDate(2013, 2, 1);
|
|
||||||
$g = new \DateTime(); $g->setDate(2013, 4, 1);
|
|
||||||
$f = new \DateTime(); $f->setDate(2013, 1, 1);
|
|
||||||
$e = new \DateTime(); $e->setDate(2013,3,1);
|
|
||||||
|
|
||||||
$a = array($d, $g, $f, $e);
|
|
||||||
|
|
||||||
|
|
||||||
usort($a, function($a, $b) {
|
|
||||||
if ($a === $b) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($a < $b) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$date = $a[0]->format('Y-m-d');
|
|
||||||
|
|
||||||
$this->assertEquals($date, '2013-01-01');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Chill is a software for social workers
|
* Chill is a software for social workers
|
||||||
* Copyright (C) 2014 Julien Fastré <julien.fastre@champs-libres.coop>
|
* Copyright (C) 2014-2015 Champs-Libres Coopérative <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
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -21,7 +21,7 @@
|
|||||||
namespace Chill\PersonBundle\Tests\Entity;
|
namespace Chill\PersonBundle\Tests\Entity;
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Entity\PersonHistoryFile;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests on person
|
* Unit tests on person
|
||||||
@ -30,106 +30,102 @@ use Chill\PersonBundle\Entity\PersonHistoryFile;
|
|||||||
*/
|
*/
|
||||||
class PersonTest extends \PHPUnit_Framework_TestCase
|
class PersonTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testGetCurrentHistory()
|
public function testGetCurrentAccompanyingPeriod()
|
||||||
{
|
{
|
||||||
$d = new \DateTime('yesterday');
|
$d = new \DateTime('yesterday');
|
||||||
$p = new Person($d);
|
$p = new Person($d);
|
||||||
|
|
||||||
$history = $p->getCurrentHistory();
|
$period = $p->getCurrentAccompanyingPeriod();
|
||||||
|
|
||||||
$this->assertInstanceOf('Chill\PersonBundle\Entity\PersonHistoryFile', $history);
|
$this->assertInstanceOf('Chill\PersonBundle\Entity\AccompanyingPeriod', $period);
|
||||||
$this->assertTrue($history->isOpen());
|
$this->assertTrue($period->isOpen());
|
||||||
$this->assertEquals($d, $history->getDateOpening());
|
$this->assertEquals($d, $period->getDateOpening());
|
||||||
|
|
||||||
//close and test
|
//close and test
|
||||||
$history->setDateClosing(new \DateTime('tomorrow'));
|
$period->setDateClosing(new \DateTime('tomorrow'));
|
||||||
|
|
||||||
$shouldBeNull = $p->getCurrentHistory();
|
$shouldBeNull = $p->getCurrentAccompanyingPeriod();
|
||||||
$this->assertNull($shouldBeNull);
|
$this->assertNull($shouldBeNull);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHistoryOrderWithUnorderedHistory() {
|
public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod() {
|
||||||
$d = new \DateTime();
|
$d = new \DateTime();
|
||||||
$d->setDate(2013, 2, 1);
|
$d->setDate(2013, 2, 1);
|
||||||
$p = new Person($d);
|
$p = new Person($d);
|
||||||
|
|
||||||
$e = new \DateTime();
|
$e = new \DateTime();
|
||||||
$e->setDate(2013, 3, 1);
|
$e->setDate(2013, 3, 1);
|
||||||
$history = $p->getCurrentHistory()->setDateClosing($e);
|
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
|
||||||
$p->close($history);
|
$p->close($period);
|
||||||
|
|
||||||
$f = new \DateTime();
|
$f = new \DateTime();
|
||||||
$f->setDate(2013, 1, 1);
|
$f->setDate(2013, 1, 1);
|
||||||
$p->open(new PersonHistoryFile($f));
|
$p->open(new AccompanyingPeriod($f));
|
||||||
|
|
||||||
$g = new \DateTime();
|
$g = new \DateTime();
|
||||||
$g->setDate(2013, 4, 1);
|
$g->setDate(2013, 4, 1);
|
||||||
$history = $p->getCurrentHistory()->setDateClosing($g);
|
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g);
|
||||||
$p->close($history);
|
$p->close($period);
|
||||||
|
|
||||||
$r = $p->getHistoriesOrdered();
|
$r = $p->getAccompanyingPeriodsOrdered();
|
||||||
|
|
||||||
$date = $r[0]->getDateOpening()->format('Y-m-d');
|
$date = $r[0]->getDateOpening()->format('Y-m-d');
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals($date, '2013-01-01');
|
$this->assertEquals($date, '2013-01-01');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testHistoryOrderSameDateOpening() {
|
public function testAccompanyingPeriodOrderSameDateOpening() {
|
||||||
$d = new \DateTime();
|
$d = new \DateTime();
|
||||||
$d->setDate(2013, 2, 1);
|
$d->setDate(2013, 2, 1);
|
||||||
$p = new Person($d);
|
$p = new Person($d);
|
||||||
|
|
||||||
$e = new \DateTime();
|
$e = new \DateTime();
|
||||||
$e->setDate(2013, 3, 1);
|
$e->setDate(2013, 3, 1);
|
||||||
$history = $p->getCurrentHistory()->setDateClosing($e);
|
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
|
||||||
$p->close($history);
|
$p->close($period);
|
||||||
|
|
||||||
$f = new \DateTime();
|
$f = new \DateTime();
|
||||||
$f->setDate(2013, 2, 1);
|
$f->setDate(2013, 2, 1);
|
||||||
$p->open(new PersonHistoryFile($f));
|
$p->open(new AccompanyingPeriod($f));
|
||||||
|
|
||||||
$g = new \DateTime();
|
$g = new \DateTime();
|
||||||
$g->setDate(2013, 4, 1);
|
$g->setDate(2013, 4, 1);
|
||||||
$history = $p->getCurrentHistory()->setDateClosing($g);
|
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g);
|
||||||
$p->close($history);
|
$p->close($period);
|
||||||
|
|
||||||
$r = $p->getHistoriesOrdered();
|
$r = $p->getAccompanyingPeriodsOrdered();
|
||||||
|
|
||||||
$date = $r[0]->getDateClosing()->format('Y-m-d');
|
$date = $r[0]->getDateClosing()->format('Y-m-d');
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals($date, '2013-03-01');
|
$this->assertEquals($date, '2013-03-01');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDateCoveringWithCoveringHistory() {
|
public function testDateCoveringWithCoveringAccompanyingPeriod() {
|
||||||
$d = new \DateTime();
|
$d = new \DateTime();
|
||||||
$d->setDate(2013, 2, 1);
|
$d->setDate(2013, 2, 1);
|
||||||
$p = new Person($d);
|
$p = new Person($d);
|
||||||
|
|
||||||
$e = new \DateTime();
|
$e = new \DateTime();
|
||||||
$e->setDate(2013, 3, 1);
|
$e->setDate(2013, 3, 1);
|
||||||
$history = $p->getCurrentHistory()->setDateClosing($e);
|
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
|
||||||
$p->close($history);
|
$p->close($period);
|
||||||
|
|
||||||
$f = new \DateTime();
|
$f = new \DateTime();
|
||||||
$f->setDate(2013, 1, 1);
|
$f->setDate(2013, 1, 1);
|
||||||
$p->open(new PersonHistoryFile($f));
|
$p->open(new AccompanyingPeriod($f));
|
||||||
|
|
||||||
$g = new \DateTime();
|
$g = new \DateTime();
|
||||||
$g->setDate(2013, 4, 1);
|
$g->setDate(2013, 4, 1);
|
||||||
$history = $p->getCurrentHistory()->setDateClosing($g);
|
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g);
|
||||||
$p->close($history);
|
$p->close($period);
|
||||||
|
|
||||||
$r = $p->checkHistoryIsNotCovering();
|
$r = $p->checkAccompanyingPeriodIsNotCovering();
|
||||||
|
|
||||||
$this->assertEquals($r['result'], Person::ERROR_OPENING_IS_INSIDE_CLOSING);
|
$this->assertEquals($r['result'], Person::ERROR_OPENING_IS_INSIDE_CLOSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function testNotOpenAFileReOpenedLater() {
|
public function testNotOpenAFileReOpenedLater() {
|
||||||
$d = new \DateTime();
|
$d = new \DateTime();
|
||||||
$d->setDate(2013, 2, 1);
|
$d->setDate(2013, 2, 1);
|
||||||
@ -137,15 +133,14 @@ class PersonTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$e = new \DateTime();
|
$e = new \DateTime();
|
||||||
$e->setDate(2013, 3, 1);
|
$e->setDate(2013, 3, 1);
|
||||||
$history = $p->getCurrentHistory()->setDateClosing($e);
|
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
|
||||||
$p->close($history);
|
$p->close($period);
|
||||||
|
|
||||||
$f = new \DateTime();
|
$f = new \DateTime();
|
||||||
$f->setDate(2013, 1, 1);
|
$f->setDate(2013, 1, 1);
|
||||||
$p->open(new PersonHistoryFile($f));
|
$p->open(new AccompanyingPeriod($f));
|
||||||
|
|
||||||
|
|
||||||
$r = $p->checkHistoryIsNotCovering();
|
$r = $p->checkAccompanyingPeriodIsNotCovering();
|
||||||
|
|
||||||
$this->assertEquals($r['result'], Person::ERROR_OPENING_NOT_CLOSED_IS_BEFORE_NEW_LINE);
|
$this->assertEquals($r['result'], Person::ERROR_OPENING_NOT_CLOSED_IS_BEFORE_NEW_LINE);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user