<?php
namespace App\Trinity\WebshopBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* SpecRepository
*/
class SpecRepository extends EntityRepository
{
public function countBy($Webshop, $SpecGroup = null){
$em = $this->getEntityManager();
$query = $em->createQuery(
'SELECT count(p)
FROM TrinityWebshopBundle:Spec p
' . ($SpecGroup != null ? 'JOIN p.groups g WITH g.id = ' . $SpecGroup->getId() . '' : '') . '
WHERE p.webshop = ' . $Webshop->getId() . '
'
);
return $query->getSingleScalarResult();
}
public function getBy($Webshop, $SpecGroup = null, $offset, $limit){
$em = $this->getEntityManager();
$query = $em->createQuery(
'SELECT p
FROM TrinityWebshopBundle:Spec p
' . ($SpecGroup != null ? 'JOIN p.groups g WITH g.id = ' . $SpecGroup->getId() . '' : '') . '
WHERE p.webshop = ' . $Webshop->getId() . '
ORDER BY p.position, p.label'
);
return $query->setFirstResult($offset)->setMaxResults($limit)->getResult();
}
public function getByGroupAndLabel($Webshop, $SpecGroup, $Label){
$em = $this->getEntityManager();
$query = $em->createQuery(
'SELECT p
FROM TrinityWebshopBundle:Spec p
' . ($SpecGroup != null ? 'JOIN p.groups g WITH g.id = ' . $SpecGroup->getId() . '' : '') . '
WHERE p.webshop = ' . $Webshop->getId() . '
AND p.label = :label
ORDER BY p.position, p.label'
)->setParameter('label', $Label);
return $query->getResult();
}
public function search($Webshop, $q){
$em = $this->getEntityManager();
$query = $em->createQuery(
'SELECT p
FROM TrinityWebshopBundle:Spec p
WHERE p.label LIKE :q
AND p.webshop = ' . $Webshop->getId() . '
ORDER BY p.position, p.label'
)
->setParameter('q', '%' . $q . '%');
return $query->getResult();
}
}