diff --git a/Controller/DefaultController.php b/Controller/DefaultController.php deleted file mode 100644 index bc7e4c5ec..000000000 --- a/Controller/DefaultController.php +++ /dev/null @@ -1,13 +0,0 @@ -render('ChillReportBundle:Default:index.html.twig', array('name' => $name)); - } -} diff --git a/Controller/ReportController.php b/Controller/ReportController.php new file mode 100644 index 000000000..26e0f54b9 --- /dev/null +++ b/Controller/ReportController.php @@ -0,0 +1,224 @@ +getDoctrine()->getManager(); + + $entities = $em->getRepository('ChillReportBundle:Report')->findAll(); + + return $this->render('ChillReportBundle:Report:index.html.twig', array( + 'entities' => $entities, + )); + } + /** + * Creates a new Report entity. + * + */ + public function createAction(Request $request) + { + $entity = new Report(); + $form = $this->createCreateForm($entity); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($entity); + $em->flush(); + + return $this->redirect($this->generateUrl('report_show', array('id' => $entity->getId()))); + } + + return $this->render('ChillReportBundle:Report:new.html.twig', array( + 'entity' => $entity, + 'form' => $form->createView(), + )); + } + + /** + * Creates a form to create a Report entity. + * + * @param Report $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createCreateForm(Report $entity) + { + $form = $this->createForm(new ReportType(), $entity, array( + 'action' => $this->generateUrl('report_create'), + 'method' => 'POST', + )); + + $form->add('submit', 'submit', array('label' => 'Create')); + + return $form; + } + + /** + * Displays a form to create a new Report entity. + * + */ + public function newAction() + { + $entity = new Report(); + $form = $this->createCreateForm($entity); + + return $this->render('ChillReportBundle:Report:new.html.twig', array( + 'entity' => $entity, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a Report entity. + * + */ + public function showAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillReportBundle:Report')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Report entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + + return $this->render('ChillReportBundle:Report:show.html.twig', array( + 'entity' => $entity, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing Report entity. + * + */ + public function editAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillReportBundle:Report')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Report entity.'); + } + + $editForm = $this->createEditForm($entity); + $deleteForm = $this->createDeleteForm($id); + + return $this->render('ChillReportBundle:Report:edit.html.twig', array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * 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) + { + $form = $this->createForm(new ReportType(), $entity, array( + 'action' => $this->generateUrl('report_update', array('id' => $entity->getId())), + 'method' => 'PUT', + )); + + $form->add('submit', 'submit', array('label' => 'Update')); + + return $form; + } + /** + * Edits an existing Report entity. + * + */ + public function updateAction(Request $request, $id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillReportBundle:Report')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Report entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + $editForm = $this->createEditForm($entity); + $editForm->handleRequest($request); + + if ($editForm->isValid()) { + $em->flush(); + + return $this->redirect($this->generateUrl('report_edit', array('id' => $id))); + } + + return $this->render('ChillReportBundle:Report:edit.html.twig', array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + /** + * Deletes a Report entity. + * + */ + public function deleteAction(Request $request, $id) + { + $form = $this->createDeleteForm($id); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $entity = $em->getRepository('ChillReportBundle:Report')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Report entity.'); + } + + $em->remove($entity); + $em->flush(); + } + + return $this->redirect($this->generateUrl('report')); + } + + /** + * Creates a form to delete a Report entity by id. + * + * @param mixed $id The entity id + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm($id) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('report_delete', array('id' => $id))) + ->setMethod('DELETE') + ->add('submit', 'submit', array('label' => 'Delete')) + ->getForm() + ; + } +} diff --git a/Entity/Report.php b/Entity/Report.php new file mode 100644 index 000000000..83b2bfb38 --- /dev/null +++ b/Entity/Report.php @@ -0,0 +1,221 @@ + + * + * 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 . + */ + +namespace Chill\ReportBundle\Entity; + +/** + * Report + */ +class Report +{ + /** + * @var integer + */ + private $id; + + /** + * @var \User + */ + private $user; + + /** + * @var \Person + */ + private $person; + + /** + * @var \DateTime + */ + private $date; + + /** + * @var string + */ + private $scope; + + /** + * @var array + */ + private $cFData; + + /** + * @var \CustomFieldsGroup + */ + private $cFGroup; + + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set userr + * + * @param \User $user + * + * @return Report + */ + public function setUser($user) + { + $this->userr = $user; + + return $this; + } + + /** + * Get user + * + * @return \User + */ + public function getUser() + { + return $this->user; + } + + /** + * Set person + * + * @param \Person $person + * + * @return Report + */ + public function setPerson($person) + { + $this->person = $person; + + return $this; + } + + /** + * Get person + * + * @return \Person + */ + public function getPerson() + { + return $this->person; + } + + /** + * Set date + * + * @param \DateTime $date + * + * @return Report + */ + public function setDate($date) + { + $this->date = $date; + + return $this; + } + + /** + * Get date + * + * @return \DateTime + */ + public function getDate() + { + return $this->date; + } + + /** + * Set scope + * + * @param string $scope + * + * @return Report + */ + public function setScope($scope) + { + $this->scope = $scope; + + return $this; + } + + /** + * Get scope + * + * @return string + */ + public function getScope() + { + return $this->scope; + } + + /** + * Set cFData + * + * @param array $cFData + * + * @return Report + */ + public function setCFData($cFData) + { + $this->cFData = $cFData; + + return $this; + } + + /** + * Get cFData + * + * @return array + */ + public function getCFData() + { + return $this->cFData; + } + + /** + * Set cFGroup + * + * @param \CustomFieldsGroup $cFGroup + * + * @return Report + */ + public function setCFGroup($cFGroup) + { + $this->cFGroup = $cFGroup; + + return $this; + } + + /** + * Get cFGroup + * + * @return \CustomFieldsGroup + */ + public function getCFGroup() + { + return $this->cFGroup; + } +} \ No newline at end of file diff --git a/Form/ReportType.php b/Form/ReportType.php new file mode 100644 index 000000000..566b8201e --- /dev/null +++ b/Form/ReportType.php @@ -0,0 +1,44 @@ +add('user') + ->add('person') + ->add('date') + ->add('scope') + ->add('cFData') + ->add('cFGroup') + ; + } + + /** + * @param OptionsResolverInterface $resolver + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Chill\ReportBundle\Entity\Report' + )); + } + + /** + * @return string + */ + public function getName() + { + return 'chill_reportbundle_report'; + } +} diff --git a/Resources/config/doctrine/report.orm.yml b/Resources/config/doctrine/report.orm.yml new file mode 100644 index 000000000..49a6182c5 --- /dev/null +++ b/Resources/config/doctrine/report.orm.yml @@ -0,0 +1,25 @@ +Chill\ReportBundle\Entity\Report: + type: entity + table: null + id: + id: + type: integer + id: true + generator: + strategy: AUTO + fields: + date: + type: datetime + scope: + type: string + length: 255 + cFData: + type: json_array + manyToOne: + user: + targetEntity: Chill\MainBundle\Entity\User + person: + targetEntity: Chill\MainBundle\Entity\Person + cFGroup: + targetEntity: Chill\CustomFieldsBundle\Entity\CustomFieldsGroup + lifecycleCallbacks: { } \ No newline at end of file diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index b2452ae9a..e9f83604e 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1,3 +1,3 @@ -chill_report_homepage: - path: /hello/{name} - defaults: { _controller: ChillReportBundle:Default:index } +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 new file mode 100644 index 000000000..7f600f680 --- /dev/null +++ b/Resources/config/routing/report.yml @@ -0,0 +1,30 @@ +report: + path: / + defaults: { _controller: "ChillReportBundle:report:index" } + +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" } + +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/Default/index.html.twig b/Resources/views/Default/index.html.twig deleted file mode 100644 index 4ce626e9b..000000000 --- a/Resources/views/Default/index.html.twig +++ /dev/null @@ -1 +0,0 @@ -Hello {{ name }}!