diff --git a/Controller/ReportController.php b/Controller/ReportController.php index 1bd09c25a..a8dc66c40 100644 --- a/Controller/ReportController.php +++ b/Controller/ReportController.php @@ -57,6 +57,18 @@ class ReportController extends Controller */ public function selectReportTypeAction($person_id, Request $request) { + $cFGroupId = $request->query->get('cFGroup'); + + echo('----'); + echo($cFGroupId); + echo('----'); + + if($cFGroupId) { + return $this->redirect( + $this->generateUrl('report_new', + array('person_id' => $person_id, 'cf_group_id' => $cFGroupId))); + } + $em = $this->getDoctrine()->getManager(); $cFGroups = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup') @@ -71,7 +83,6 @@ class ReportController extends Controller $form = $this->get('form.factory') ->createNamedBuilder(null, 'form', null, array( 'method' => 'GET', - 'action' => $this->generateUrl('report_new'), 'csrf_protection' => false )) ->add('cFGroup', 'choice', array( @@ -85,30 +96,50 @@ class ReportController extends Controller } /** - * Creates a new Report entity. + * Displays a form to create a new Report entity. * */ - public function createAction(Request $request) + public function newAction($person_id, $cf_group_id, Request $request) { $em = $this->getDoctrine()->getManager(); $entity = new Report(); - $cFGroupId = $request->query->get('cFGroup',null); - echo $cFGroupId; - die(); + $cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cf_group_id); + $entity->setCFGroup($cFGroup); - if($cFGroupId) { - $entity.setCFGroup( - $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cFGroupID) - ); - } + $form = $this->createCreateForm($entity, $person_id, $cFGroup); - $form = $this->createCreateForm($entity); + return $this->render('ChillReportBundle:Report:new.html.twig', array( + 'entity' => $entity, + 'form' => $form->createView(), + )); + } + + /** + * Creates a new Report entity. + * + */ + public function createAction($person_id, $cf_group_id, Request $request) + { + $em = $this->getDoctrine()->getManager(); + + $entity = new Report(); + $cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cf_group_id); + + $form = $this->createCreateForm($entity, $person_id, $cFGroup); $form->handleRequest($request); if ($form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cf_group_id); + $entity->setCFGroup($cFGroup); + + $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); + $entity->setPerson($person); + + $user = $this->get('security.context')->getToken()->getUser(); + $entity->setUser($user); + $em->persist($entity); $em->flush(); @@ -128,10 +159,11 @@ class ReportController extends Controller * * @return \Symfony\Component\Form\Form The form */ - private function createCreateForm(Report $entity, $cFGroup) + private function createCreateForm(Report $entity, $person_id, $cFGroup) { $form = $this->createForm(new ReportType(), $entity, array( - 'action' => $this->generateUrl('report_create'), + 'action' => $this->generateUrl('report_create', + array('person_id' => $person_id, 'cf_group_id' => $cFGroup->getId())), 'method' => 'POST', 'em' => $this->getDoctrine()->getManager(), 'cFGroup' => $cFGroup, @@ -142,33 +174,6 @@ class ReportController extends Controller return $form; } - /** - * Displays a form to create a new Report entity. - * - */ - public function newAction(Request $request) - { - $em = $this->getDoctrine()->getManager(); - - $entity = new Report(); - - $cFGroupId = $request->query->get('cFGroup'); - - if(! $cFGroupId) { - throw new Exception("Error Processing Request", 1); - } - - $cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cFGroupId); - $entity->setCFGroup($cFGroup); - - $form = $this->createCreateForm($entity, $cFGroup); - - return $this->render('ChillReportBundle:Report:new.html.twig', array( - 'entity' => $entity, - 'form' => $form->createView(), - )); - } - /** * Finds and displays a Report entity. * diff --git a/Form/ReportType.php b/Form/ReportType.php index 2c6e2499e..c97cbec31 100644 --- a/Form/ReportType.php +++ b/Form/ReportType.php @@ -20,8 +20,6 @@ class ReportType extends AbstractType $transformer = new CustomFieldsGroupToIdTransformer($entityManager); $builder - ->add('user') - ->add('person') ->add('date') ->add('scope') ->add('cFData', 'custom_field', array('group' => $options['cFGroup'])) diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 909cbf165..6554b7e4a 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1,5 +1,5 @@ report_select_type: - pattern: /person/{person_id}/report/create + pattern: /person/{person_id}/report/select/type/for/creation defaults: { _controller: "ChillReportBundle:Report:selectReportType" } options: menus: @@ -7,6 +7,19 @@ report_select_type: order: 100 label: Add a report +report_new: + path: /person/{person_id}/report/cfgroup/{cf_group_id}/new + defaults: { _controller: "ChillReportBundle:Report:new" } + +report_create: + path: /person/{person_id}/report/cfgroup/{cf_group_id}/create + defaults: { _controller: "ChillReportBundle:Report:create" } + requirements: { _method: post } + +report_show: + path: 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 diff --git a/Resources/config/routing/report.yml b/Resources/config/routing/report.yml index bb21c22c0..33e0aab6c 100644 --- a/Resources/config/routing/report.yml +++ b/Resources/config/routing/report.yml @@ -6,15 +6,6 @@ report_show: path: /{id}/show defaults: { _controller: "ChillReportBundle:Report:show" } -report_new: - path: /new - defaults: { _controller: "ChillReportBundle:Report:new" } - -report_create: - path: /create - defaults: { _controller: "ChillReportBundle:Report:create" } - requirements: { _method: post } - report_edit: path: /{id}/edit defaults: { _controller: "ChillReportBundle:Report:edit" } diff --git a/Resources/views/Report/new.html.twig b/Resources/views/Report/new.html.twig index dfe5f4320..3a63af29e 100644 --- a/Resources/views/Report/new.html.twig +++ b/Resources/views/Report/new.html.twig @@ -1,6 +1,6 @@ -{% extends '::base.html.twig' %} +{% extends "ChillMainBundle::layout.html.twig" %} -{% block body -%} +{% block content %}

Report creation

{{ form(form) }} diff --git a/Resources/views/Report/select_report_type.html.twig b/Resources/views/Report/select_report_type.html.twig index acaa3c01b..1ba18644f 100644 --- a/Resources/views/Report/select_report_type.html.twig +++ b/Resources/views/Report/select_report_type.html.twig @@ -1,7 +1,6 @@ {% extends "ChillMainBundle::layout.html.twig" %} - - {% block content %} +{% block content %} {{ form_start(form) }} {{ form_row(form) }} diff --git a/Resources/views/Report/show.html.twig b/Resources/views/Report/show.html.twig index 064b13b7a..f0c4bdb4a 100644 --- a/Resources/views/Report/show.html.twig +++ b/Resources/views/Report/show.html.twig @@ -11,7 +11,7 @@ Userr - {{ entity.userr }} + {{ entity.user }} Person