src/Controller/MachineController.php line 86

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Machine;
  4. use App\Entity\MachinePaperSizeMatrix;
  5. use App\Entity\PaperSize;
  6. use App\Form\MachinePaperSizeMatrixType;
  7. use App\Form\MachineType;
  8. use App\Repository\MachinePaperSizeMatrixRepository;
  9. use App\Repository\MachineRepository;
  10. use App\Repository\PaperSizeRepository;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Knp\Component\Pager\PaginatorInterface;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
  18. /**
  19.  * @Route("/admin/machine")
  20.  */
  21. class MachineController extends AbstractController
  22. {
  23.     /**
  24.      * @Route("/", name="machine_index", methods={"GET"})
  25.      */
  26.     public function index(MachineRepository $machineRepository,
  27.                           PaginatorInterface $paginator,Request $request,
  28.                           EntityManagerInterface $em): Response
  29.     {
  30.         $query $machineRepository->findAll();
  31.         $pagination $paginator->paginate(
  32.             $query/* query NOT result */
  33.             $request->query->getInt('page'1), /*page number*/
  34.             20/*limit per page*/
  35.             [
  36.                 'defaultSortFieldName'      => 'c.createdAt',
  37.                 'defaultSortDirection' => 'desc'
  38.             ]
  39.         );
  40.         return $this->render('machine/index.html.twig', [
  41.             'pagination' => $pagination
  42.         ]);
  43.     }
  44.     /**
  45.      * @Route("/new", name="machine_new", methods={"GET", "POST"})
  46.      */
  47.     public function new(Request $requestMachineRepository $machineRepository): Response
  48.     {
  49.         $machine = new Machine();
  50.         $form $this->createForm(MachineType::class, $machine);
  51.         $form->handleRequest($request);
  52.         if ($form->isSubmitted() && $form->isValid()) {
  53.             $machineRepository->add($machinetrue);
  54.             return $this->redirectToRoute('machine_index', [], Response::HTTP_SEE_OTHER);
  55.         }
  56.         return $this->renderForm('machine/new.html.twig', [
  57.             'machine' => $machine,
  58.             'form' => $form,
  59.         ]);
  60.     }
  61.     /**
  62.      * @Route("/{id}", name="machine_show", methods={"GET"})
  63.      */
  64.     public function show(Machine $machine): Response
  65.     {
  66.         return $this->render('machine/show.html.twig', [
  67.             'machine' => $machine,
  68.         ]);
  69.     }
  70.     /**
  71.      * @Route("/{id}/edit", name="machine_edit", methods={"GET", "POST"})
  72.      */
  73.     public function edit(Request $requestMachine $machineMachineRepository $machineRepository): Response
  74.     {
  75.         $form $this->createForm(MachineType::class, $machine);
  76.         $form->handleRequest($request);
  77.         if ($form->isSubmitted() && $form->isValid()) {
  78.             $machineRepository->add($machinetrue);
  79.             $this->addFlash('success''Machine updated.');
  80.             return $this->redirectToRoute('machine_edit', ['id' =>$machine->getId()], Response::HTTP_SEE_OTHER);
  81.         }
  82.         return $this->renderForm('machine/edit.html.twig', [
  83.             'machine' => $machine,
  84.             'form' => $form,
  85.         ]);
  86.     }
  87.     /**
  88.      * @Route("/{id}/paper_size_matrix_index", name="paper_size_matrix_index")
  89.      */
  90.     public function paper_size_matrix_index(Request $requestMachine $machineEntityManagerInterface $entityManager): Response
  91.     {
  92.         //Paper size matrix available
  93.         $paperSizes $machine->getPaperSizes();
  94.         //$machinePaperSizeMatrices = $machine->getMachinePaperSizeMatrices();
  95.         //$entityManager->initializeObject($machinePaperSizeMatrices);
  96.         //dump($machinePaperSizeMatrices);
  97.         //Check if the paper size matrix exists
  98. /*        foreach ($paperSizes as $paperSize){
  99.             $
  100.         }
  101.         dump($papersizes);*/
  102.         /*foreach ($machinePaperSizeMatrices as $machinePaperSizeMatrix){
  103.             foreach ($paperSizes as $paperSize){
  104.                 if ($machinePaperSizeMatrix->getPaperSize()->getName() == $machinePaperSize->getName()){
  105.                 }
  106.             }
  107.         }*/
  108.         $paperSizesAvailable = [];
  109.         return $this->render('machine/machine_paper_size_matrix_index.html.twig', [
  110.             'machine' => $machine,
  111.             'paperSizes' => $paperSizes
  112.         ]);
  113.     }
  114.     /**
  115.      * @Route("/paper_size_matrix_edit/{id}", name="paper_size_matrix_edit")
  116.      */
  117.     public function paper_size_matrix_edit(Request $requestMachinePaperSizeMatrix $machinePaperSizeMatrix,
  118.                                            MachinePaperSizeMatrixRepository$machinePaperSizeMatrixRepository): Response
  119.     {
  120.         //dump($machinePaperSizeMatrix);
  121.         $form $this->createForm(MachinePaperSizeMatrixType::class, $machinePaperSizeMatrix);
  122.         $form->handleRequest($request);
  123.         if ($form->isSubmitted() && $form->isValid()) {
  124.             $machinePaperSizeMatrixRepository->add($machinePaperSizeMatrixtrue);
  125.             $machine $machinePaperSizeMatrix->getMachine();
  126.             return $this->redirectToRoute('paper_size_matrix_index', ['id' => $machine->getId()], Response::HTTP_SEE_OTHER);
  127.         }
  128.         return $this->renderForm('machine/machine_paper_size_matrix_edit.html.twig', [
  129.             'machinePaperSizeMatrix' => $machinePaperSizeMatrix,
  130.             'machine' => $machinePaperSizeMatrix->getMachine(),
  131.             'form' => $form
  132.         ]);
  133.     }
  134.     /**
  135.      * @Route("/paper_size_matrix_new/{id}/paper_size/{paper_size_id}", name="paper_size_matrix_new")
  136.      * @Entity("paperSize", expr="repository.find(paper_size_id)")
  137.      */
  138.     public function machine_paper_size_matrix_new(Request $requestMachine $machine,
  139.         PaperSize $paperSizeMachinePaperSizeMatrixRepository $machinePaperSizeMatrixRepository
  140.         ): Response
  141.     {
  142.         //$paperSizeId = $request->request->get("paper_size_id");
  143.         $machinePaperSizeMatrix = new MachinePaperSizeMatrix();
  144.         $form $this->createForm(MachinePaperSizeMatrixType::class, $machinePaperSizeMatrix);
  145.         $form->handleRequest($request);
  146.         if ($form->isSubmitted() && $form->isValid()) {
  147.             $machinePaperSizeMatrix->setMachine($machine);
  148.             $machinePaperSizeMatrix->setPaperSize($paperSize);
  149.             $machinePaperSizeMatrixRepository->add($machinePaperSizeMatrixtrue);
  150.             return $this->redirectToRoute('paper_size_matrix_index', ['id' => $machine->getId()], Response::HTTP_SEE_OTHER);
  151.         }
  152.         return $this->renderForm('machine/machine_paper_size_matrix_new.html.twig', [
  153.             'machinePaperSizeMatrix' => $machinePaperSizeMatrix,
  154.             'machine' => $machine,
  155.             'paperSize' => $paperSize,
  156.             'form' => $form
  157.         ]);
  158.     }
  159.     /**
  160.      * @Route("/{id}", name="machine_delete", methods={"POST"})
  161.      */
  162.     public function delete(Request $requestMachine $machineMachineRepository $machineRepository): Response
  163.     {
  164.         if ($this->isCsrfTokenValid('delete'.$machine->getId(), $request->request->get('_token'))) {
  165.             $this->addFlash('success''Machine ID: '.$machine->getId().' deleted.');
  166.             $machineRepository->remove($machinetrue);
  167.         }
  168.         return $this->redirectToRoute('machine_index', [], Response::HTTP_SEE_OTHER);
  169.     }
  170. }