src/Controller/Backend/ProductionCompanyController.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Backend;
  3. use App\Entity\ProductionCompany;
  4. use App\Services\Helper;
  5. use Exception;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class ProductionCompanyController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/{_locale}/dashboard/production-company/list")
  15.      */
  16.     public function listProductionsAction(Request $request){
  17.         $em $this->getDoctrine()->getManager();
  18.         $productions $em->getRepository(ProductionCompany::class)->findBy(['deleted' => 0]);
  19.         return $this->render('/backend/productions/list.html.twig',[
  20.             'productions' => $productions
  21.         ]);
  22.     }
  23.     /**
  24.      * @Route("/{_locale}/dashboard/production-company/edit/{idProduction}")
  25.      * @Route("/{_locale}/dashboard/production-company/add", defaults={"idProduction":null})
  26.      */
  27.     public function editProductionsAction(Request $requestHelper $helper){
  28.         $em $this->getDoctrine()->getManager();
  29.         $idProduction $helper->sanitize($request->get('idProduction'));
  30.         $production $em->getRepository(ProductionCompany::class)->findOneBy(['idProduction' => $idProduction]);
  31.         if(!$production){
  32.             $production = new ProductionCompany();
  33.         }
  34.         return $this->render('backend/productions/edit.html.twig',[
  35.             'production' => $production
  36.         ]);
  37.     }
  38.     /**
  39.      * @Route("/{_locale}/dashboard/production-company/save")
  40.      */
  41.     public function productionSaveAction(Request $requestHelper $helper){
  42.         $em $this->getDoctrine()->getManager();
  43.         $response = new JsonResponse();
  44.         try{
  45.             $idProduction $helper->sanitize($request->request->get('idProduction'));
  46.             $name $helper->sanitize($request->request->get('name'));
  47.             $production $em->getRepository(ProductionCompany::class)->findOneBy(['idProduction' => $idProduction]);
  48.             if(!$production){
  49.                 $production = new ProductionCompany();
  50.             }
  51.             $production->setName($name);
  52.             $production->setDeleted(0);
  53.             $em->persist($production);
  54.             $em->flush();
  55.             $response->setStatusCode(200);
  56.             $response->setData(array(
  57.                 'response' => 'success',
  58.                 'msg' => 'Action performed successfully',
  59.                 'idProduction' => $production->getIdProduction()
  60.             ));
  61.             return $response;
  62.         } catch(Exception $e){
  63.             $response->setStatusCode(500);
  64.             $response->setData(array(
  65.                 'response' => 'error',
  66.                 'msg' => 'Something has gone wrong'
  67.             ));
  68.             return $response;
  69.         }
  70.     }
  71.     /**
  72.      * @Route("/{_locale}/dashboard/production-company/delete")
  73.      */
  74.     public function productionDeleteAction(Request $requestHelper $helper){
  75.         $em $this->getDoctrine()->getManager();
  76.         $response = new JsonResponse();
  77.         try{
  78.             $idProduction $helper->sanitize($request->request->get('idProduction'));
  79.             $production $em->getRepository(ProductionCompany::class)->findOneBy(['idProduction' => $idProduction]);
  80.             $production->setDeleted(1);
  81.             $em->persist($production);
  82.             $em->flush();
  83.             $response->setStatusCode(200);
  84.             $response->setData(array(
  85.                 'response' => 'success'
  86.             ));
  87.             return $response;
  88.         } catch(Exception $e){
  89.             $response->setStatusCode(500);
  90.             $response->setData(array(
  91.                 'response' => 'error',
  92.                 'msg' => 'Something has gone wrong'
  93.             ));
  94.             return $response;
  95.         }
  96.     }
  97. }