Adding Report Entity

This commit is contained in:
Marc Ducobu 2014-11-07 16:34:09 +01:00
parent a911c7aeae
commit 8d4ad512bd
8 changed files with 547 additions and 17 deletions

View File

@ -1,13 +0,0 @@
<?php
namespace Chill\ReportBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction($name)
{
return $this->render('ChillReportBundle:Default:index.html.twig', array('name' => $name));
}
}

View File

@ -0,0 +1,224 @@
<?php
namespace Chill\ReportBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chill\ReportBundle\Entity\Report;
use Chill\ReportBundle\Form\ReportType;
/**
* Report controller.
*
*/
class ReportController extends Controller
{
/**
* Lists all Report entities.
*
*/
public function indexAction()
{
$em = $this->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()
;
}
}

221
Entity/Report.php Normal file
View File

@ -0,0 +1,221 @@
<?php
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\Person;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
/*
*
* 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/>.
*/
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;
}
}

44
Form/ReportType.php Normal file
View File

@ -0,0 +1,44 @@
<?php
namespace Chill\ReportBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class ReportType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->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';
}
}

View File

@ -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: { }

View File

@ -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

View File

@ -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 }

View File

@ -1 +0,0 @@
Hello {{ name }}!