src/Controller/Gestion/DashboardController.php line 21

  1. <?php
  2. namespace App\Controller\Gestion;
  3. use App\Form\SearchType;
  4. use App\Repository\Finder\SearchFinder;
  5. use App\Repository\OrderRepository;
  6. use App\Repository\ShopRepository;
  7. use Knp\Component\Pager\PaginatorInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  10. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. #[Route('/gestion')]
  15. class DashboardController extends AbstractController
  16. {
  17.     #[Route('/'name'app_gestion_dashboard_index')]
  18.     public function index(
  19.         OrderRepository $repository,
  20.         PaginatorInterface $paginator,
  21.         Request $request,
  22.         ShopRepository $shopRepository,
  23.     ): Response {
  24.         $query $repository->findDefault();
  25.         $form $this
  26.             ->createForm(SearchType::class, [
  27.                 'q' => $request->get('q'),
  28.                 'shop' => $request->get('shop'),
  29.                 'archived' => (bool)$request->get('archived'),
  30.             ])
  31.             ->add('shop'ChoiceType::class, [
  32.                 'choices' => $shopRepository->findList(),
  33.                 'label'=> false,
  34.                 'placeholder' => 'Filtrer par boutique',
  35.             ])
  36.             ->add('archived'CheckboxType::class, [
  37.                 'false_values' => [null0],
  38.                 'required' => false,
  39.                 'label' => 'Commandes archivĂ©es'
  40.             ]);
  41.         if ($request->get('q')) {
  42.             $query SearchFinder::findLike(
  43.                 $query,
  44.                 $request->get('q'),
  45.                 $repository::SEARCH_FIELDS
  46.             );
  47.         }
  48.         if (!$request->get('archived')) {
  49.             $query->andWhere('o.ended = 0');
  50.         }
  51.         if ($shopId $request->get('shop')) {
  52.             $query
  53.                 ->andWhere('o.shop = :shop')
  54.                 ->setParameter('shop'$shopId);
  55.         }
  56.         $pagination $paginator->paginate(
  57.             $query,
  58.             $request->query->getInt('page'1),
  59.             $request->query->getInt('limit'20),
  60.             [
  61.                 PaginatorInterface::DEFAULT_SORT_FIELD_NAME => 'o.dateUpdate',
  62.                 PaginatorInterface::DEFAULT_SORT_DIRECTION => 'DESC',
  63.                 PaginatorInterface::PAGE_OUT_OF_RANGE => PaginatorInterface::PAGE_OUT_OF_RANGE_FIX
  64.             ]
  65.         );
  66.         return $this->render('gestion/dashboard/index.html.twig', [
  67.             'pagination' => $pagination,
  68.             'search_form' => $form->createView(),
  69.         ]);
  70.     }
  71. }