ObjetivoPlanPatriaController.php 4.45 KB
<?php

namespace UBV\SurUbvBundle\Controller;

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

/**
 * Objetivoplanpatrium controller.
 *
 * @Route("objetivoplanpatria")
 */
class ObjetivoPlanPatriaController extends Controller
{
    /**
     * Lists all objetivoPlanPatrium entities.
     *
     * @Route("/", name="objetivoplanpatria_index")
     * @Method("GET")
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        $objetivoPlanPatrias = $em->getRepository('UBVSurUbvBundle:ObjetivoPlanPatria')->findAll();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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