@@ -3,21 +3,46 @@ | |||
namespace Lc\CaracoleBundle\Repository\Product; | |||
use Knp\Component\Pager\PaginatorInterface; | |||
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | |||
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait; | |||
use Lc\CaracoleBundle\Repository\StatusRepositoryQueryTrait; | |||
use Lc\CaracoleBundle\Repository\TreeRepositoryQueryTrait; | |||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||
class ProductCategoryRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
use SectionRepositoryQueryTrait; | |||
use StatusRepositoryQueryTrait; | |||
use TreeRepositoryQueryTrait; | |||
protected $isJoinProductFamilies = false; | |||
public function __construct(ProductCategoryRepository $repository, PaginatorInterface $paginator) | |||
{ | |||
parent::__construct($repository, 'r', $paginator); | |||
} | |||
public function filterIsParent(){ | |||
return $this->andWhere('.parent is NULL'); | |||
public function joinProductFamilies(): self | |||
{ | |||
if (!$this->isJoinProductFamilies) { | |||
$this->isJoinProductFamilies = true; | |||
return $this | |||
->innerJoin('.productFamilies', 'pf'); | |||
} | |||
return $this; | |||
} | |||
public function hasProductFamilyOnline(): self | |||
{ | |||
$this->joinProductFamilies(); | |||
return $this->andWhere('pf.status = 1'); | |||
} | |||
public function filterByCurrentDay(): self | |||
{ | |||
return $this->andWhere('e.displaySpecificDay IS NULL OR e.displaySpecificDay = :dayToday') | |||
->setParameter('dayToday', date('N')); | |||
} | |||
} |
@@ -2,6 +2,7 @@ | |||
namespace Lc\CaracoleBundle\Repository\Product; | |||
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; | |||
use Lc\CaracoleBundle\Repository\SectionStoreTrait; | |||
use Lc\SovBundle\Repository\AbstractStore; | |||
@@ -16,13 +17,45 @@ class ProductCategoryStore extends AbstractStore | |||
$this->query = $query; | |||
} | |||
public function getParents(){ | |||
public function getParents() | |||
{ | |||
$query = $this->query->create(); | |||
if($this->section) { | |||
if ($this->section) { | |||
$query->filterBySection($this->section); | |||
} | |||
$query->filterIsParent(); | |||
return $query->find(); | |||
} | |||
//findAllByParent | |||
public function getByParent( | |||
ProductCategoryInterface $parentCategory, | |||
bool $withOffline = false, | |||
bool $withEmptyCategories = true, | |||
bool $filterBySpecificDay = false | |||
): array { | |||
$query = $this->query->create(); | |||
$query->filterByParent($parentCategory); | |||
if ($withOffline) { | |||
$query->filterIsOnlineAndOffline(); | |||
} else { | |||
$query->filterIsOnline(); | |||
} | |||
if (!$withEmptyCategories) { | |||
$query->hasProductFamilyOnline(); | |||
} | |||
if ($filterBySpecificDay) { | |||
$query->filterBySpecificDay(); | |||
} | |||
$query->orderBy('position', 'asc'); | |||
return $query->find(); | |||
} | |||
} |
@@ -0,0 +1,26 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Repository; | |||
trait StatusRepositoryQueryTrait | |||
{ | |||
public function filterByStatus(int $status):self | |||
{ | |||
return $this->andWhere('.status = :status')->setParameter(':status', $status); | |||
} | |||
public function filterIsOffline():self | |||
{ | |||
return $this->andWhere('.status = :status')->setParameter(':status', 0); | |||
} | |||
public function filterIsOnline():self | |||
{ | |||
return $this->andWhere('.status = :status')->setParameter(':status', 1); | |||
} | |||
public function filterIsOnlineAndOffline():self | |||
{ | |||
return $this->andWhere('.status >= 0'); | |||
} | |||
} |
@@ -0,0 +1,22 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Repository; | |||
use Lc\SovBundle\Doctrine\EntityInterface; | |||
trait TreeRepositoryQueryTrait | |||
{ | |||
public function filterIsParent(){ | |||
return $this->andWhere('.parent is NULL'); | |||
} | |||
public function filterIsChildren(){ | |||
return $this->andWhere('.parent is NOT NULL'); | |||
} | |||
public function filterByParent(EntityInterface $parent){ | |||
return $this->andWhere('.parent = :parent')->setParameter('parent', $parent); | |||
} | |||
} |