src/Controller/HistoriqueController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Sites;
  4. use App\Repository\CommandesRepository;
  5. use Knp\Component\Pager\PaginatorInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  10. class HistoriqueController extends AbstractController
  11. {
  12.     /**
  13.      * @Route("/historique", name="historique")
  14.      * @IsGranted("ROLE_USER")
  15.      */
  16.     public function HistoriqueList(
  17.         Request $request,
  18.         CommandesRepository $commandesRepository,
  19.         PaginatorInterface $paginator
  20.     ){
  21.         // 1 - Savoir qui est connecté
  22.         /** @var  $user */
  23.         $user = $this->getUser();
  24.         /** @var Sites */
  25.         $site = $user->getIdSite();
  26.         if ($this->isGranted('ROLE_MANAGER') or $this->isGranted('ROLE_ADMIN')){
  27.             $commandes = $commandesRepository->findBy(
  28.                 ['idSite' => $site],
  29.                 ['idSiteMagasin' => 'ASC', 'idOperationCommerciale' => 'DESC']
  30.             );
  31.         } else {
  32.             $commandes = $commandesRepository->findBy([
  33.                 'idSiteMagasin' => $this->getUser()->getIdSite()->getId()
  34.             ]);
  35.         }
  36.         /* Pagination (10 par page) */
  37.         $paginatedOrders = $paginator->paginate(
  38.             $commandes,
  39.             $request->query->getInt('page', 1),
  40.             10
  41.         );
  42.         return $this->render('historique/historiqueListe.html.twig', [
  43.             'historique' => true,
  44.             'commandes' => $paginatedOrders
  45.         ]);
  46.     }
  47. }