MoustacheLance

Untitled

Oct 27th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.02 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Mag\AppsBundle\Controller;
  4.  
  5. use Mag\AppsBundle\Entity\App;
  6. use Mag\AppsBundle\Entity\Client;
  7. use Mag\AppsBundle\Entity\Platform;
  8. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11.  
  12. class DefaultController extends Controller
  13. {
  14. //Index
  15.     public function indexAppAction($apps)
  16.     {
  17.         //return $this->render('AppsBundle:Default:index.html.twig', array('name' => $name));
  18.  
  19.         $apps = $this->getDoctrine()->getRepository('AppBundles:App')->findAll();
  20.         if(!$apps)
  21.         {
  22.             throw $this->createNotFoundException('No apps found');
  23.         }
  24.         $build['apps'] = $apps;
  25.         return $this->render('AppBundle:Default:apps_show_all.html.twig', $build);
  26.     }
  27.     public function indexClientsAction($clients)
  28.     {
  29.         $clients = $this->getDoctrine()->getRepository('AppBundles:Client')->findAll();
  30.         if(!$clients)
  31.         {
  32.             throw $this->createNotFoundException('No clients found');
  33.         }
  34.         $build['clients'] = $clients;
  35.         return $this->render('AppBundle:Default:clients_show_all.html.twig',$build);
  36.     }
  37.     public function indexPlatformAction($platforms)
  38.     {
  39.         $platforms = $this->getDoctrine()->getRepository('AppBundles:Platform')->findAll();
  40.         if(!$platforms)
  41.         {
  42.             throw $this->createNotFoundException('No platforms found');
  43.         }
  44.         $build['platforms'] = $platforms;
  45.         return $this->render('AppBundle:Default:clients_show_all.html.twig',$build);
  46.     }
  47.  
  48. //Show
  49.     public function showAppAction($id)
  50.     {
  51.         $apps = $this->getDoctrine()->getRepository('AppBundles:App')->find($id);
  52.  
  53.         if(!$apps)
  54.         {
  55.             throw $this->createNotFoundException('No Apps found by id'.$id);
  56.         }
  57.  
  58.         $build['apps_item'] = $apps;
  59.         return $this->render('AppsBundle:Default:apps_show.html.twig', $build);
  60.     }
  61.     public function showClientAction($id)
  62.     {
  63.         $clients = $this->getDoctrine()->getRepository('AppBundles:Client')->find($id);
  64.  
  65.         if(!$clients)
  66.         {
  67.             throw $this->createNotFoundException('No Clients found by id'.$id);
  68.         }
  69.  
  70.         $build['clients_item'] = $clients;
  71.         return $this->render('AppsBundle:Default:clients_show.html.twig', $build);
  72.     }
  73.     public function showPlatformAction($id)
  74.     {
  75.         $platforms = $this->getDoctrine()->getRepository('AppBundles:Platforms')->find($id);
  76.  
  77.         if(!$platforms)
  78.         {
  79.             throw $this->createNotFoundException('No Platforms found by id'.$id);
  80.         }
  81.  
  82.         $build['platforms_item'] = $platforms;
  83.         return $this->render('AppsBundle:Default:platforms_show.html.twig', $build);
  84.     }
  85. //Add
  86.     public function addAppAction(Request $request)
  87.     {
  88.         $app = new App();
  89.  
  90.         $form = $this->createFormBuilder($app)->add('name','text')->add('version','text')->add('save','submit')->getForm();
  91.  
  92.         $form->handleRequest($request);
  93.         if($form->isValid())
  94.         {
  95.             $em = $this->getDoctrine()->getManager();
  96.             $em->persist($app);
  97.             $em->flush();
  98.             return new Response('App added successfuly');
  99.         }
  100.         $build['form'] = $form->createView();
  101.         return $this->render('AppsBundle:Default:app_add.html.twig', $build);
  102.     }
  103.     public function addClientAction(Request $request)
  104.     {
  105.         $client = new Client();
  106.  
  107.         $form = $this->createFormBuilder($client)->add('name','text')->add('save','submit')->getForm();
  108.         if($form->isValid())
  109.         {
  110.             $em = $this->getDoctrine()->getManager();
  111.             $em->persist($client);
  112.             $em->flush();
  113.             return new Response('Client added successfuly');
  114.         }
  115.         $build['form'] = $form->createView();
  116.         return $this->render('AppsBundle:Default:client_add.html.twig', $build);
  117.     }
  118.     public function addPlatformAction(Request $request)
  119.     {
  120.         $platform = new Platform();
  121.  
  122.         $form = $this->createFormBuilder($platform)->add('name','text')->add('save','submit')->getForm();
  123.         if($form->isValid())
  124.         {
  125.             $em = $this->getDoctrine()->getManager();
  126.             $em->persist($platform);
  127.             $em->flush();
  128.             return new Response('Platform added successfuly');
  129.         }
  130.         $build['form'] = $form->createView();
  131.         return $this->render('AppsBundle:Default:client_add.html.twig', $build);
  132.     }
  133.  
  134. //Edit
  135.     public function editAppAction($id, Request $request)
  136.     {
  137.         $em = $this->getDoctrine()->getManager();
  138.         $app = $em->getRepository('AppsBundle:App');
  139.  
  140.         if(!$app)
  141.         {
  142.             throw $this->createNotFoundException('No apps found for id '. $id);
  143.         }
  144.  
  145.         $form = $this->createFormBuilder($app)->add('name','text')->add('version','text')->add('save','submit')->getForm();
  146.         $form->handleRequest($request);
  147.  
  148.         if($form->isValid())
  149.         {
  150.             $em->flush();
  151.             return new Response('Apps updated successfully');
  152.         }
  153.  
  154.         $build['form'] = $form->createView();
  155.  
  156.         return $this->render('AppsBundle:Default:app_add.html.twig', $build);
  157.     }
  158.     public function editClientAction($id, Request $request)
  159.     {
  160.         $em = $this->getDoctrine()->getManager();
  161.         $client = $em->getRepository('AppsBundles:Client');
  162.  
  163.         if(!$client)
  164.         {
  165.             throw $this->createNotFoundException('No client for id '. $id);
  166.         }
  167.  
  168.         $form = $this->createFormBuilder($client)->add('name','text')->add('save','submit')->getForm();
  169.         $form->handleRequest($request);
  170.  
  171.         if($form->isValid())
  172.         {
  173.             $em->flush();
  174.             return new Response('Clients updated successfully');
  175.         }
  176.  
  177.         $build['form'] = $form->createView();
  178.  
  179.         return $this->render('AppsBundle:Default:client_add.html.twig', $build);
  180.     }
  181.     public function editPlatformAction($id, Request $request)
  182.     {
  183.         $em = $this->getDoctrine()->getManager();
  184.         $platform = $em->getRepository('AppsBundles:Platform');
  185.  
  186.         if(!$platform)
  187.         {
  188.             throw $this->createNotFoundException('No client for id '. $id);
  189.         }
  190.  
  191.         $form = $this->createFormBuilder($platform)->add('name','text')->add('save','submit')->getForm();
  192.         $form->handleRequest($request);
  193.  
  194.         if($form->isValid())
  195.         {
  196.             $em->flush();
  197.             return new Response('Clients updated successfully');
  198.         }
  199.  
  200.         $build['form'] = $form->createView();
  201.  
  202.         return $this->render('AppsBundle:Default:platform_add.html.twig', $build);
  203.     }
  204.  
  205. //Delete
  206.     public function deleteAppAction($id, Request $request)
  207.     {
  208.         $em = $this->getDoctrine()->getManager();
  209.         $app = $em->getRepository('AppsBundles:App')->find($id);
  210.  
  211.         if(!$app)
  212.         {
  213.             throw $this->createNotFoundException('No app found for id '.$id);
  214.         }
  215.  
  216.         $form = $this->createFormBuilder($app)->add('name','text')->add('version','text')->add('save','submit')->getForm();
  217.         $form->handleRequest($request);
  218.  
  219.         if (!$form->isValid())
  220.         {
  221.             $em->remove($app);
  222.             $em->flush();
  223.             return new Response('App deleted successfully');
  224.         }
  225.  
  226.         $build['form'] = $form->createView();
  227.         return $this->render('FooNewsBundle:Default:news_add.html.twig', $build);
  228.     }
  229.     public function deleteClientAction($id, Request $request)
  230.     {
  231.         $em = $this->getDoctrine()->getManager();
  232.         $client = $em->getRepository('AppsBundles:App')->find($id);
  233.  
  234.         if(!$client)
  235.         {
  236.             throw $this->createNotFoundException('No app found for id '.$id);
  237.         }
  238.  
  239.         $form = $this->createFormBuilder($client)->add('name','text')->add('save','submit')->getForm();
  240.         $form->handleRequest($request);
  241.  
  242.         if (!$form->isValid())
  243.         {
  244.             $em->remove($client);
  245.             $em->flush();
  246.             return new Response('App deleted successfully');
  247.         }
  248.  
  249.         $build['form'] = $form->createView();
  250.         return $this->render('FooNewsBundle:Default:news_add.html.twig', $build);
  251.     }
  252.     public function deletePlatformAction($id, Request $request)
  253.     {
  254.         $em = $this->getDoctrine()->getManager();
  255.         $platform = $em->getRepository('AppsBundles:App')->find($id);
  256.  
  257.         if(!$platform)
  258.         {
  259.             throw $this->createNotFoundException('No app found for id '.$id);
  260.         }
  261.  
  262.         $form = $this->createFormBuilder($platform)->add('name','text')->add('save','submit')->getForm();
  263.         $form->handleRequest($request);
  264.  
  265.         if (!$form->isValid())
  266.         {
  267.             $em->remove($platform);
  268.             $em->flush();
  269.             return new Response('App deleted successfully');
  270.         }
  271.  
  272.         $build['form'] = $form->createView();
  273.         return $this->render('FooNewsBundle:Default:news_add.html.twig', $build);
  274.     }
  275. }
Advertisement
Add Comment
Please, Sign In to add comment