Eccube\Repository\CategoryRepository::getList PHP Method

getList() public method

引数 $Parent を指定した場合は, 指定したカテゴリの子以下を取得する.
public getList ( Category $Parent = null, boolean $flat = false ) : Category[]
$Parent Eccube\Entity\Category 指定の親カテゴリ
$flat boolean trueの場合, 階層化されたカテゴリを一つの配列にまとめる
return Eccube\Entity\Category[] カテゴリの配列
    public function getList(Category $Parent = null, $flat = false)
    {
        $options = $this->app['config']['doctrine_cache'];
        $lifetime = $options['result_cache']['lifetime'];
        $qb = $this->createQueryBuilder('c1')->select('c1, c2, c3, c4, c5')->leftJoin('c1.Children', 'c2')->leftJoin('c2.Children', 'c3')->leftJoin('c3.Children', 'c4')->leftJoin('c4.Children', 'c5')->orderBy('c1.rank', 'DESC')->addOrderBy('c2.rank', 'DESC')->addOrderBy('c3.rank', 'DESC')->addOrderBy('c4.rank', 'DESC')->addOrderBy('c5.rank', 'DESC');
        if ($Parent) {
            $qb->where('c1.Parent = :Parent')->setParameter('Parent', $Parent);
        } else {
            $qb->where('c1.Parent IS NULL');
        }
        $Categories = $qb->getQuery()->useResultCache(true, $lifetime)->getResult();
        if ($flat) {
            $array = array();
            foreach ($Categories as $Category) {
                $array = array_merge($array, $Category->getSelfAndDescendants());
            }
            $Categories = $array;
        }
        return $Categories;
    }