Sulu\Bundle\MediaBundle\Entity\CollectionRepository::findCollections PHP Method

findCollections() public method

public findCollections ( $filter = [], $limit = null, $offset = null, $sortBy = [] )
    public function findCollections($filter = [], $limit = null, $offset = null, $sortBy = [])
    {
        list($parent, $depth, $search) = [isset($filter['parent']) ? $filter['parent'] : null, isset($filter['depth']) ? $filter['depth'] : null, isset($filter['search']) ? $filter['search'] : null];
        try {
            $qb = $this->createQueryBuilder('collection')->leftJoin('collection.meta', 'collectionMeta')->leftJoin('collection.defaultMeta', 'defaultMeta')->leftJoin('collection.type', 'type')->leftJoin('collection.parent', 'parent')->leftJoin('collection.children', 'children')->addSelect('collectionMeta')->addSelect('defaultMeta')->addSelect('type')->addSelect('parent')->addSelect('children');
            if ($sortBy !== null && is_array($sortBy) && count($sortBy) > 0) {
                foreach ($sortBy as $column => $order) {
                    $qb->addOrderBy('collectionMeta.' . $column, strtolower($order) === 'asc' ? 'ASC' : 'DESC');
                }
            }
            $qb->addOrderBy('collection.id', 'ASC');
            if ($parent !== null) {
                $qb->andWhere('parent.id = :parent');
            }
            if ($depth !== null) {
                $qb->andWhere('collection.depth <= :depth');
            }
            if ($search !== null) {
                $qb->andWhere('collectionMeta.title LIKE :search');
            }
            if ($offset !== null) {
                $qb->setFirstResult($offset);
            }
            if ($limit !== null) {
                $qb->setMaxResults($limit);
            }
            $query = $qb->getQuery();
            if ($parent !== null) {
                $query->setParameter('parent', $parent);
            }
            if ($depth !== null) {
                $query->setParameter('depth', intval($depth));
            }
            if ($search !== null) {
                $query->setParameter('search', '%' . $search . '%');
            }
            return new Paginator($query);
        } catch (NoResultException $ex) {
            return;
        }
    }