diff --git a/Controller/ReportController.php b/Controller/ReportController.php index ef5596b4b..8da41ce0d 100644 --- a/Controller/ReportController.php +++ b/Controller/ReportController.php @@ -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,73 +204,79 @@ 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, )); } /** - * Creates a form to edit a Report entity. - * - * @param Report $entity The entity - * - * @return \Symfony\Component\Form\Form The form - */ - private function createEditForm(Report $entity) + * Creates a form to edit a Report entity. + * + * @param Report $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + 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 )); } } diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 73c24c81f..c4c9ab1a2 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -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 \ No newline at end of file +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 } \ No newline at end of file diff --git a/Resources/config/routing/report.yml b/Resources/config/routing/report.yml deleted file mode 100644 index fe0bba6d9..000000000 --- a/Resources/config/routing/report.yml +++ /dev/null @@ -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 } diff --git a/Resources/views/Report/edit.html.twig b/Resources/views/Report/edit.html.twig index 407ec3a55..7779b87a4 100644 --- a/Resources/views/Report/edit.html.twig +++ b/Resources/views/Report/edit.html.twig @@ -1,16 +1,27 @@ -{% extends '::base.html.twig' %} +{# + * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, + * + * 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 . +#} +{% extends "ChillPersonBundle::layout.html.twig" %} -{% block body -%} -

Report edit

+{% set activeRouteKey = 'report_select_type' %} + +{% block title %}{{ 'Edition du rapport' |trans() }}{% endblock title %} + +{% block personcontent %} {{ form(edit_form) }} - {% endblock %} diff --git a/Resources/views/Report/list.html.twig b/Resources/views/Report/list.html.twig index f92269d75..bf5e53ee2 100644 --- a/Resources/views/Report/list.html.twig +++ b/Resources/views/Report/list.html.twig @@ -36,7 +36,7 @@ {% if report.date %}{{ report.date|date('d-m-Y') }}{% endif %} {{ report.cFGroup.getName(app.request.locale) }} {{ report.scope }} - {{ 'update' | trans }} + {{ 'update' | trans }} {% endfor %} diff --git a/Resources/views/Report/show.html.twig b/Resources/views/Report/show.html.twig index b6fbcee20..539ac25ca 100644 --- a/Resources/views/Report/show.html.twig +++ b/Resources/views/Report/show.html.twig @@ -51,6 +51,10 @@ Cfgroup {{ entity.cFGroup.getName(app.request.locale) }} + + + {{ 'update' | trans }} + {% endblock %} \ No newline at end of file