Advertisement
yamcsha

CollabController.php

Aug 25th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?php
  2.  
  3. class CollabController extends AbstractController
  4. {
  5.     /**
  6.      * @Route("/editmatform", name="collab_edit_mat_form", methods={"GET","POST"})
  7.      */
  8.     public function editmatform(Request $request)
  9.     {
  10.         $em = $this->getDoctrine()->getManager();
  11.         $id_collab = $request->request->get("collab");
  12.         $retiremat = $request->request->get("cbRetiremat");
  13.         $addMat = $request->request->get("cbAddmat");
  14.  
  15.         /** @var \App\Entity\Collab $collab */
  16.         $collab = $em->getRepository(Collab::class)->find($id_collab);
  17.         $materiels = $collab->getMateriels();
  18.  
  19.         if (! $retiremat) {
  20.             return $this->redirectToRoute('collab_edit_mat', ['id' => $id_collab]);
  21.         }
  22.  
  23.         foreach ($materiels as $materiel) {
  24.             if (in_array($materiel->getId(), $retiremat, false)) {
  25.                 $collab->removeMteriel($materiel);
  26.             }
  27.             $em->flush();
  28.         }
  29.  
  30.         return $this->redirectToRoute('collab_edit_mat', ['id' => $id_collab]);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement