src/Controller/Marketplace/UserController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Marketplace;
  3. use App\Entity\Company;
  4. use App\Entity\MarketplaceReservation;
  5. use App\Entity\UserFavorite;
  6. use App\Form\Marketplace\CompanyMarketplaceType;
  7. use App\Manager\ConfigurationManager;
  8. use App\Repository\MarketplaceReservationRepository;
  9. use App\Service\ToolsService;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  12. use Knp\Snappy\Pdf;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. class UserController extends AbstractController
  19. {
  20.     /**
  21.      * @var ConfigurationManager
  22.      */
  23.     private $configurationManager;
  24.     public function __construct(ConfigurationManager $configurationManager)
  25.     {
  26.         $this->configurationManager $configurationManager;
  27.     }
  28.     /**
  29.      * @IsGranted("ROLE_USER")
  30.      * @Route("/mon-compte", name="app_user")
  31.      */
  32.     public function index(Request $requestEntityManagerInterface $em): Response
  33.     {
  34.         $company $em->getRepository(Company::class)->find($this->getUser()->getCompany()->getId()) ?? null;
  35.         try {
  36.             // $reservations = $em->getRepository(MarketplaceReservation::class)->findBy([
  37.             //     'user' => $this->getUser()->getId(),
  38.             // ],['createdAt' => "DESC"]);
  39.             $reservations $em->getRepository(MarketplaceReservation::class)->getMarketplaceReservationsForClient($this->getUser()->getId());
  40.         } catch (\Throwable $th) {
  41.             throw $th;
  42.         }
  43.         try {
  44.             $demandes $em->getRepository(MarketplaceReservation::class)->findBy([
  45.                 'user' => $this->getUser()->getId(),
  46.                 'paymentAmount' => null,
  47.                 // 'status'    => MarketplaceReservation::STATUS_PENDING,
  48.             ], ['createdAt' => "DESC"]);
  49.         } catch (\Throwable $th) {
  50.             //throw $th;
  51.         }
  52.         try {
  53.             $demandes array_merge($demandes$em->getRepository(MarketplaceReservation::class)->findBy([
  54.                 'user' => $this->getUser()->getId(),
  55.                 'paymentAmount' => 0,
  56.                 // 'status'    => MarketplaceReservation::STATUS_PENDING,
  57.             ], ['createdAt' => "DESC"]));
  58.         } catch (\Throwable $th) {
  59.             //throw $th;
  60.         }
  61.         
  62.         try {
  63.             $favorites $em->getRepository(UserFavorite::class)->findBy([ // Récupération des favoris
  64.                 'user' => $this->getUser()->getId(),
  65.             ], ['createdAt' => "DESC"]);
  66.         } catch (\Throwable $th) {
  67.             //throw $th;
  68.         }
  69.             
  70.         $form $this->createForm(CompanyMarketplaceType::class, $company);
  71.         $form->handleRequest($request);
  72.         if ($form->isSubmitted() ) {
  73.             $em->persist($company);
  74.             $em->flush();
  75.             $this->addFlash('success''Informations modifiées');
  76.         }
  77.         return $this->render('marketplace/user/index.html.twig', [
  78.             'reservations' => $reservations ?? [],
  79.             'demandes' => $demandes ?? [],
  80.             'form'  => $form->createView(),
  81.             'nav'   => $request->query->getInt('nav'1),
  82.             'favorites' => $favorites ?? [],
  83.         ]);
  84.     }
  85.     /**
  86.      * @IsGranted("ROLE_USER")
  87.      * @Route("/mon-compte/facture/{reservationId}", name="reservation_invoice")
  88.      */
  89.     public function reservationInvoice(Request $requestMarketplaceReservationRepository $marketplaceResRepoPdf $knpSnappyPdfToolsService $toolsint $reservationId)
  90.     {
  91.         $reservation $marketplaceResRepo->find($reservationId);
  92.         $ulteam $this->configurationManager->getInvoiceSellerData();
  93.         $name "Facture pour l'atelier du " $reservation->getDateStart()->format('d-m-Y');
  94.         if (!empty($reservation)) {
  95.             $html $this->renderView('marketplace/components/pdf_invoice.html.twig',
  96.                 [
  97.                     'name' => $name,
  98.                     'reservation' => $reservation,
  99.                     'ulteam' => $ulteam,
  100.                 ]);
  101.             $footerHtml $this->renderView('marketplace/components/invoice_footer.html.twig');
  102.             $knpSnappyPdf->setOption('footer-html'$footerHtml);    
  103.             $knpSnappyPdf->setOption('enable-local-file-access'true);
  104.             return new PdfResponse($knpSnappyPdf->getOutputFromHtml($html), "$name.pdf");
  105.         }
  106.     }
  107. }