Bläddra i källkod

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

packProduct
Guillaume 3 år sedan
förälder
incheckning
a8eb113009
4 ändrade filer med 77 tillägg och 14 borttagningar
  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 Visa fil

@@ -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 Visa fil

@@ -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 Visa fil

@@ -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 Visa fil

@@ -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();

Laddar…
Avbryt
Spara