DocenteController.php 3.8 KB
<?php

namespace UBV\SurUbvBundle\Controller;

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

/**
 * Docente controller.
 *
 * @Route("docente")
 */
class DocenteController extends Controller
{
    /**
     * Lists all docente entities.
     *
     * @Route("/", name="docente_index")
     * @Method("GET")
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        $docentes = $em->getRepository('UBVSurUbvBundle:Docente')->findAll();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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