diff --git a/Controller/ReportController.php b/Controller/ReportController.php index 87c3eaae9..b97025c8c 100644 --- a/Controller/ReportController.php +++ b/Controller/ReportController.php @@ -1,20 +1,20 @@ - * + * * 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 . */ @@ -23,10 +23,13 @@ namespace Chill\ReportBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Security\Core\Role\Role; + use Chill\PersonBundle\Entity\Person; use Chill\ReportBundle\Entity\Report; use Chill\ReportBundle\Form\ReportType; -use Symfony\Component\Security\Core\Role\Role; + /** * Report controller. @@ -46,26 +49,26 @@ class ReportController extends Controller $em = $this->getDoctrine()->getManager(); $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); - + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); - + $reachableScopes = $this->get('chill.main.security.authorization.helper') ->getReachableScopes($this->getUser(), new Role('CHILL_REPORT_SEE'), $person->getCenter()); - + $total = $em ->createQuery("SELECT COUNT(r.id) FROM ChillReportBundle:Report r " . "WHERE r.person = :person AND r.scope IN (:scopes) ") ->setParameter('person', $person) ->setParameter('scopes', $reachableScopes) ->getSingleScalarResult(); - + // get the PaginatorFactory $paginator = $this->get('chill_main.paginator_factory')->create($total); - - $reports = $em->createQuery('SELECT r + + $reports = $em->createQuery('SELECT r FROM ChillReportBundle:Report r - WHERE r.person = :person AND r.scope IN (:scopes) + WHERE r.person = :person AND r.scope IN (:scopes) ORDER BY r.date DESC') ->setParameter('person', $person) ->setParameter('scopes', $reachableScopes) @@ -73,7 +76,7 @@ class ReportController extends Controller ->setMaxResults($paginator->getItemsPerPage()) ->getResult() ; - + return $this->render('ChillReportBundle:Report:list.html.twig', array( 'reports' => $reports, 'person' => $person, @@ -91,20 +94,20 @@ class ReportController extends Controller public function selectReportTypeAction($person_id, Request $request) { $em = $this->getDoctrine()->getManager(); - + $person = $em->getRepository('ChillPersonBundle:Person') ->find($person_id); - + if ($person === NULL) { throw $this->createNotFoundException('Person not found!'); } - + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person, 'access denied for person view'); // check access on report creation for a dummy report - $this->denyAccessUnlessGranted('CHILL_REPORT_CREATE', + $this->denyAccessUnlessGranted('CHILL_REPORT_CREATE', (new Report())->setPerson($person), 'access denied for report creation'); - - + + $cFGroupId = $request->query->get('cFGroup'); if($cFGroupId) { @@ -118,7 +121,7 @@ class ReportController extends Controller if(count($cFGroups) === 1 ){ return $this->redirect( - $this->generateUrl('report_new', + $this->generateUrl('report_new', array('person_id' => $person_id, 'cf_group_id' => $cFGroups[0]->getId()))); } @@ -133,8 +136,9 @@ class ReportController extends Controller 'method' => 'GET', 'csrf_protection' => false )) - ->add('cFGroup', 'choice', array( - 'choices' => $cFGroupsChoice + ->add('cFGroup', ChoiceType::class, array( + 'choices' => $cFGroupsChoice, + 'choices_as_values' => true )) ->getForm(); @@ -147,7 +151,7 @@ class ReportController extends Controller } /** - * Display a form for selecting which type of report to export + * Display a form for selecting which type of report to export * (a csv file with all the report of this type) * * @param Request $request The request @@ -159,7 +163,7 @@ class ReportController extends Controller if($cFGroupId) { return $this->redirect( - $this->generateUrl('report_export_list', + $this->generateUrl('report_export_list', array('cf_group_id' => $cFGroupId))); } @@ -185,8 +189,9 @@ class ReportController extends Controller 'method' => 'GET', 'csrf_protection' => false )) - ->add('cFGroup', 'choice', array( - 'choices' => $cFGroupsChoice + ->add('cFGroup', ChoiceType::class, array( + 'choices' => $cFGroupsChoice, + 'choices_as_values' => true )) ->getForm(); @@ -201,7 +206,7 @@ class ReportController extends Controller * * @param integer $cf_group_id The id of the report type to export * @param Request $request The request - * @return A csv file with all the reports of the selected type + * @return A csv file with all the reports of the selected type */ public function exportAction($cf_group_id, Request $request) { @@ -233,20 +238,20 @@ class ReportController extends Controller { $em = $this->getDoctrine()->getManager(); - $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); + $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); $cFGroup = $em ->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup') ->find($cf_group_id); - + if ($person === NULL) { throw $this->createNotFoundException("Person not found"); } - + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); // check access on report creation for a dummy report - $this->denyAccessUnlessGranted('CHILL_REPORT_CREATE', + $this->denyAccessUnlessGranted('CHILL_REPORT_CREATE', (new Report())->setPerson($person), 'access denied for report creation'); - + if ($cFGroup === NULL){ throw $this->createNotFoundException("custom fields group not found"); } @@ -281,14 +286,14 @@ class ReportController extends Controller $entity = new Report(); $cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup') ->find($cf_group_id); - + $person = $em->getRepository('ChillPersonBundle:Person') ->find($person_id); - + if($person === NULL || $cFGroup === NULL) { throw $this->createNotFoundException(); } - + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); $form = $this->createCreateForm($entity, $person, $cFGroup); @@ -297,20 +302,20 @@ class ReportController extends Controller if ($form->isValid()) { $entity->setCFGroup($cFGroup); $entity->setPerson($person); - + $this->denyAccessUnlessGranted('CHILL_REPORT_CREATE', $entity); - + $em->persist($entity); $em->flush(); $this->get('session') ->getFlashBag() - ->add('success', + ->add('success', $this->get('translator') ->trans('Success : report created!') ); - return $this->redirect($this->generateUrl('report_view', + return $this->redirect($this->generateUrl('report_view', array('person_id' => $person_id,'report_id' => $entity->getId()))); } @@ -340,8 +345,8 @@ class ReportController extends Controller private function createCreateForm(Report $entity, Person $person, $cFGroup) { $form = $this->createForm('chill_reportbundle_report', $entity, array( - 'action' => $this->generateUrl('report_create', - array('person_id' => $person->getId(), + 'action' => $this->generateUrl('report_create', + array('person_id' => $person->getId(), 'cf_group_id' => $cFGroup->getId())), 'method' => 'POST', 'cFGroup' => $cFGroup, @@ -371,7 +376,7 @@ class ReportController extends Controller throw $this->createNotFoundException( $this->get('translator')->trans('Unable to find this report.')); } - + $this->denyAccessUnlessGranted('CHILL_REPORT_SEE', $entity); return $this->render('ChillReportBundle:Report:view.html.twig', array( @@ -402,7 +407,7 @@ class ReportController extends Controller throw new \RuntimeException( $this->get('translator')->trans('This is not the report of the person.'), 1); } - + $this->denyAccessUnlessGranted('CHILL_REPORT_UPDATE', $report); $person = $report->getPerson(); @@ -425,8 +430,8 @@ class ReportController extends Controller private function createEditForm(Report $entity) { $form = $this->createForm('chill_reportbundle_report', $entity, array( - 'action' => $this->generateUrl('report_update', - array('person_id' => $entity->getPerson()->getId(), + 'action' => $this->generateUrl('report_update', + array('person_id' => $entity->getPerson()->getId(), 'report_id' => $entity->getId())), 'method' => 'PUT', 'cFGroup' => $entity->getCFGroup(), @@ -454,7 +459,7 @@ class ReportController extends Controller throw $this->createNotFoundException( $this->get('translator')->trans('Unable to find this report.')); } - + $this->denyAccessUnlessGranted('CHILL_REPORT_UPDATE', $report); $editForm = $this->createEditForm($report); @@ -465,12 +470,12 @@ class ReportController extends Controller $this->get('session') ->getFlashBag() - ->add('success', + ->add('success', $this->get('translator') ->trans('Success : report updated!') ); - return $this->redirect($this->generateUrl('report_view', + return $this->redirect($this->generateUrl('report_view', array('person_id' => $report->getPerson()->getId(), 'report_id' => $report_id))); }