app/Plugin/CustomerGroup42/Repository/CategoryRepository.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of CustomerGroup
  4.  *
  5.  * Copyright(c) Akira Kurozumi <info@a-zumi.net>
  6.  *
  7.  * https://a-zumi.net
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\CustomerGroup42\Repository;
  13. use Doctrine\ORM\QueryBuilder;
  14. use Doctrine\Persistence\ManagerRegistry as RegistryInterface;
  15. use Eccube\Common\EccubeConfig;
  16. use Eccube\Doctrine\Query\Queries;
  17. class CategoryRepository extends \Eccube\Repository\CategoryRepository
  18. {
  19.     /**
  20.      * @var Queries
  21.      */
  22.     private Queries $queries;
  23.     public function __construct(
  24.         RegistryInterface $registry,
  25.         EccubeConfig $eccubeConfig,
  26.         Queries $queries
  27.     ) {
  28.         parent::__construct($registry$eccubeConfig);
  29.         $this->queries $queries;
  30.     }
  31.     /**
  32.      * @param array $searchData
  33.      *
  34.      * @return QueryBuilder
  35.      */
  36.     public function getQueryBuilderBySearchData(array $searchData): QueryBuilder
  37.     {
  38.         $qb $this->createQueryBuilder('c1')
  39.             ->select('c1, c2, c3, c4, c5')
  40.             ->leftJoin('c1.Children''c2')
  41.             ->leftJoin('c2.Children''c3')
  42.             ->leftJoin('c3.Children''c4')
  43.             ->leftJoin('c4.Children''c5')
  44.             ->orderBy('c1.sort_no''DESC')
  45.             ->addOrderBy('c2.sort_no''DESC')
  46.             ->addOrderBy('c3.sort_no''DESC')
  47.             ->addOrderBy('c4.sort_no''DESC')
  48.             ->addOrderBy('c5.sort_no''DESC');
  49.         if (isset($searchData['parent']) && $searchData['parent']) {
  50.             $qb->where('c1.Parent = :Parent')->setParameter('Parent'$searchData['parent']);
  51.         } else {
  52.             $qb->where('c1.Parent IS NULL');
  53.         }
  54.         return $this->queries->customize(QueryKey::CATEGORY_SEARCH$qb$searchData);
  55.     }
  56. }