Browse Source

Store : système de filter by section et merchant required ou optionnal

packProduct
Guillaume 3 years ago
parent
commit
a8eb113009
4 changed files with 77 additions and 14 deletions
  1. +47
    -0
      Repository/MerchantStoreTrait.php
  2. +0
    -7
      Repository/Order/OrderShopRepositoryQuery.php
  3. +3
    -7
      Repository/Order/OrderShopStore.php
  4. +27
    -0
      Repository/SectionStoreTrait.php

+ 47
- 0
Repository/MerchantStoreTrait.php View File

namespace Lc\CaracoleBundle\Repository; namespace Lc\CaracoleBundle\Repository;


use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Lc\SovBundle\Repository\StoreInterface;


trait MerchantStoreTrait trait MerchantStoreTrait
{ {


return $this; return $this;
} }

public function isMerchantDefined(): bool
{
return isset($this->merchant) && $this->merchant;
}

public function addFilterByMerchantOptionnal(RepositoryQueryInterface $query): StoreInterface
{
if($this->isMerchantDefined()) {
$query->filterByMerchant($this->merchant);
}

return $this;
}

public function addFilterByMerchantRequired(RepositoryQueryInterface $query): StoreInterface
{
$this->addFilterByMerchantOptionnal($query);

if(!$this->isMerchantDefined()) {
throw new \ErrorException('Le Merchant doit être définie dans '.get_class($this));
}

return $this;
}

public function addFilterByMerchantViaSectionOptionnal(RepositoryQueryInterface $query): StoreInterface
{
if($this->isMerchantDefined()) {
$query->filterByMerchantViaSection($this->merchant);
}

return $this;
}

public function addFilterByMerchantViaSectionRequired(RepositoryQueryInterface $query): StoreInterface
{
$this->addFilterByMerchantOptionnal($query);

if(!$this->isMerchantDefined()) {
throw new \ErrorException('Le Merchant doit être définie dans '.get_class($this));
}

return $this;
}
} }

+ 0
- 7
Repository/Order/OrderShopRepositoryQuery.php View File

->select('count(r.id) as total'); ->select('count(r.id) as total');
} }


public function filterByMerchant(MerchantInterface $merchant)
{
$this->joinMerchant();
return $this->andWhere('s.merchant = :merchant')
->setParameter('merchant', $merchant);
}

public function filterByUser(UserInterface $user): self public function filterByUser(UserInterface $user): self
{ {
return $this return $this

+ 3
- 7
Repository/Order/OrderShopStore.php View File



public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
if(isset($this->section) && $this->section) {
$query->filterBySection($this->section);
}

if(isset($this->merchant) && $this->merchant) {
$query->filterByMerchant($this->merchant);
}
$this
->addFilterBySectionOptionnal($query)
->addFilterByMerchantViaSectionOptionnal($query);


return $query; return $query;
} }

+ 27
- 0
Repository/SectionStoreTrait.php View File

namespace Lc\CaracoleBundle\Repository; namespace Lc\CaracoleBundle\Repository;


use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Lc\SovBundle\Repository\StoreInterface;


trait SectionStoreTrait trait SectionStoreTrait
{ {
return $this; return $this;
} }


public function isSectionDefined(): bool
{
return isset($this->section) && $this->section;
}

public function addFilterBySectionOptionnal(RepositoryQueryInterface $query): StoreInterface
{
if($this->isSectionDefined()) {
$query->filterBySection($this->section);
}

return $this;
}

public function addFilterBySectionRequired(RepositoryQueryInterface $query): StoreInterface
{
$this->addFilterBySectionOptionnal($query);

if(!$this->isSectionDefined()) {
throw new \ErrorException('La Section doit être définie dans '.get_class($this));
}

return $this;
}

public function getParents() public function getParents()
{ {
$query = $this->query->create(); $query = $this->query->create();

Loading…
Cancel
Save