ProgramaTipoController.php 4.08 KB
<?php

namespace UBV\SurUbvBundle\Controller;

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

/**
 * Programatipo controller.
 *
 * @Route("programatipo")
 */
class ProgramaTipoController extends Controller
{
    /**
     * Lists all programaTipo entities.
     *
     * @Route("/", name="programatipo_index")
     * @Method("GET")
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        $programaTipos = $em->getRepository('UBVSurUbvBundle:ProgramaTipo')->findAll();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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