%PDF- %PDF-
Direktori : /home/emtnaeewxm/www/src/EEM/TraiteBundle/Controller/ |
Current File : /home/emtnaeewxm/www/src/EEM/TraiteBundle/Controller/ClientController.php |
<?php namespace EEM\TraiteBundle\Controller; use EEM\TraiteBundle\Entity\Client; 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; /** * Client controller. * * @Route("/admin/client") */ class ClientController extends Controller { /** * Lists all client entities. * * @Route("/", name="client_index") * @Method("GET") * @Security("has_role('ROLE_USER')") */ public function indexAction(Request $request) { $em = $this->getDoctrine()->getManager(); $paginator = $this->get('knp_paginator'); $clients = $paginator->paginate( $em->getRepository('EEMTraiteBundle:Client')->MyFindAll($request->query->all()), /* query NOT result */ $request->query->getInt('page', 1)/* page number */, 10/* limit per page */ ); return $this->render('@EEMTraite/client/index.html.twig', array( 'clients' => $clients, )); } /** * Creates a new client entity. * * @Route("/new", name="client_new") * @Method({"GET", "POST"}) * @Security("has_role('ROLE_USER')") */ public function newAction(Request $request) { $client = new Client(); $form = $this->createForm('EEM\TraiteBundle\Form\ClientType', $client); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $client->setEtat('non_engage'); $em->persist($client); $em->flush(); $this->addFlash('success', 'Client ajouté avec succès.'); return $this->redirectToRoute('client_show', array('id' => $client->getId())); } return $this->render('@EEMTraite/client/new.html.twig', array( 'client' => $client, 'form' => $form->createView(), )); } /** * Finds and displays a client entity. * * @Route("/{id}", name="client_show") * @Method("GET") * @Security("has_role('ROLE_USER')") */ public function showAction(Client $client) { $deleteForm = $this->createDeleteForm($client); return $this->render('@EEMTraite/client/show.html.twig', array( 'client' => $client, 'delete_form' => $deleteForm->createView(), 'listeEtat'=>$client->listeEtat() )); } /** * Displays a form to edit an existing client entity. * * @Route("/{id}/edit", name="client_edit") * @Method({"GET", "POST"}) * @Security("has_role('ROLE_USER')") */ public function editAction(Request $request, Client $client) { $deleteForm = $this->createDeleteForm($client); $editForm = $this->createForm('EEM\TraiteBundle\Form\ClientType', $client); $editForm->handleRequest($request); if ($editForm->isSubmitted() && $editForm->isValid()) { $this->getDoctrine()->getManager()->flush(); $this->addFlash('success', 'Client Modifié avec succès.'); return $this->redirectToRoute('client_show', array('id' => $client->getId())); } return $this->render('@EEMTraite/client/edit.html.twig', array( 'client' => $client, 'form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); } /** * Deletes a client entity. * * @Route("/{id}/delete", name="client_delete") * @Method("DELETE") * @Security("has_role('ROLE_USER')") */ public function deleteAction(Request $request, Client $client) { $form = $this->createDeleteForm($client); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->remove($client); $em->flush(); } return $this->redirectToRoute('client_index'); } /** * Creates a form to delete a client entity. * * @param Client $client The client entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Client $client) { return $this->createFormBuilder() ->setAction($this->generateUrl('client_delete', array('id' => $client->getId()))) ->setMethod('DELETE') ->getForm() ; } }