Skip to content

Instantly share code, notes, and snippets.

@fabricekabongo
Created May 20, 2015 14:10
Show Gist options
  • Save fabricekabongo/ab603c1b96e649726748 to your computer and use it in GitHub Desktop.
Save fabricekabongo/ab603c1b96e649726748 to your computer and use it in GitHub Desktop.
<?php
namespace Sacoza\ClientBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sacoza\CoreBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sacoza\ClientBundle\Entity\CompanyAuditor;
use Sacoza\ClientBundle\Form\CompanyAuditorType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sacoza\LoanBundle\Entity\Loan;
/**
* CompanyAuditor controller.
*
* @Route("/companyauditor")
*/
class CompanyAuditorController extends Controller
{
public function __construct(){
$this->functionality = "client_company_auditor";
}
/**
* Lists all CompanyAuditor entities.
*
* @Route("/", name="companyauditor")
* @Method("GET")
* @Template()
*/
public function indexAction()
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('SacozaClientBundle:CompanyAuditor')->findAll();
return array(
'entities' => $entities,
);
}
/**
* Creates a new CompanyAuditor entity.
*
* @Route("/", name="companyauditor_create")
* @Method("POST")
* @Template("SacozaClientBundle:CompanyAuditor:new.html.twig")
*/
public function createAction(Request $request)
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$entity = new CompanyAuditor();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('companyauditor_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Creates a form to create a CompanyAuditor entity.
*
* @param CompanyAuditor $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(CompanyAuditor $entity)
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$form = $this->createForm(new CompanyAuditorType(), $entity, array(
'action' => $this->generateUrl('companyauditor_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
/**
* Displays a form to create a new CompanyAuditor entity.
*
* @Route("/new", name="companyauditor_new")
* @Method("GET")
* @Template()
*/
public function newAction()
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$entity = new CompanyAuditor();
$form = $this->createCreateForm($entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Creates a new CompanyAuditor entity.
*
* @Route("/wizard/{id}", name="companyauditor_wizard_create")
* @ParamConverter("loan", class="SacozaLoanBundle:Loan", options={"mapping": {"id": "id"}})
* @Method("POST")
* @Template("SacozaClientBundle:CompanyAuditor:new.html.twig")
*/
public function createWizardAction(Request $request,Loan $loan)
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$entity = new CompanyAuditor();
$form = $this->createCreateForm($entity,$loan);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity->setCompany($loan->getClient()->getCompany());
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('companyauditor_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Creates a form to create a CompanyAuditor entity.
*
* @param CompanyAuditor $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateWizardForm(CompanyAuditor $entity,Loan $loan)
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$form = $this->createForm(new CompanyAuditorType(), $entity, array(
'action' => $this->generateUrl('companyauditor_create',array("id" => $loan->getId())),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
/**
* Displays a form to create a new CompanyAuditor entity.
*
* @Route("/new/wizard/{id}", name="companyauditor_wizard_new")
* @ParamConverter("loan", class="SacozaLoanBundle:Loan", options={"mapping": {"id": "id"}})
* @Method("GET")
* @Template()
*/
public function newWizardAction(Loan $loan)
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$entity = new CompanyAuditor();
$form = $this->createCreateWizardForm($entity,$loan);
return array(
'entity' => $entity,
'form' => $form->createView(),
'loan' => $loan
);
}
/**
* Finds and displays a CompanyAuditor entity.
*
* @Route("/{id}", name="companyauditor_show")
* @Method("GET")
* @Template()
*/
public function showAction($id)
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('SacozaClientBundle:CompanyAuditor')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CompanyAuditor entity.');
}
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
);
}
/**
* Displays a form to edit an existing CompanyAuditor entity.
*
* @Route("/{id}/edit", name="companyauditor_edit")
* @Method("GET")
* @Template()
*/
public function editAction($id)
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('SacozaClientBundle:CompanyAuditor')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CompanyAuditor entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Creates a form to edit a CompanyAuditor entity.
*
* @param CompanyAuditor $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(CompanyAuditor $entity)
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$form = $this->createForm(new CompanyAuditorType(), $entity, array(
'action' => $this->generateUrl('companyauditor_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
/**
* Edits an existing CompanyAuditor entity.
*
* @Route("/{id}", name="companyauditor_update")
* @Method("PUT")
* @Template("SacozaClientBundle:CompanyAuditor:edit.html.twig")
*/
public function updateAction(Request $request, $id)
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('SacozaClientBundle:CompanyAuditor')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CompanyAuditor entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('companyauditor_edit', array('id' => $id)));
}
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Deletes a CompanyAuditor entity.
*
* @Route("/{id}", name="companyauditor_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, $id)
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('SacozaClientBundle:CompanyAuditor')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CompanyAuditor entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('companyauditor'));
}
/**
* Creates a form to delete a CompanyAuditor entity by id.
*
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm($id)
{
if(!$this->hasAccess()){
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
return $this->createFormBuilder()
->setAction($this->generateUrl('companyauditor_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment