src/Controller/Operation/OdrController.php line 68

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Operation;
  3. use App\Controller\APIController;
  4. use App\Model\Operation\Odr;
  5. use App\Service\APIKiwi;
  6. use Exception;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  10. /**
  11.  * Class OdrController.
  12.  *
  13.  * @Route("/offre-de-remboursement")
  14.  */
  15. class OdrController extends APIController
  16. {
  17.     /**
  18.      * @Route("/", name="kiwi_operation_odr")
  19.      *
  20.      * @throws Exception|TransportExceptionInterface
  21.      */
  22.     public function index(APIKiwi $APIKiwi)
  23.     {
  24.         $user $this->getUser();
  25.         if ($user) {
  26.             $odrResp $APIKiwi->getKiwi(['path' => '/odrs'.'?nbParticipations=true''token' => $user->getToken()]);
  27.             $odrs $this->batchDeserialize(json_decode($odrResp->getContent(), true)['hydra:member'], Odr::class, 'get_odrs');
  28.         } else {
  29.             $odrResp $this->APIKiwi->getPublicKiwi('odrs', [
  30.                 'nbParticipations' => true,
  31.                 'online' => true,
  32.                 'startDate[strictly_before]' => date('Y-m-d H:i:s'),
  33.                 'subscriptionEndDate[strictly_after]' => date('Y-m-d H:i:s'),
  34.             ]);
  35.             $odrs $this->batchDeserialize(json_decode($odrResp->getContent(), true)['hydra:member'], Odr::class, 'get_odrs');
  36.         }
  37.         if (=== count($odrs)) {
  38.             return $this->redirectToRoute('kiwi_operation_odr_show', ['odrId' => $odrs[0]->getId()]);
  39.         }
  40.         return $this->render('operation/odr/index.html.twig', [
  41.             'odrs' => $odrs,
  42.             'target_path' => 'kiwi_operation_odr',
  43.             'register_path' => 'kiwi_operation_odr_register_user',
  44.         ]);
  45.     }
  46.     /**
  47.      * @Route("/odr/{odrId}", name="kiwi_operation_odr_show")
  48.      */
  49.     public function show($odrId): Response
  50.     {
  51.         $odrResp $this->APIKiwi->getPublicKiwi('odr/'.$odrId);
  52.         $odr $this->deserialize($odrResp->getContent(), Odr::class, 'get_odr');
  53.         $registerRoute 'kiwi_operation_odr_register_user';
  54.         $user null;
  55.         $userInterface $this->getUser();
  56.         if ($userInterface) {
  57.             $user $this->APIKiwi->getUserData($userInterface);
  58.         }
  59.          $this->requestStack->getSession()->set('kiwi_operation_odr_id'$odr->getId());
  60.          $this->requestStack->getSession()->set('_target_path''kiwi_operation_odr_form_participation_user');
  61.          $this->requestStack->getSession()->set('_target_path_params', ['odrId' => $odrId]);
  62.         return $this->render('operation/odr/details.html.twig', [
  63.             'odr' => $odr,
  64.             'register_path' => $registerRoute,
  65.             'target_path' => 'kiwi_operation_odr',
  66.             'user' => $user,
  67.         ]);
  68.     }
  69. }