Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Mag\AppsBundle\Controller;
- use Mag\AppsBundle\Entity\App;
- use Mag\AppsBundle\Entity\Client;
- use Mag\AppsBundle\Entity\Platform;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- class DefaultController extends Controller
- {
- //Index
- public function indexAppAction($apps)
- {
- //return $this->render('AppsBundle:Default:index.html.twig', array('name' => $name));
- $apps = $this->getDoctrine()->getRepository('AppBundles:App')->findAll();
- if(!$apps)
- {
- throw $this->createNotFoundException('No apps found');
- }
- $build['apps'] = $apps;
- return $this->render('AppBundle:Default:apps_show_all.html.twig', $build);
- }
- public function indexClientsAction($clients)
- {
- $clients = $this->getDoctrine()->getRepository('AppBundles:Client')->findAll();
- if(!$clients)
- {
- throw $this->createNotFoundException('No clients found');
- }
- $build['clients'] = $clients;
- return $this->render('AppBundle:Default:clients_show_all.html.twig',$build);
- }
- public function indexPlatformAction($platforms)
- {
- $platforms = $this->getDoctrine()->getRepository('AppBundles:Platform')->findAll();
- if(!$platforms)
- {
- throw $this->createNotFoundException('No platforms found');
- }
- $build['platforms'] = $platforms;
- return $this->render('AppBundle:Default:clients_show_all.html.twig',$build);
- }
- //Show
- public function showAppAction($id)
- {
- $apps = $this->getDoctrine()->getRepository('AppBundles:App')->find($id);
- if(!$apps)
- {
- throw $this->createNotFoundException('No Apps found by id'.$id);
- }
- $build['apps_item'] = $apps;
- return $this->render('AppsBundle:Default:apps_show.html.twig', $build);
- }
- public function showClientAction($id)
- {
- $clients = $this->getDoctrine()->getRepository('AppBundles:Client')->find($id);
- if(!$clients)
- {
- throw $this->createNotFoundException('No Clients found by id'.$id);
- }
- $build['clients_item'] = $clients;
- return $this->render('AppsBundle:Default:clients_show.html.twig', $build);
- }
- public function showPlatformAction($id)
- {
- $platforms = $this->getDoctrine()->getRepository('AppBundles:Platforms')->find($id);
- if(!$platforms)
- {
- throw $this->createNotFoundException('No Platforms found by id'.$id);
- }
- $build['platforms_item'] = $platforms;
- return $this->render('AppsBundle:Default:platforms_show.html.twig', $build);
- }
- //Add
- public function addAppAction(Request $request)
- {
- $app = new App();
- $form = $this->createFormBuilder($app)->add('name','text')->add('version','text')->add('save','submit')->getForm();
- $form->handleRequest($request);
- if($form->isValid())
- {
- $em = $this->getDoctrine()->getManager();
- $em->persist($app);
- $em->flush();
- return new Response('App added successfuly');
- }
- $build['form'] = $form->createView();
- return $this->render('AppsBundle:Default:app_add.html.twig', $build);
- }
- public function addClientAction(Request $request)
- {
- $client = new Client();
- $form = $this->createFormBuilder($client)->add('name','text')->add('save','submit')->getForm();
- if($form->isValid())
- {
- $em = $this->getDoctrine()->getManager();
- $em->persist($client);
- $em->flush();
- return new Response('Client added successfuly');
- }
- $build['form'] = $form->createView();
- return $this->render('AppsBundle:Default:client_add.html.twig', $build);
- }
- public function addPlatformAction(Request $request)
- {
- $platform = new Platform();
- $form = $this->createFormBuilder($platform)->add('name','text')->add('save','submit')->getForm();
- if($form->isValid())
- {
- $em = $this->getDoctrine()->getManager();
- $em->persist($platform);
- $em->flush();
- return new Response('Platform added successfuly');
- }
- $build['form'] = $form->createView();
- return $this->render('AppsBundle:Default:client_add.html.twig', $build);
- }
- //Edit
- public function editAppAction($id, Request $request)
- {
- $em = $this->getDoctrine()->getManager();
- $app = $em->getRepository('AppsBundle:App');
- if(!$app)
- {
- throw $this->createNotFoundException('No apps found for id '. $id);
- }
- $form = $this->createFormBuilder($app)->add('name','text')->add('version','text')->add('save','submit')->getForm();
- $form->handleRequest($request);
- if($form->isValid())
- {
- $em->flush();
- return new Response('Apps updated successfully');
- }
- $build['form'] = $form->createView();
- return $this->render('AppsBundle:Default:app_add.html.twig', $build);
- }
- public function editClientAction($id, Request $request)
- {
- $em = $this->getDoctrine()->getManager();
- $client = $em->getRepository('AppsBundles:Client');
- if(!$client)
- {
- throw $this->createNotFoundException('No client for id '. $id);
- }
- $form = $this->createFormBuilder($client)->add('name','text')->add('save','submit')->getForm();
- $form->handleRequest($request);
- if($form->isValid())
- {
- $em->flush();
- return new Response('Clients updated successfully');
- }
- $build['form'] = $form->createView();
- return $this->render('AppsBundle:Default:client_add.html.twig', $build);
- }
- public function editPlatformAction($id, Request $request)
- {
- $em = $this->getDoctrine()->getManager();
- $platform = $em->getRepository('AppsBundles:Platform');
- if(!$platform)
- {
- throw $this->createNotFoundException('No client for id '. $id);
- }
- $form = $this->createFormBuilder($platform)->add('name','text')->add('save','submit')->getForm();
- $form->handleRequest($request);
- if($form->isValid())
- {
- $em->flush();
- return new Response('Clients updated successfully');
- }
- $build['form'] = $form->createView();
- return $this->render('AppsBundle:Default:platform_add.html.twig', $build);
- }
- //Delete
- public function deleteAppAction($id, Request $request)
- {
- $em = $this->getDoctrine()->getManager();
- $app = $em->getRepository('AppsBundles:App')->find($id);
- if(!$app)
- {
- throw $this->createNotFoundException('No app found for id '.$id);
- }
- $form = $this->createFormBuilder($app)->add('name','text')->add('version','text')->add('save','submit')->getForm();
- $form->handleRequest($request);
- if (!$form->isValid())
- {
- $em->remove($app);
- $em->flush();
- return new Response('App deleted successfully');
- }
- $build['form'] = $form->createView();
- return $this->render('FooNewsBundle:Default:news_add.html.twig', $build);
- }
- public function deleteClientAction($id, Request $request)
- {
- $em = $this->getDoctrine()->getManager();
- $client = $em->getRepository('AppsBundles:App')->find($id);
- if(!$client)
- {
- throw $this->createNotFoundException('No app found for id '.$id);
- }
- $form = $this->createFormBuilder($client)->add('name','text')->add('save','submit')->getForm();
- $form->handleRequest($request);
- if (!$form->isValid())
- {
- $em->remove($client);
- $em->flush();
- return new Response('App deleted successfully');
- }
- $build['form'] = $form->createView();
- return $this->render('FooNewsBundle:Default:news_add.html.twig', $build);
- }
- public function deletePlatformAction($id, Request $request)
- {
- $em = $this->getDoctrine()->getManager();
- $platform = $em->getRepository('AppsBundles:App')->find($id);
- if(!$platform)
- {
- throw $this->createNotFoundException('No app found for id '.$id);
- }
- $form = $this->createFormBuilder($platform)->add('name','text')->add('save','submit')->getForm();
- $form->handleRequest($request);
- if (!$form->isValid())
- {
- $em->remove($platform);
- $em->flush();
- return new Response('App deleted successfully');
- }
- $build['form'] = $form->createView();
- return $this->render('FooNewsBundle:Default:news_add.html.twig', $build);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment