src/Repository/Adherent/MagasinMarquesRepository.php line 136

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Adherent;
  3. use App\Entity\Adherent\BrandPicture;
  4. use App\Entity\Adherent\MagasinMarques;
  5. use App\Entity\Webfactory\Opc\OpcMarque;
  6. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  7. use Doctrine\ORM\Query\Expr\Join;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. /**
  10.  * @method MagasinMarques|null find($id, $lockMode = null, $lockVersion = null)
  11.  * @method MagasinMarques|null findOneBy(array $criteria, array $orderBy = null)
  12.  * @method MagasinMarques[]    findAll()
  13.  * @method MagasinMarques[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  14.  */
  15. class MagasinMarquesRepository extends ServiceEntityRepository
  16. {
  17.     public function __construct(ManagerRegistry $registry)
  18.     {
  19.         parent::__construct($registryMagasinMarques::class);
  20.     }
  21.     public function getSelectionOrdered($magasin)
  22.     {
  23.         return $this->createQueryBuilder('mm')
  24.             ->select('mm.id, mm.sort, mm.created_at, mm.updated_at, m.id as marque_id, m.name as marque_name, m.popoverInfo as popover, m.popoverInfoNl as popover_nl, om.id as opc_id')
  25.             ->leftJoin(OpcMarque::class, 'om'Join::WITH'om.idMarque = mm.marque AND om.kAdh = :mag')
  26.             ->innerJoin('mm.marque''m')
  27.             ->andWhere('mm.magasin = :mag')
  28.             ->andWhere('mm.active = 1')
  29.             ->setParameter('mag'$magasin)
  30.             ->orderBy('mm.sort''ASC')
  31.             ->getQuery()
  32.             ->getResult();
  33.     }
  34.     public function getBrandByCategory($magasin$categoryId$limit 10$page 1)
  35.     {
  36.         if ($page == 1) {
  37.             $page 0;
  38.         }
  39.         return $this->createQueryBuilder('mb')
  40.             ->join('mb.marque''ma''mb.marque = ma.id')
  41.             ->join('ma.category''categ''ma.category = categ.id')
  42.             ->where('mb.magasin = :mag')
  43.             ->andWhere('categ.id = :category')
  44.             ->setParameter('mag'$magasin)
  45.             ->setParameter('category'$categoryId)
  46.             ->setFirstResult($page)
  47.             ->setMaxResults($limit)
  48.             ->getQuery()->getResult();
  49.     }
  50.     public function getSearchedBrandByCategories($magasin$value$filters$limit$offset$order)
  51.     {
  52.         $brands $this->createQueryBuilder('mm');
  53.         $brands->leftJoin('mm.marque''b')
  54.             ->leftJoin('b.category''c')
  55.             ->leftJoin('mm.magasinMarquesException''mme'); // Joindre la table des exceptions
  56.         if ($value) {
  57.             $brands->andWhere('b.name LIKE :searchedValue')
  58.                 ->setParameter('searchedValue''%' $value '%');
  59.         }
  60.         $defaultConditions $brands->expr()->orX(); // Pour accumuler les conditions des filtres des catégories (pas eco et made france)
  61.         if (!empty($filters)) {
  62.             foreach ($filters as $index => $filter) {
  63.                 if (isset($filter['value'])) {
  64.                     switch ($filter['value']) {
  65.                         case 'eco-choice':
  66.                             $brands->andWhere('b.ecoBrand = :ecoBrand')
  67.                                 ->setParameter('ecoBrand'1);
  68.                             break;
  69.                         case 'made-france':
  70.                             $brands->andWhere('b.ofg = :ofg')
  71.                                 ->setParameter('ofg'1);
  72.                             break;
  73.                         default:
  74.                             $paramName 'catId_' $index;
  75.                             // On ajoute au groupe de conditions les catégories sélectionnées
  76.                             $defaultConditions->add(
  77.                                 $brands->expr()->orX(
  78.                                     $brands->expr()->andX(
  79.                                         'c.id = :' $paramName,
  80.                                         'mme.exceptionCat IS NULL'  // Exclure les marques exceptionnelles
  81.                                     ),
  82.                                     'mme.exceptionCat = :' $paramName '_exception'
  83.                                 )
  84.                             );
  85.                             $brands->setParameter($paramName$filter['id']);
  86.                             $brands->setParameter($paramName '_exception'$filter['id']);
  87.                             break;
  88.                     }
  89.                 }
  90.             }
  91.             // Appliquer les autres filtres seulement s'ils existent
  92.             if ($defaultConditions->count() > 0) {
  93.                 $brands->andWhere($defaultConditions);
  94.             }
  95.         }
  96.         // Filtre par magasin
  97.         $brands->andWhere('mm.magasin = :mag')
  98.             ->andWhere('mm.active = 1')
  99.             ->setParameter('mag'$magasin);
  100.         // Gestion de la pagination
  101.         $brands->setFirstResult($offset);
  102.         $brands->setMaxResults($limit);
  103.         $brands->groupBy('b.id');
  104.         // Si un ordre est demandé (par exemple, ordre alphabétique)
  105.         if ($order != "default") {
  106.             $brands->orderBy('b.name''ASC');
  107.         } else {
  108.             $brands->orderBy('mm.sort''ASC');
  109.         }
  110.         $result $brands->getQuery()->getResult();
  111.         return $result;
  112.     }
  113.     public function getAllBrands($magasin$limit 12$page 1$sort)
  114.     {
  115.         if ($page == 1) {
  116.             $page 0;
  117.         }
  118.         $brands $this->createQueryBuilder('mb')
  119.             ->leftJoin('mb.marque''m')
  120.             ->where('mb.magasin = :mag')
  121.             ->andWhere('mb.active = 1')
  122.             ->setParameter('mag'$magasin)
  123.             ->setFirstResult($page)
  124.             ->setMaxResults($limit);
  125.         if ($sort != "default") {
  126.             $brands->orderBy('m.name''ASC');
  127.         } else {
  128.             $brands->orderBy('mb.sort''ASC');
  129.         }
  130.         return $brands->getQuery()->getResult();
  131.     }
  132. }