mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add feature: update the date of an opened file
This commit is contained in:
parent
af984962a7
commit
9c249160cc
@ -4,6 +4,8 @@ namespace CL\Chill\PersonBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use CL\Chill\PersonBundle\Entity\Person;
|
||||
use CL\Chill\PersonBundle\Form\PersonHistoryFileType;
|
||||
use CL\Chill\PersonBundle\Entity\PersonHistoryFile;
|
||||
|
||||
class HistoryController extends Controller
|
||||
{
|
||||
@ -21,8 +23,75 @@ class HistoryController extends Controller
|
||||
|
||||
}
|
||||
|
||||
public function updateAction($historyId){
|
||||
public function updateAction($id, $historyId){
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$history = $em->getRepository('CLChillPersonBundle:PersonHistoryFile')
|
||||
->find($historyId);
|
||||
|
||||
if ($history === null) {
|
||||
return $this->createNotFoundException("history with id ".$historyId.
|
||||
" 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);
|
||||
|
||||
$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'))
|
||||
&& count($errors) === 0) {
|
||||
$em->flush();
|
||||
|
||||
$flashBag->add('success',
|
||||
$this->get('translator')->trans(
|
||||
'controller.Person.history.update.done'));
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_person_history_list',
|
||||
array('id' => $person->getId())));
|
||||
} else {
|
||||
|
||||
$flashBag->add('danger', $this->get('translator')
|
||||
->trans('controller.Person.history.update.error'));
|
||||
|
||||
foreach($errors as $error) {
|
||||
$flashBag->add('info', $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->render('CLChillPersonBundle:History:update.html.twig',
|
||||
array('form' => $form->createView(),
|
||||
'person' => $person ) );
|
||||
}
|
||||
|
||||
public function closeAction($id) {
|
||||
@ -157,7 +226,9 @@ class HistoryController extends Controller
|
||||
return $this->createNotFoundException('Person not found');
|
||||
}
|
||||
|
||||
if ($person->isOpen() === true) {
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ($person->isOpen() === true && ! $request->query->has('historyId')) {
|
||||
$this->get('session')->getFlashBag()
|
||||
->add('danger', $this->get('translator')
|
||||
->trans('controller.Person.history.open.is_not_closed',
|
||||
@ -169,32 +240,55 @@ class HistoryController extends Controller
|
||||
)));
|
||||
}
|
||||
|
||||
$current = $person->getCurrentHistory();
|
||||
$historyId = $request->query->get('historyId', null);
|
||||
|
||||
$container = array(
|
||||
'dateOpening' => new \DateTime(),
|
||||
'texto' => null);
|
||||
if ($historyId !== null) {
|
||||
$history = $this->getDoctrine()->getEntityManager()
|
||||
->getRepository('CLChillPersonBundle: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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$form = $this->createFormBuilder($container)
|
||||
|
||||
|
||||
$form = $this->createFormBuilder()
|
||||
->add('dateOpening', 'date', array(
|
||||
'data' => new \DateTime()
|
||||
'data' => $history->getDateOpening()
|
||||
))
|
||||
->add('texto', 'textarea', array(
|
||||
'required' => false
|
||||
'required' => false,
|
||||
'data' => $history->getMemo()
|
||||
))
|
||||
->getForm();
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
$errors = $this->_validatePerson($person);
|
||||
@ -239,7 +333,7 @@ class HistoryController extends Controller
|
||||
array(
|
||||
'form' => $form->createView(),
|
||||
'person' => $person,
|
||||
'history' => $current
|
||||
'history' => $history
|
||||
));
|
||||
}
|
||||
|
||||
|
56
Form/PersonHistoryFileType.php
Normal file
56
Form/PersonHistoryFileType.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace CL\Chill\PersonBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
|
||||
class PersonHistoryFileType extends AbstractType
|
||||
{
|
||||
|
||||
private $motives = array();
|
||||
|
||||
public function __construct(array $motivesArray) {
|
||||
foreach ($motivesArray as $key => $params ) {
|
||||
$this->motives[$key] = $params['label'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('date_opening', 'date', array("required" => true,
|
||||
'widget' => 'single_text'))
|
||||
->add('date_closing', 'date', array('required' => true,
|
||||
'widget' => 'single_text'))
|
||||
->add('motive', 'choice', array(
|
||||
'choices' => $this->motives,
|
||||
'required' => true
|
||||
))
|
||||
->add('memo', 'textarea')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolverInterface $resolver
|
||||
*/
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'CL\Chill\PersonBundle\Entity\PersonHistoryFile'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'cl_chill_personbundle_personhistoryfile';
|
||||
}
|
||||
}
|
Binary file not shown.
@ -52,6 +52,8 @@ CL\Chill\PersonBundle\Entity\PersonHistoryFile:
|
||||
- NotNull: ~
|
||||
date_closing:
|
||||
- Date: ~
|
||||
- NotNull:
|
||||
groups: [closed]
|
||||
constraints:
|
||||
- Callback:
|
||||
methods: [isDateConsistent]
|
@ -36,14 +36,17 @@ controller:
|
||||
history:
|
||||
close:
|
||||
done: Bravo ! Le dossier de <em>%name%</em> a été clotûré.
|
||||
error: Une erreur est survenue. Le dossier n'a pu être clos.
|
||||
error: Les informations introduites ne sont pas valides. Le dossier n'a pu être clos.
|
||||
error_in_form: Le formulaire n'est pas valide.
|
||||
is_not_open: Le dossier de </em>%name%</em> n'est pas ouvert. Il ne peut donc être fermé.
|
||||
open:
|
||||
done: Bravo ! Le dossier de <em>%name%</em> est maintenant ouvert.
|
||||
error: Une erreur est survenue. Le dossier n'a pu être ouvert.
|
||||
error_in_form: Le formulaire n'est pas valide.
|
||||
error: Les informations introduites ne sont pas valides. Le dossier n'a pu être ouvert.
|
||||
error_in_fom: Le formulaire n'est pas valide.
|
||||
is_not_closed: Le dossier de <em>%name%</em> n'est pas fermé. Il ne peut donc être ouvert.
|
||||
update:
|
||||
done: Bravo ! La mise à jour de l'historique a réussi !
|
||||
error: Les données introduites ne sont pas valides. Veuillez vérifier les informations ci-dessous.
|
||||
|
||||
views:
|
||||
layout:
|
||||
@ -100,6 +103,12 @@ views:
|
||||
action: Ouvrir
|
||||
date_of_opening: Date d'ouverture
|
||||
texto: Mémo
|
||||
hupdate:
|
||||
dateOpening: Date d'ouverture
|
||||
dateClosing: Date de fermeture
|
||||
motive_of_closing: Motif de clôture
|
||||
texto: Mémo
|
||||
action: Modifier
|
||||
|
||||
|
||||
|
||||
|
@ -30,7 +30,13 @@
|
||||
|
||||
{% endspaceless %}</td>
|
||||
<td>
|
||||
<div class="small warning btn icon-right entypo icon-pencil"><a href="{{ path('chill_person_history_update', {'id' : person.id, 'historyId' : history.id } ) }}">{{ 'views.Person.hlist.edit'|trans }}</a></div>
|
||||
<div class="small warning btn icon-right entypo icon-pencil">
|
||||
{% if history.isOpen %}
|
||||
<a href="{{ path('chill_person_history_open', {'id' : person.id, 'historyId' : history.id } ) }}">{{ 'views.Person.hlist.edit'|trans }}</a>
|
||||
{% else %}
|
||||
<a href="{{ path('chill_person_history_update', {'id' : person.id, 'historyId' : history.id } ) }}">{{ 'views.Person.hlist.edit'|trans }}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
29
Resources/views/History/update.html.twig
Normal file
29
Resources/views/History/update.html.twig
Normal file
@ -0,0 +1,29 @@
|
||||
{% extends "CLChillPersonBundle::layout.html.twig" %}
|
||||
|
||||
{% set activeRouteKey = null %}
|
||||
|
||||
{% block title %}{% endblock title %}
|
||||
|
||||
{% form_theme form 'CLChillMainBundle:Form:fields.html.twig' %}
|
||||
|
||||
{% block personcontent %}
|
||||
|
||||
{{ form_start(form) }}
|
||||
|
||||
{{ form_row(form.date_opening, { 'label' : 'views.Person.hupdate.dateOpening' }) }}
|
||||
|
||||
{{ form_row(form.date_closing, { 'label' : 'views.Person.hupdate.dateClosing' }) }}
|
||||
|
||||
{{ form_row(form.motive, { 'label' : 'views.Person.hupdate.motive_of_closing' }) }}
|
||||
|
||||
{{ form_row(form.memo, { 'label' : 'views.Person.hupdate.texto' }) }}
|
||||
|
||||
{{form_rest(form) }}
|
||||
|
||||
<div class="medium btn danger icon-right entypo icon-lock">
|
||||
<button type="submit">{{ 'views.Person.hupdate.action'|trans }}</button>
|
||||
</div>
|
||||
|
||||
{{ form_end(form) }}
|
||||
|
||||
{% endblock personcontent %}
|
Loading…
x
Reference in New Issue
Block a user