%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/emtnaeewxm/www/src/EEM/ParametreBundle/Controller/
Upload File :
Create Path :
Current File : /home/emtnaeewxm/www/src/EEM/ParametreBundle/Controller/MagasinController.php

<?php

namespace EEM\ParametreBundle\Controller;

use EEM\ParametreBundle\Entity\Magasin;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;

/**
 * Magasin controller.
 *
 * @Route("/admin/magasin")
 */
class MagasinController extends Controller
{
    /**
     * Lists all magasin entities.
     *
     * @Route("/", name="magasin_index")
     * @Method("GET")
     * @Security("has_role('ROLE_ADMIN')")
     */
    public function indexAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $paginator = $this->get('knp_paginator');

        $magasins = $paginator->paginate(
            $em->getRepository('EEMParametreBundle:Magasin')->findAll($request->query->all()), /* query NOT result */
            $request->query->getInt('page', 1)/* page number */, 10/* limit per page */
        );

        return $this->render('@EEMParametre/magasin/index.html.twig', array(
            'magasins' => $magasins,
        ));
    }

    /**
     * Creates a new magasin entity.
     *
     * @Route("/new", name="magasin_new")
     * @Method({"GET", "POST"})
     * @Security("has_role('ROLE_ADMIN')")
     */
    public function newAction(Request $request)
    {
        $magasin = new Magasin();
        $form = $this->createForm('EEM\ParametreBundle\Form\MagasinType', $magasin);
        $form->handleRequest($request);

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

            $this->addFlash('success', 'Magasin ajouté avec succès.');
            return $this->redirectToRoute('magasin_show', array('id' => $magasin->getId()));
        }

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

    /**
     * Finds and displays a magasin entity.
     *
     * @Route("/{id}", name="magasin_show")
     * @Method("GET")
     * @Security("has_role('ROLE_ADMIN')")
     */
    public function showAction(Magasin $magasin)
    {
        $deleteForm = $this->createDeleteForm($magasin);

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

    /**
     * Displays a form to edit an existing magasin entity.
     *
     * @Route("/{id}/edit", name="magasin_edit")
     * @Method({"GET", "POST"})
     * @Security("has_role('ROLE_ADMIN')")
     */
    public function editAction(Request $request, Magasin $magasin)
    {
        $deleteForm = $this->createDeleteForm($magasin);
        $editForm = $this->createForm('EEM\ParametreBundle\Form\MagasinType', $magasin);
        $editForm->handleRequest($request);

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

            $this->addFlash('success', 'Magasin Modifié avec succès.');
            return $this->redirectToRoute('magasin_edit', array('id' => $magasin->getId()));
        }

        return $this->render('@EEMParametre/magasin/edit.html.twig', array(
            'magasin' => $magasin,
            'form' => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        ));
    }

    /**
     * Deletes a magasin entity.
     *
     * @Route("/{id}/delete", name="magasin_delete")
     * @Method("DELETE")
     * @Security("has_role('ROLE_ADMIN')")
     */
    public function deleteAction(Request $request, Magasin $magasin)
    {
        $form = $this->createDeleteForm($magasin);
        $form->handleRequest($request);

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

        $this->addFlash('success', 'Magasin supprimé avec succès.');
        return $this->redirectToRoute('magasin_index');
    }

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

Zerion Mini Shell 1.0