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

@@ -3,6 +3,8 @@
namespace Lc\CaracoleBundle\Repository;

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

trait MerchantStoreTrait
{
@@ -14,4 +16,49 @@ trait MerchantStoreTrait

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

@@ -49,13 +49,6 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
->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
{
return $this

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

@@ -88,13 +88,9 @@ class OrderShopStore extends AbstractStore

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;
}

+ 27
- 0
Repository/SectionStoreTrait.php View File

@@ -3,6 +3,8 @@
namespace Lc\CaracoleBundle\Repository;

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

trait SectionStoreTrait
{
@@ -15,6 +17,31 @@ trait SectionStoreTrait
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()
{
$query = $this->query->create();

Loading…
Cancel
Save