app/Plugin/ProductField/Repository/ConfigRepository.php line 67

Open in your IDE?
  1. <?php
  2. namespace Plugin\ProductField\Repository;
  3. use Eccube\Repository\AbstractRepository;
  4. use Plugin\ProductField\Entity\Config;
  5. use Doctrine\Persistence\ManagerRegistry as RegistryInterface;
  6. /**
  7.  * ConfigRepository
  8.  *
  9.  * This class was generated by the Doctrine ORM. Add your own custom
  10.  * repository methods below.
  11.  */
  12. class ConfigRepository extends AbstractRepository
  13. {
  14.     /**
  15.      * ConfigRepository constructor.
  16.      *
  17.      * @param RegistryInterface $registry
  18.      */
  19.     public function __construct(RegistryInterface $registry)
  20.     {
  21.         parent::__construct($registryConfig::class);
  22.     }
  23.     /**
  24.      * @param int $id
  25.      *
  26.      * @return null|Config
  27.      */
  28.     public function get($id 1)
  29.     {
  30.         return $this->find($id);
  31.     }
  32.     public function findNotIdKey($id 0,$meta_key 0){
  33.         //指定した以外のids以外のmeta_keyを検索
  34.         //a as 別名
  35.         $qb $this->createQueryBuilder('a')->where('not a.id = :id')->andWhere('a.meta_key = :meta_key')->setParameters(['id' => $id,'meta_key' => $meta_key]);
  36.         return $qb->getQuery()->getResult();
  37.     }
  38.     public function joinMetaKey($product_id 0){
  39.         $qb $this->createQueryBuilder('a')->select('a','b')->leftJoin('Plugin\ProductField\Entity\ProductFieldContent''b''WITH''(b.product_id = :product_id or b.product_id IS NULL) and a.meta_key = b.meta_key')
  40.         ->setParameters(['product_id' => $product_id])->orderBy('a.sort','ASC');
  41.         $qb =  $qb->getQuery()->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
  42.         $tmp = [];
  43.         $uniqueQb = [];
  44.         if(!empty($qb)){
  45.             //重複削除DISTINCT 使えないため
  46.             foreach ($qb as $q){
  47.                 if (!in_array($q['a_meta_key'], $tmp)) {
  48.                     $tmp[] = $q['a_meta_key'];
  49.                     $uniqueQb[] = $q;
  50.                 }
  51.             }
  52.         }
  53.         return $uniqueQb;
  54.     }
  55.     public function joinMetaKeyFind($product_id 0,$meta_key ""){
  56.         $qb $this->createQueryBuilder('a')->select('a','b')->leftJoin('Plugin\ProductField\Entity\ProductFieldContent''b''WITH''(b.product_id = :product_id or b.product_id IS NULL) and a.meta_key = b.meta_key')
  57.         ->where('a.meta_key = :meta_key')->setParameters(['product_id' => $product_id,'meta_key' => $meta_key])->orderBy('a.sort','ASC');
  58.         return $qb->getQuery()->getOneOrNullResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
  59.     }
  60. }