Gina Next Generation
 All Classes Namespaces Files Functions Variables
DeleteController.php
Go to the documentation of this file.
00001 <?php
00002 
00003 namespace Admingenerated\EtraliGinangBundle\BaseCountryController;
00004 
00005 use Admingenerator\GeneratorBundle\Controller\Doctrine\BaseController as BaseController;
00006 use Symfony\Component\HttpFoundation\RedirectResponse;
00007 
00008 
00009 
00010 class DeleteController extends BaseController
00011 {
00012     public function indexAction($pk)
00013     {
00014         try {
00015             $Country = $this->getObject($pk);
00016 
00017             
00018 
00019             $this->preRemove($Country);
00020             $this->process($Country);
00021             $this->postRemove($Country);
00022 
00023             $this->get('session')->setFlash('success', $this->get('translator')->trans("batch.delete.success", array(), 'Admingenerator') );
00024         } catch (\Exception $e) {
00025             $this->get('session')->setFlash('error', $this->get('translator')->trans("batch.delete.error", array(), 'Admingenerator') );
00026             $this->onException($e, $Country);
00027         }
00028 
00029         return new RedirectResponse($this->generateUrl("Etrali_GinangBundle_Country_list"));
00030     }
00031 
00032     /**
00033     * This method is here to make your life better, so overwrite  it
00034     *
00035     * @param \Exception $exception throwed exception
00036     * @param \Etrali\GinangBundle\Entity\Country $Country your \Etrali\GinangBundle\Entity\Country object
00037     */
00038     public function onException(\Exception $exception, \Etrali\GinangBundle\Entity\Country $Country)
00039     {
00040     }
00041 
00042     /**
00043     * This method is here to make your life better, so overwrite it
00044     *
00045     * @param \Etrali\GinangBundle\Entity\Country $Country your \Etrali\GinangBundle\Entity\Country object
00046     */
00047     public function preRemove(\Etrali\GinangBundle\Entity\Country $Country)
00048     {
00049     }
00050 
00051     /**
00052     * This method is here to make your life better, so overwrite it
00053     *
00054     * @param \Etrali\GinangBundle\Entity\Country $Country your \Etrali\GinangBundle\Entity\Country object
00055     */
00056     public function postRemove(\Etrali\GinangBundle\Entity\Country $Country)
00057     {
00058     }
00059 
00060 
00061     protected function getObject($pk)
00062     {
00063         $Country = $this->getDoctrine()
00064              ->getEntityManager()
00065              ->getRepository('Etrali\GinangBundle\Entity\Country')
00066              ->find($pk);
00067 
00068         if (!$Country) {
00069             throw new \InvalidArgumentException("No Etrali\GinangBundle\Entity\Country found on idCountry : $pk");
00070         }
00071 
00072         return $Country;
00073     }
00074 
00075     protected function process(\Etrali\GinangBundle\Entity\Country $Country)
00076     {
00077         $em = $this->getDoctrine()->getEntityManager();
00078         $em->remove($Country);
00079         $em->flush();
00080         $em->clear();
00081     }
00082 
00083 }
 All Classes Namespaces Files Functions Variables