use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | ||||
use Lc\CaracoleBundle\Model\User\UserPointSaleInterface; | use Lc\CaracoleBundle\Model\User\UserPointSaleInterface; | ||||
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; | use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; | ||||
use App\Entity\File\File; | |||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
protected $userPointSales; | protected $userPointSales; | ||||
/** | |||||
* @ORM\ManyToOne(targetEntity=File::class, cascade={"persist", "remove"}) | |||||
*/ | |||||
protected $image; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getImage(): ?File | |||||
{ | |||||
return $this->image; | |||||
} | |||||
public function setImage(?File $image): self | |||||
{ | |||||
$this->image = $image; | |||||
return $this; | |||||
} | |||||
} | } |
namespace Lc\CaracoleBundle\Repository\Product; | namespace Lc\CaracoleBundle\Repository\Product; | ||||
use Knp\Component\Pager\PaginatorInterface; | use Knp\Component\Pager\PaginatorInterface; | ||||
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | |||||
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait; | use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait; | ||||
use Lc\CaracoleBundle\Repository\StatusRepositoryQueryTrait; | |||||
use Lc\CaracoleBundle\Repository\TreeRepositoryQueryTrait; | |||||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | use Lc\SovBundle\Repository\AbstractRepositoryQuery; | ||||
class ProductCategoryRepositoryQuery extends AbstractRepositoryQuery | class ProductCategoryRepositoryQuery extends AbstractRepositoryQuery | ||||
{ | { | ||||
use SectionRepositoryQueryTrait; | use SectionRepositoryQueryTrait; | ||||
use StatusRepositoryQueryTrait; | |||||
use TreeRepositoryQueryTrait; | |||||
protected $isJoinProductFamilies = false; | |||||
public function __construct(ProductCategoryRepository $repository, PaginatorInterface $paginator) | public function __construct(ProductCategoryRepository $repository, PaginatorInterface $paginator) | ||||
{ | { | ||||
parent::__construct($repository, 'r', $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')); | |||||
} | } | ||||
} | } |
namespace Lc\CaracoleBundle\Repository\Product; | namespace Lc\CaracoleBundle\Repository\Product; | ||||
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; | |||||
use Lc\CaracoleBundle\Repository\SectionStoreTrait; | use Lc\CaracoleBundle\Repository\SectionStoreTrait; | ||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
public function getParents(){ | |||||
public function getParents() | |||||
{ | |||||
$query = $this->query->create(); | $query = $this->query->create(); | ||||
if($this->section) { | |||||
if ($this->section) { | |||||
$query->filterBySection($this->section); | $query->filterBySection($this->section); | ||||
} | } | ||||
$query->filterIsParent(); | $query->filterIsParent(); | ||||
return $query->find(); | 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(); | |||||
} | |||||
} | } |
<?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'); | |||||
} | |||||
} |
<?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); | |||||
} | |||||
} |