AporteTipoController.php 3.97 KB
<?php

namespace UBV\SurUbvBundle\Controller;

use UBV\SurUbvBundle\Entity\AporteTipo;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request;

/**
 * Aportetipo controller.
 *
 * @Route("aportetipo")
 */
class AporteTipoController extends Controller
{
    /**
     * Lists all aporteTipo entities.
     *
     * @Route("/", name="aportetipo_index")
     * @Method("GET")
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        $aporteTipos = $em->getRepository('UBVSurUbvBundle:AporteTipo')->findAll();

        return $this->render('aportetipo/index.html.twig', array(
            'aporteTipos' => $aporteTipos,
        ));
    }

    /**
     * Creates a new aporteTipo entity.
     *
     * @Route("/new", name="aportetipo_new")
     * @Method({"GET", "POST"})
     */
    public function newAction(Request $request)
    {
        $aporteTipo = new Aportetipo();
        $form = $this->createForm('UBV\SurUbvBundle\Form\AporteTipoType', $aporteTipo);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($aporteTipo);
            $em->flush();

            return $this->redirectToRoute('aportetipo_show', array('id' => $aporteTipo->getId()));
        }

        return $this->render('aportetipo/new.html.twig', array(
            'aporteTipo' => $aporteTipo,
            'form' => $form->createView(),
        ));
    }

    /**
     * Finds and displays a aporteTipo entity.
     *
     * @Route("/{id}", name="aportetipo_show")
     * @Method("GET")
     */
    public function showAction(AporteTipo $aporteTipo)
    {
        $deleteForm = $this->createDeleteForm($aporteTipo);

        return $this->render('aportetipo/show.html.twig', array(
            'aporteTipo' => $aporteTipo,
            'delete_form' => $deleteForm->createView(),
        ));
    }

    /**
     * Displays a form to edit an existing aporteTipo entity.
     *
     * @Route("/{id}/edit", name="aportetipo_edit")
     * @Method({"GET", "POST"})
     */
    public function editAction(Request $request, AporteTipo $aporteTipo)
    {
        $deleteForm = $this->createDeleteForm($aporteTipo);
        $editForm = $this->createForm('UBV\SurUbvBundle\Form\AporteTipoType', $aporteTipo);
        $editForm->handleRequest($request);

        if ($editForm->isSubmitted() && $editForm->isValid()) {
            $this->getDoctrine()->getManager()->flush();

            return $this->redirectToRoute('aportetipo_edit', array('id' => $aporteTipo->getId()));
        }

        return $this->render('aportetipo/edit.html.twig', array(
            'aporteTipo' => $aporteTipo,
            'edit_form' => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        ));
    }

    /**
     * Deletes a aporteTipo entity.
     *
     * @Route("/{id}", name="aportetipo_delete")
     * @Method("DELETE")
     */
    public function deleteAction(Request $request, AporteTipo $aporteTipo)
    {
        $form = $this->createDeleteForm($aporteTipo);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->remove($aporteTipo);
            $em->flush();
        }

        return $this->redirectToRoute('aportetipo_index');
    }

    /**
     * Creates a form to delete a aporteTipo entity.
     *
     * @param AporteTipo $aporteTipo The aporteTipo entity
     *
     * @return \Symfony\Component\Form\Form The form
     */
    private function createDeleteForm(AporteTipo $aporteTipo)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('aportetipo_delete', array('id' => $aporteTipo->getId())))
            ->setMethod('DELETE')
            ->getForm()
        ;
    }
}