Exemplo n.º 1
0
 public function getCollectionWithCategoria(\TemTudoAqui\Categoria $categoria, \TemTudoAqui\AbstractEntity $entity, $params = [], $fields = [], $type = self::RESULT_ARRAY)
 {
     $this->setFilter(function ($alias, $query) use($categoria) {
         if ($categoria->getId() > 0) {
             $query->innerJoin("{$alias}.produtos", 'p')->innerJoin("p.categorias", 'c')->andWhere($query->expr()->orX("c.subreferencia LIKE :subreferencial", "c.subreferencia = :subreferencia"))->setParameter('subreferencial', $categoria->getSubreferencia() . ".%")->setParameter('subreferencia', $categoria->getSubreferencia())->groupBy('p.marca');
         }
         return $query;
     });
     $rs = parent::getCollection($entity, $params, $fields, $type);
     return $rs;
 }
Exemplo n.º 2
0
 public function getCollectionWithCategoria(\TemTudoAqui\Categoria $categoria, $onlyWithImage = false, \TemTudoAqui\AbstractEntity $entity, $params = [], $fields = [], $type = self::RESULT_ARRAY)
 {
     $this->setFilter(function ($alias, $query) use($categoria, $onlyWithImage) {
         if ($categoria->getId() > 0) {
             $query->innerJoin("{$alias}.categorias", 'c')->andWhere($query->expr()->orX("c.subreferencia LIKE :subreferencial", "c.subreferencia = :subreferencia"))->setParameter('subreferencial', $categoria->getSubreferencia() . ".%")->setParameter('subreferencia', $categoria->getSubreferencia())->addSelect('c')->innerJoin('c.url', 'uc')->addSelect('uc');
         } else {
             $query->innerJoin("{$alias}.categorias", 'c')->addSelect('c')->innerJoin('c.url', 'uc')->addSelect('uc');
         }
         if ($onlyWithImage) {
             $query->leftJoin("{$alias}.imagens", 'i')->andWhere("i.sessao = 'produtos'")->orderBy('i.id', "DESC");
         }
         return $query;
     });
     $rs = parent::getCollection($entity, $params, $fields, $type);
     return $rs;
 }