src/Controller/RevueManagement/Numero2Controller.php line 121

Open in your IDE?
  1. <?php
  2. namespace App\Controller\RevueManagement;
  3. use App\Entity\LovManagement\NumeroStatus;
  4. use App\Entity\RevueManagement\Image;
  5. use App\Entity\RevueManagement\Numero2;
  6. use App\Entity\RevueManagement\Numero2History;
  7. use App\Entity\RevueManagement\Revue;
  8. use App\Entity\RevueManagement\RevueHistory;
  9. use App\Form\RevueManagement\Numero2Type;
  10. use App\Form\RevueManagement\Numero2DeleteType;
  11. use App\Manager\RevueManagement\ImageManager;
  12. use App\Manager\RevueManagement\ZipManager;
  13. use App\Message\RevueManagement\Numero2Message;
  14. use App\Message\RevueManagement\Numero2UpdateMessage;
  15. use App\Repository\RevueManagement\ImageRepository;
  16. use App\Repository\RevueManagement\Numero2Repository;
  17. use App\Repository\RevueManagement\PageRepository;
  18. use App\Service\RevueManagement\Numero2Service;
  19. use Doctrine\DBAL\Exception as DBALException;
  20. use Doctrine\ORM\Query;
  21. use Doctrine\ORM\QueryBuilder;
  22. use Omines\DataTablesBundle\Adapter\Doctrine\Event\ORMAdapterQueryEvent;
  23. use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
  24. use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapterEvents;
  25. use Omines\DataTablesBundle\Column\DateTimeColumn;
  26. use Omines\DataTablesBundle\Column\TextColumn;
  27. use Omines\DataTablesBundle\Column\TwigStringColumn;
  28. use Omines\DataTablesBundle\DataTableFactory;
  29. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  30. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  31. use Spatie\PdfToImage\Pdf;
  32. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  33. use Symfony\Component\Form\FormError;
  34. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  35. use Symfony\Component\HttpFoundation\JsonResponse;
  36. use Symfony\Component\HttpFoundation\Request;
  37. use Symfony\Component\HttpFoundation\Response;
  38. use Symfony\Component\HttpKernel\KernelInterface;
  39. use Symfony\Component\Messenger\MessageBusInterface;
  40. use Symfony\Component\Routing\Annotation\Route;
  41. use Symfony\Component\Serializer\SerializerInterface;
  42. use Symfony\Component\String\Slugger\SluggerInterface;
  43. use Symfony\Contracts\Translation\TranslatorInterface;
  44. use Twig\Environment;
  45. use Twig\Extension\StringLoaderExtension;
  46. /**
  47.  * @Route("/admin/numero2")
  48.  */
  49. class Numero2Controller extends AbstractController
  50. {
  51.     private $kernel;
  52.     private $messageBus;
  53.     private $slugger;
  54.     private $translator;
  55.     private $imageManager;
  56.     private $zipManager;
  57.     private $imageRepository;
  58.     private $numeroRepository;
  59.     private $serializer;
  60.     private $numeroService;
  61.     public function __construct(MessageBusInterface $messageBusTranslatorInterface $translatorKernelInterface $kernelSluggerInterface $sluggerImageManager $imageManagerZipManager $zipManagerImageRepository $imageRepositoryNumero2Repository $numeroRepositorySerializerInterface $serializerNumero2Service $numeroService)
  62.     {
  63.         $this->kernel $kernel;
  64.         $this->messageBus $messageBus;
  65.         $this->slugger $slugger;
  66.         $this->translator $translator;
  67.         $this->imageManager $imageManager;
  68.         $this->zipManager $zipManager;
  69.         $this->imageRepository $imageRepository;
  70.         $this->numeroRepository $numeroRepository;
  71.         $this->serializer $serializer;
  72.         $this->numeroService $numeroService;
  73.     }
  74.     /**
  75.      * replaced by admin_numero_omines
  76.      * 
  77.      * @Route("/index", name="admin_numero2_index", methods={"GET"})
  78.      * @Security("is_granted('ROLE_GESTION_NUMEROS')")
  79.      */
  80.     public function index(Numero2Repository $numeroRepository): Response
  81.     {
  82.         return $this->render('RevueManagement/Numero2/index.html.twig', [
  83.             'numeros' => $numeroRepository->findBy(['isDeleted' => false], ['updateDate' => 'DESC']),
  84.         ]);
  85.     }
  86.     /**
  87.      * @Route("/new/{id}", name="admin_revue_new_numero2", methods={"GET","POST"})
  88.      * @Security("is_granted('ROLE_GESTION_NUMEROS')")
  89.      */
  90.     public function new(Request $requestRevue $revue): Response
  91.     {
  92.         $numero = new Numero2();
  93.         $numero->setRevue($revue);
  94.         $form $this->createForm(Numero2Type::class, $numero);
  95.         $form->handleRequest($request);
  96.         if ($form->isSubmitted() && $form->isValid()) {
  97.             if ($result $this->numeroService->create($form$numero)) {
  98.                 return $this->redirectToRoute('admin_numero2_show', ['id' => $numero->getId()]);
  99.             }
  100.         }
  101.         return $this->render('RevueManagement/Numero2/new.html.twig', [
  102.             'numero' => $numero,
  103.             'form' => $form->createView(),
  104.             'revue' => $revue
  105.         ]);
  106.     }
  107.     /**
  108.      * @Route("/end/{numero}", name="admin_numero2_end", methods={"GET"})
  109.      */
  110.     public function end(Request $requestNumero2 $numero)
  111.     {
  112.         if ($numero->getNumeroStatus() != NumeroStatus::NUMERO_STATUS_END_TREATEMENT) {
  113.             return new JsonResponse(['end' => false]);
  114.         }
  115.         else {
  116.             return new JsonResponse(['end' => true'lastNumero2History' => $numero->getLastNumero2History()->getId()]);
  117.         }
  118.     }
  119.     /**
  120.      * @Route("/askTreatement/{id}", name="admin_numero2_ask_treatement", methods={"GET","POST"})
  121.      * @Security("is_granted('ROLE_GESTION_NUMEROS')")
  122.      */
  123.     public function askTreatement(Request $requestNumero2 $numero): Response
  124.     {
  125.         $this->numeroService->treatement($numero);
  126.         //redirect to last result in revue controller, set value to numeroID
  127.         return $this->redirectToRoute('admin_revue_show', ['id' => $numero->getRevue()->getId(), 'numeroID' => $numero->getId()]);
  128.         //redirect to last result
  129.         //return $this->redirectToRoute('admin_indexation_numero2History', ['numero2History' => $numero->getLastNumero2History()->getId()]);
  130.     }
  131.     /**
  132.      * @Route("/edit/{id}", name="admin_numero2_edit", methods={"GET","POST"})
  133.      * Security("is_granted('ROLE_GESTION_NUMEROS')")
  134.      */
  135.     public function edit(Request $requestNumero2 $numero): Response
  136.     {
  137.         $form $this->createForm(Numero2Type::class, $numero);
  138.         $form->handleRequest($request);
  139.         $old_numero $this->serializer->serialize($numero'json', ['groups' => 'detail']);
  140.         if ($form->isSubmitted() && $form->isValid()) {
  141.             if ($result $this->numeroService->update($form$numero$old_numero)) {
  142.                 return $this->redirectToRoute('admin_numero2_show', ['id' => $numero->getId()]);
  143.             }
  144.         }
  145.         return $this->render('RevueManagement/Numero2/edit.html.twig', [
  146.             'numero' => $numero,
  147.             'form' => $form->createView(),
  148.         ]);
  149.     }
  150.     /**
  151.      * @Route("/edit_flash/{id}", name="admin_numero2_edit_flash", methods={"GET","POST"})
  152.      * @Security("is_granted('ROLE_GESTION_NUMEROS')")
  153.      */
  154.     public function editFlash(Request $request,  Numero2 $numero): Response
  155.     {
  156.         $em $this->getDoctrine()->getManager();
  157.         $output = [];
  158.         $output['id'] = $request->get('pk');
  159.         $output['name'] = $request->get('name');
  160.         $output['value'] = $request->get('value');
  161.         switch ($request->get('name')) {
  162.             case 'description':
  163.                 $numero->setDescription($request->get('value'));
  164.                 break;
  165.             default:
  166.                 break;
  167.         }
  168.         $em->persist($numero);
  169.         $em->flush();
  170.         return new JsonResponse($output200);
  171.     }
  172.     /**
  173.      * @Route("/show/{id}", name="admin_numero2_show", methods={"GET"})
  174.      * @Security("is_granted('ROLE_GESTION_NUMEROS')")
  175.      */
  176.     public function show(Request $requestNumero2 $numero): Response
  177.     {
  178.         $form $this->createForm(Numero2DeleteType::class, $numero);
  179.         return $this->render('RevueManagement/Numero2/show.html.twig', [
  180.             'numero' => $numero,
  181.             'form' => $form->createView(),
  182.             'action' => $request->get('action'),
  183.         ]);
  184.     }
  185.     /**
  186.      * Desactive/Active un numero.
  187.      *
  188.      * @Route("/disable/{id}", name="admin_numero2_disable", methods={"GET","POST"})
  189.      * @Security("is_granted('ROLE_GESTION_NUMEROS')")
  190.      */
  191.     public function disable(Numero2 $numero): Response
  192.     {
  193.         $em $this->getDoctrine()->getManager();
  194.         if ($numero->getIsValid()) {
  195.             $numero->setIsValid(false);
  196.             $this->addFlash('success'$this->translator->trans('numero.flash.disable'));
  197.             $action 'disable';
  198.         } else {
  199.             $numero->setIsValid(true);
  200.             $this->addFlash('success'$this->translator->trans('numero.flash.enable'));
  201.             $action 'enable';
  202.         }
  203.         try {
  204.             $numero->setUpdateUser($this->getUser());
  205.             $em->persist($numero);
  206.             $em->flush();
  207.             
  208.             return $this->redirectToRoute('admin_revue_show', ['id' => $numero->getRevue()->getId()]);
  209.         } catch (DBALException $exception) {
  210.             $this->addFlash('error'$exception->getMessage());
  211.         }
  212.         return $this->redirectToRoute('admin_numero2_show', ['id' => $numero->getId(), 'action' => $action]);
  213.     }
  214. }