mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
Updating report
This commit is contained in:
parent
bdbcdd2db9
commit
2ae19eba39
@ -147,7 +147,7 @@ class ReportController extends Controller
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('report_show',
|
||||
array('person_id' => $person_id,'id' => $entity->getId())));
|
||||
array('person_id' => $person_id,'report_id' => $entity->getId())));
|
||||
}
|
||||
|
||||
return $this->render('ChillReportBundle:Report:new.html.twig', array(
|
||||
@ -182,13 +182,13 @@ class ReportController extends Controller
|
||||
* Finds and displays a Report entity.
|
||||
*
|
||||
*/
|
||||
public function showAction($id, $person_id)
|
||||
public function showAction($report_id, $person_id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
||||
|
||||
$entity = $em->getRepository('ChillReportBundle:Report')->find($id);
|
||||
$entity = $em->getRepository('ChillReportBundle:Report')->find($report_id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Report entity.');
|
||||
@ -204,23 +204,27 @@ class ReportController extends Controller
|
||||
* Displays a form to edit an existing Report entity.
|
||||
*
|
||||
*/
|
||||
public function editAction($id)
|
||||
public function editAction($person_id, $report_id, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillReportBundle:Report')->find($id);
|
||||
$report = $em->getRepository('ChillReportBundle:Report')->find($report_id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Report entity.');
|
||||
if (!$report) {
|
||||
throw $this->createNotFoundException('Unable to find the report.');
|
||||
}
|
||||
|
||||
$editForm = $this->createEditForm($entity);
|
||||
$deleteForm = $this->createDeleteForm($id);
|
||||
if(intval($person_id) !== intval($report->getPerson()->getId())) {
|
||||
throw new Exception("This is not the report of the person", 1);
|
||||
}
|
||||
|
||||
$person = $report->getPerson();
|
||||
|
||||
$editForm = $this->createEditForm($report, $person->getId());
|
||||
|
||||
return $this->render('ChillReportBundle:Report:edit.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
'person' => $person,
|
||||
));
|
||||
}
|
||||
|
||||
@ -231,46 +235,48 @@ class ReportController extends Controller
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createEditForm(Report $entity)
|
||||
private function createEditForm(Report $entity, $person_id)
|
||||
{
|
||||
$form = $this->createForm(new ReportType(), $entity, array(
|
||||
'action' => $this->generateUrl('report_update', array('id' => $entity->getId())),
|
||||
'action' => $this->generateUrl('report_update',
|
||||
array('person_id' => $person_id, 'report_id' => $entity->getId())),
|
||||
'method' => 'PUT',
|
||||
'em' => $this->getDoctrine()->getManager(),
|
||||
'cFGroup' => $entity->getCFGroup(),
|
||||
));
|
||||
|
||||
$form->add('submit', 'submit', array('label' => 'Update'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits an existing Report entity.
|
||||
*
|
||||
*/
|
||||
public function updateAction(Request $request, $id)
|
||||
public function updateAction($person_id, $report_id, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillReportBundle:Report')->find($id);
|
||||
$report = $em->getRepository('ChillReportBundle:Report')->find($report_id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Report entity.');
|
||||
if (!$report) {
|
||||
throw $this->createNotFoundException('Unable to find the report '.$report_id.'.');
|
||||
}
|
||||
|
||||
$deleteForm = $this->createDeleteForm($id);
|
||||
$editForm = $this->createEditForm($entity);
|
||||
$editForm = $this->createEditForm($report, $person_id);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isValid()) {
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('report_edit', array('id' => $id)));
|
||||
return $this->redirect($this->generateUrl('report_edit',
|
||||
array('person_id' => $report->getPerson()->getId(), 'report_id' => $report_id)));
|
||||
}
|
||||
|
||||
return $this->render('ChillReportBundle:Report:edit.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
'person' => $person
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,15 @@ report_list:
|
||||
person:
|
||||
order: 101
|
||||
label: Report list
|
||||
|
||||
report_show:
|
||||
path: /person/{person_id}/report/{id}/show
|
||||
path: /person/{person_id}/report/{report_id}/show
|
||||
defaults: { _controller: "ChillReportBundle:Report:show" }
|
||||
|
||||
cl_custom_fields_report:
|
||||
resource: "@ChillReportBundle/Resources/config/routing/report.yml"
|
||||
prefix: /report
|
||||
report_edit:
|
||||
path: /person/{person_id}/report/{report_id}/edit
|
||||
defaults: { _controller: "ChillReportBundle:Report:edit" }
|
||||
|
||||
report_update:
|
||||
path: /person/{person_id}/report/{report_id}/update
|
||||
defaults: { _controller: "ChillReportBundle:Report:update" }
|
||||
requirements: { _method: post|put }
|
@ -1,17 +0,0 @@
|
||||
report:
|
||||
path: /
|
||||
defaults: { _controller: "ChillReportBundle:Report:index" }
|
||||
|
||||
report_edit:
|
||||
path: /{id}/edit
|
||||
defaults: { _controller: "ChillReportBundle:Report:edit" }
|
||||
|
||||
report_update:
|
||||
path: /{id}/update
|
||||
defaults: { _controller: "ChillReportBundle:Report:update" }
|
||||
requirements: { _method: post|put }
|
||||
|
||||
report_delete:
|
||||
path: /{id}/delete
|
||||
defaults: { _controller: "ChillReportBundle:Report:delete" }
|
||||
requirements: { _method: post|delete }
|
@ -1,16 +1,27 @@
|
||||
{% extends '::base.html.twig' %}
|
||||
{#
|
||||
* Copyright (C) 2014, 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/>.
|
||||
#}
|
||||
{% extends "ChillPersonBundle::layout.html.twig" %}
|
||||
|
||||
{% block body -%}
|
||||
<h1>Report edit</h1>
|
||||
{% set activeRouteKey = 'report_select_type' %}
|
||||
|
||||
{% block title %}{{ 'Edition du rapport' |trans() }}{% endblock title %}
|
||||
|
||||
{% block personcontent %}
|
||||
|
||||
{{ form(edit_form) }}
|
||||
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<a href="{{ path('report') }}">
|
||||
Back to the list
|
||||
</a>
|
||||
</li>
|
||||
<li>{{ form(delete_form) }}</li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
@ -36,7 +36,7 @@
|
||||
<td>{% if report.date %}{{ report.date|date('d-m-Y') }}{% endif %}</td>
|
||||
<td>{{ report.cFGroup.getName(app.request.locale) }}</td>
|
||||
<td>{{ report.scope }}</td>
|
||||
<td><a href="{#{ path('report_edit', { 'id': entity.id }) }#}">{{ 'update' | trans }}</a></td>
|
||||
<td><a href="{{ path('report_edit', { 'person_id': report.person.id, 'report_id': report.id }) }}">{{ 'update' | trans }}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
@ -51,6 +51,10 @@
|
||||
<th>Cfgroup</th>
|
||||
<td>{{ entity.cFGroup.getName(app.request.locale) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td><a href="{{ path('report_edit', { 'person_id': entity.person.id, 'report_id': entity.id }) }}">{{ 'update' | trans }}</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user