diff --git a/Controller/HistoryController.php b/Controller/HistoryController.php
index 0dabef2eb..52e7c80c1 100644
--- a/Controller/HistoryController.php
+++ b/Controller/HistoryController.php
@@ -9,9 +9,9 @@ use Chill\PersonBundle\Entity\PersonHistoryFile;
class HistoryController extends Controller
{
- public function listAction($id){
+ public function listAction($person_id){
- $person = $this->_getPerson($id);
+ $person = $this->_getPerson($person_id);
if ($person === null) {
return $this->createNotFoundException('Person not found');
@@ -23,21 +23,21 @@ class HistoryController extends Controller
}
- public function createAction($personId) {
- $person = $this->_getPerson($personId);
+ public function createAction($person_id) {
+ $person = $this->_getPerson($person_id);
if ($person === null) {
return $this->createNotFoundException('Person not found');
}
$history = new PersonHistoryFile(new \DateTime());
- $history->setPerson($person);
+ $history->setPerson($person)
+ ->setDateOpening(new \DateTime())
+ ->setDateClosing(new \DateTime());
- $motivesArray = $this->get('service_container')
- ->getParameter('person.history.close.motives');
- $form = $this->createForm(new PersonHistoryFileType($motivesArray),
- $history);
+ $form = $this->createForm(new PersonHistoryFileType(),
+ $history, array('period_action' => 'update'));
$request = $this->getRequest();
@@ -62,7 +62,7 @@ class HistoryController extends Controller
'controller.Person.history.create.done'));
return $this->redirect($this->generateUrl('chill_person_history_list',
- array('id' => $person->getId())));
+ array('person_id' => $person->getId())));
} else {
$flashBag->add('danger', $this->get('translator')
@@ -76,43 +76,30 @@ class HistoryController extends Controller
- return $this->render('ChillPersonBundle:History:update.html.twig',
- array('form' => $form->createView(),
- 'person' => $person ) );
+ return $this->render('ChillPersonBundle:History:form.html.twig',
+ array(
+ 'form' => $form->createView(),
+ 'person' => $person,
+ 'history' => $history
+ )
+ );
}
- public function updateAction($id, $historyId){
+ public function updateAction($history_id){
$em = $this->getDoctrine()->getManager();
$history = $em->getRepository('ChillPersonBundle:PersonHistoryFile')
- ->find($historyId);
+ ->find($history_id);
if ($history === null) {
- return $this->createNotFoundException("history with id ".$historyId.
+ return $this->createNotFoundException("history with id ".$history_id.
" is not found");
}
- if ($history->isOpen()) {
- $r = new \Symfony\Component\HttpFoundation\Response("You are not allowed "
- . "to edit an opened history");
- $r->setStatusCode(400);
- return $r;
- }
-
$person = $history->getPerson();
- if ($person->getId() != $id) {
- $r = new \Symfony\Component\HttpFoundation\Response("person id does not"
- . " match history id");
- $r->setStatusCode(400);
- return $r;
- }
-
- $motivesArray = $this->get('service_container')
- ->getParameter('person.history.close.motives');
-
- $form = $this->createForm(new PersonHistoryFileType($motivesArray),
- $history);
+ $form = $this->createForm(new PersonHistoryFileType(),
+ $history, array('period_action' => 'update'));
$request = $this->getRequest();
@@ -133,11 +120,11 @@ class HistoryController extends Controller
'controller.Person.history.update.done'));
return $this->redirect($this->generateUrl('chill_person_history_list',
- array('id' => $person->getId())));
+ array('person_id' => $person->getId())));
} else {
$flashBag->add('danger', $this->get('translator')
- ->trans('controller.Person.history.update.error'));
+ ->trans('controller.Person.history.edit.error'));
foreach($errors as $error) {
$flashBag->add('info', $error->getMessage());
@@ -147,13 +134,16 @@ class HistoryController extends Controller
- return $this->render('ChillPersonBundle:History:update.html.twig',
- array('form' => $form->createView(),
- 'person' => $person ) );
+ return $this->render('ChillPersonBundle:History:form.html.twig',
+ array(
+ 'form' => $form->createView(),
+ 'person' => $person,
+ 'history' => $history
+ ) );
}
- public function closeAction($id) {
- $person = $this->_getPerson($id);
+ public function closeAction($person_id) {
+ $person = $this->_getPerson($person_id);
if ($person === null) {
return $this->createNotFoundException('Person not found');
@@ -162,54 +152,29 @@ class HistoryController extends Controller
if ($person->isOpen() === false) {
$this->get('session')->getFlashBag()
->add('danger', $this->get('translator')
- ->trans('controller.Person.history.close.is_not_open',
+ ->trans('controller.Person.history.close.is_closed',
array('%name%' => $person->__toString())));
return $this->redirect(
$this->generateUrl('chill_person_history_list', array(
- 'id' => $person->getId()
+ 'person_id' => $person->getId()
)));
}
$current = $person->getCurrentHistory();
- $container = array(
- 'dateClosing' => new \DateTime(),
- 'motive' => null,
- 'texto' => $current->getMemo());
-
-
-
- $form = $this->createFormBuilder($container)
- ->add('dateClosing', 'date', array(
- 'data' => new \DateTime()
- ))
- ->add('motive', 'choice', array(
- 'choices' => $this->_getMotive(),
- 'empty_value' => 'views.Person.close.select_a_motive'
- ))
- ->add('texto', 'textarea', array(
- 'required' => false
- ))
- ->getForm();
-
+ $form = $this->createForm(new PersonHistoryFileType(), $current, array(
+ 'period_action' => 'close'
+ ));
+
$request = $this->getRequest();
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
if ($form->isValid()){
-
-
-
- $person->close($form['dateClosing']->getData(),
- $form['motive']->getData(),
- $form['texto']->getData());
-
-
+ $person->close($current);
$errors = $this->_validatePerson($person);
-
-
if (count($errors) === 0) {
$this->get('session')->getFlashBag()
@@ -221,7 +186,7 @@ class HistoryController extends Controller
return $this->redirect(
$this->generateUrl('chill_person_history_list', array(
- 'id' => $person->getId()
+ 'person_id' => $person->getId()
))
);
} else {
@@ -250,7 +215,7 @@ class HistoryController extends Controller
- return $this->render('ChillPersonBundle:History:close.html.twig',
+ return $this->render('ChillPersonBundle:History:form.html.twig',
array(
'form' => $form->createView(),
'person' => $person,
@@ -277,8 +242,8 @@ class HistoryController extends Controller
}
- public function openAction($id) {
- $person = $this->_getPerson($id);
+ public function openAction($person_id) {
+ $person = $this->_getPerson($person_id);
if ($person === null) {
return $this->createNotFoundException('Person not found');
@@ -286,7 +251,8 @@ class HistoryController extends Controller
$request = $this->getRequest();
- if ($person->isOpen() === true && ! $request->query->has('historyId')) {
+ //in case the person is already open
+ if ($person->isOpen() === true) {
$this->get('session')->getFlashBag()
->add('danger', $this->get('translator')
->trans('controller.Person.history.open.is_not_closed',
@@ -294,60 +260,20 @@ class HistoryController extends Controller
return $this->redirect(
$this->generateUrl('chill_person_history_list', array(
- 'id' => $person->getId()
+ 'person_id' => $person->getId()
)));
}
-
- $historyId = $request->query->get('historyId', null);
-
- if ($historyId !== null) {
- $history = $this->getDoctrine()->getEntityManager()
- ->getRepository('ChillPersonBundle:PersonHistoryFile')
- ->find($historyId);
-
- } else {
- $history = new PersonHistoryFile(new \DateTime());
- }
-
- //this may happen if we set an historyId and history is not closed
- if ($request->query->has('historyId') && ! $history->isOpen()) {
- $r = new \Symfony\Component\HttpFoundation\Response("You are not allowed "
- . "to edit a closed history");
- $r->setStatusCode(400);
- return $r;
+ $history = new PersonHistoryFile(new \DateTime());
- }
-
-
-
-
-
- $form = $this->createFormBuilder()
- ->add('dateOpening', 'date', array(
- 'data' => $history->getDateOpening()
- ))
- ->add('texto', 'textarea', array(
- 'required' => false,
- 'data' => $history->getMemo()
- ))
- ->getForm();
-
-
+ $form = $this->createForm(new PersonHistoryFileType(), $history, array(
+ 'period_action' => 'open'));
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
if ($form->isValid()) {
- if ($request->query->has('historyId')) {
- $history->setDateOpening($form['dateOpening']->getData())
- ->setMemo($form['texto']->getData());
- } else {
- $person->open($form['dateOpening']->getData(),
- $form['texto']->getData());
- }
-
-
+ $person->open($history);
$errors = $this->_validatePerson($person);
@@ -361,7 +287,7 @@ class HistoryController extends Controller
return $this->redirect(
$this->generateUrl('chill_person_history_list', array(
- 'id' => $person->getId()
+ 'person_id' => $person->getId()
))
);
} else {
@@ -383,11 +309,7 @@ class HistoryController extends Controller
}
-
-
-
-
- return $this->render('ChillPersonBundle:History:open.html.twig',
+ return $this->render('ChillPersonBundle:History:form.html.twig',
array(
'form' => $form->createView(),
'person' => $person,
@@ -395,20 +317,6 @@ class HistoryController extends Controller
));
}
- private function _getMotive() {
- $motivesArray = $this->get('service_container')
- ->getParameter('person.history.close.motives');
-
- $a = array();
-
- foreach ($motivesArray as $key => $params ) {
- $a[$key] = $params['label'];
- }
-
- return $a;
-
- }
-
private function _getPerson($id) {
return $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
diff --git a/DataFixtures/ORM/LoadAccompanyingPeriodClosingMotive.php b/DataFixtures/ORM/LoadAccompanyingPeriodClosingMotive.php
new file mode 100644
index 000000000..8853999b2
--- /dev/null
+++ b/DataFixtures/ORM/LoadAccompanyingPeriodClosingMotive.php
@@ -0,0 +1,69 @@
+
+ */
+class LoadAccompanyingPeriodClosingMotive extends AbstractFixture
+ implements OrderedFixtureInterface
+{
+
+ public function getOrder() {
+ return 9500;
+ }
+
+ public static $closingMotives = array(
+ 'nothing_to_do' => array(
+ 'name' => array(
+ 'fr' => 'Plus rien à faire',
+ 'en' => 'Nothing to do',
+ 'nl' => 'nieks meer te doen'
+ )
+ ),
+ 'did_not_come_back' => array(
+ 'name' => array(
+ 'fr' => "N'est plus revenu",
+ 'en' => "Did'nt come back",
+ 'nl' => "Niet teruggekomen"
+ )
+ ),
+ 'no_more_money' => array(
+ 'active' => false,
+ 'name' => array(
+ 'fr' => "Plus d'argent",
+ 'en' => "No more money",
+ 'nl' => "Geen geld"
+ )
+ )
+ );
+
+ public static $references = array();
+
+ public function load(ObjectManager $manager)
+ {
+ foreach (static::$closingMotives as $ref => $new) {
+ $motive = new ClosingMotive();
+ $motive->setName($new['name'])
+ ->setActive((isset($new['active']) ? $new['active'] : true))
+ ;
+
+ $manager->persist($motive);
+ $this->addReference($ref, $motive);
+ echo "Adding ClosingMotive $ref\n";
+ }
+
+ $manager->flush();
+ }
+
+
+
+
+}
diff --git a/Entity/AccompanyingPeriod/ClosingMotive.php b/Entity/AccompanyingPeriod/ClosingMotive.php
new file mode 100644
index 000000000..44cbeb1aa
--- /dev/null
+++ b/Entity/AccompanyingPeriod/ClosingMotive.php
@@ -0,0 +1,92 @@
+
+ *
+ * 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