<?php
namespace Plugin\ProductField\Repository;
use Eccube\Repository\AbstractRepository;
use Plugin\ProductField\Entity\Config;
use Doctrine\Persistence\ManagerRegistry as RegistryInterface;
/**
* ConfigRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class ConfigRepository extends AbstractRepository
{
/**
* ConfigRepository constructor.
*
* @param RegistryInterface $registry
*/
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Config::class);
}
/**
* @param int $id
*
* @return null|Config
*/
public function get($id = 1)
{
return $this->find($id);
}
public function findNotIdKey($id = 0,$meta_key = 0){
//指定した以外のids以外のmeta_keyを検索
//a as 別名
$qb = $this->createQueryBuilder('a')->where('not a.id = :id')->andWhere('a.meta_key = :meta_key')->setParameters(['id' => $id,'meta_key' => $meta_key]);
return $qb->getQuery()->getResult();
}
public function joinMetaKey($product_id = 0){
$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')
->setParameters(['product_id' => $product_id])->orderBy('a.sort','ASC');
$qb = $qb->getQuery()->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
$tmp = [];
$uniqueQb = [];
if(!empty($qb)){
//重複削除DISTINCT 使えないため
foreach ($qb as $q){
if (!in_array($q['a_meta_key'], $tmp)) {
$tmp[] = $q['a_meta_key'];
$uniqueQb[] = $q;
}
}
}
return $uniqueQb;
}
public function joinMetaKeyFind($product_id = 0,$meta_key = ""){
$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')
->where('a.meta_key = :meta_key')->setParameters(['product_id' => $product_id,'meta_key' => $meta_key])->orderBy('a.sort','ASC');
return $qb->getQuery()->getOneOrNullResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
}
}