Browse Source

Mise en place createQuery

packProduct
Guillaume 3 years ago
parent
commit
4625328e51
11 changed files with 109 additions and 190 deletions
  1. +7
    -10
      Repository/File/DocumentStore.php
  2. +54
    -115
      Repository/Order/OrderShopStore.php
  3. +0
    -2
      Repository/Product/ProductCategoryStore.php
  4. +12
    -9
      Repository/Reduction/ReductionCartStore.php
  5. +8
    -5
      Repository/Reduction/ReductionCatalogStore.php
  6. +2
    -2
      Repository/Reduction/ReductionCreditStore.php
  7. +3
    -9
      Repository/Reminder/ReminderStore.php
  8. +3
    -3
      Repository/Section/SectionStore.php
  9. +2
    -6
      Repository/Site/NewsStore.php
  10. +5
    -29
      Repository/Site/PageStore.php
  11. +13
    -0
      Solver/Order/OrderShopSolver.php

+ 7
- 10
Repository/File/DocumentStore.php View File

@@ -18,30 +18,27 @@ class DocumentStore extends AbstractStore
$this->query = $query;
}

public function getOneLatestByType(string $documentType)
public function getOneLatestByType(string $documentType, $query = null)
{
// @TODO : à écrire
}

// findLastInvoice
public function getOneLastInvoice()
public function getOneLastInvoice($query = null)
{
$query = $this->query->create();
$query = $this->createQuery($query);

$query
->filterByMerchant($this->merchant)
->filterBySection($this->section)
->orderBy('.createdAt', 'DESC');

return $query->findOne();
}

public function getByBuyerAddress(Address $buyerAddress)
public function getByBuyerAddress(Address $buyerAddress, $query = null)
{
$query = $this->query->create();

$query
->filterByBuyerAddress($buyerAddress);

$query = $this->createQuery($query);
$query->filterByBuyerAddress($buyerAddress);
return $query->find();
}


+ 54
- 115
Repository/Order/OrderShopStore.php View File

@@ -74,7 +74,7 @@ class OrderShopStore extends AbstractStore
}

// getOrderShopsOfWeek
public function getByCurrentCycle($params = [])
public function getByCurrentCycle($params = [], $query = null)
{
$orderShops = $this->getBy(
array_merge(
@@ -84,14 +84,15 @@ class OrderShopStore extends AbstractStore
'isValid' => true,
],
$params
)
),
$query
);

return $orderShops;
}

// getOrderShopsOfWeekByUser
public function getByCurrentCycleAndUser(UserInterface $user, array $params = [])
public function getByCurrentCycleAndUser(UserInterface $user, array $params = [], $query = null)
{
return $this->getByCurrentCycle(
array_merge(
@@ -101,20 +102,21 @@ class OrderShopStore extends AbstractStore
'excludeComplementaryOrderShops' => true
],
$params
)
),
$query
);
}

//public $countOrderShopsOfWeek = null;

public function countByCurrentCycle(bool $excludeComplementaryOrderShops = true)
public function countByCurrentCycle(bool $excludeComplementaryOrderShops = true, $query = null)
{
return $this->getByCurrentCycle(
[
'count' => true,
'excludeComplementaryOrderShops' => $excludeComplementaryOrderShops

]
],
$query
);

// @TODO : optimisation à remettre en place
@@ -132,9 +134,9 @@ class OrderShopStore extends AbstractStore
}

// getNextWeekId
public function getNextCycleId(int $cycleNumber): int
public function getNextCycleId(int $cycleNumber, $query = null): int
{
$lastOrder = $this->getOneLastValidOfCycle($cycleNumber);
$lastOrder = $this->getOneLastValidOfCycle($cycleNumber, $query);
if ($lastOrder) {
return intval($lastOrder->getCycleId() + 1);
} else {
@@ -142,9 +144,9 @@ class OrderShopStore extends AbstractStore
}
}

public function getNextIdValidOrder(): int
public function getNextIdValidOrder($query = null): int
{
$lastOrder = $this->getOneLastValid();
$lastOrder = $this->getOneLastValid($query);

if ($lastOrder) {
return intval($lastOrder->getIdValidOrder() + 1);
@@ -154,20 +156,21 @@ class OrderShopStore extends AbstractStore
}

// countValidOrderShopByUserAllMerchant
public function countValidByUserAllMerchant($user): int
public function countValidByUserAllMerchant($user, $query = null): int
{
return $this->countBy(
[
'user' => $user,
'isValid' => true,
// @TODO : à tester
// @TODO : à tester
'isMerchantOnline' => true,
'excludeComplementaryOrderShops' => true
]
],
$query
);
}

public function countValidByUser(UserInterface $user): int
public function countValidByUser(UserInterface $user, $query = null): int
{
return $this->countBy(
[
@@ -175,11 +178,12 @@ class OrderShopStore extends AbstractStore
'isValid' => true,
'section' => $this->section,
'excludeComplementaryOrderShops' => true
]
],
$query
);
}

public function countValidByCurrentCycle(): int
public function countValidByCurrentCycle($query = null): int
{
return $this->countBy(
[
@@ -187,20 +191,23 @@ class OrderShopStore extends AbstractStore
'isValid' => true,
'section' => $this->section,
'excludeComplementaryOrderShops' => true
]
],
$query
);
}

// countValidOrderWithReductionCredit
public function countValidWithReductionCredit(
ReductionCreditInterface $reductionCredit,
UserInterface $user = null
UserInterface $user = null,
$query = null
): int {
$query = $this->query->create();
$query = $this->createQuery($query);

if ($user) {
$query->filterByUser($user);
}

$query
->selectCount()
->filterByReductionCredit($reductionCredit)
@@ -212,9 +219,11 @@ class OrderShopStore extends AbstractStore

// countValidOrderWithReductionCart
public function countValidWithReductionCart(
ReductionCartInterface $reductionCart
ReductionCartInterface $reductionCart,
$query = null
): int {
$query = $this->query->create();
$query = $this->createQuery($query);

$query
->selectCount()
->filterByReductionCart($reductionCart)
@@ -227,9 +236,10 @@ class OrderShopStore extends AbstractStore
// countValidOrderWithReductionCartPerUser
public function countValidWithReductionCartByUser(
ReductionCartInterface $reductionCart,
UserInterface $user
UserInterface $user,
$query = null
): int {
$query = $this->query->create();
$query = $this->createQuery($query);

$query
->selectCount()
@@ -242,17 +252,15 @@ class OrderShopStore extends AbstractStore
}

// findCartCurrent
public function getCartCurrent(array $params): ?OrderShopInterface
public function getCartCurrent(array $params, $query = null): ?OrderShopInterface
{
$query = $this->query->create();
$query = $this->createQuery($query);

if (isset($params['user'])) {
$query
->filterByUser($params['user']);
$query->filterByUser($params['user']);
}
if (isset($params['visitor'])) {
$query
->filterByVisitor($params['visitor']);
$query->filterByVisitor($params['visitor']);
}

$query
@@ -261,13 +269,12 @@ class OrderShopStore extends AbstractStore
->filterBySection($this->section);

return $query->findOne();

}

// findLastOrderValidOfWeek
public function getOneLastValidByCycle(int $cycleNumber): ?OrderShopInterface
public function getOneLastValidByCycle(int $cycleNumber, $query = null): ?OrderShopInterface
{
$query = $this->query->create();
$query = $this->createQuery($query);

$query
->filterByCycleNumber($cycleNumber)
@@ -280,9 +287,9 @@ class OrderShopStore extends AbstractStore
}

//findLastOrderValid
public function getOneLastValid(): ?OrderShopInterface
public function getOneLastValid($query = null): ?OrderShopInterface
{
$query = $this->query->create();
$query = $this->createQuery($query);

$query
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
@@ -293,23 +300,23 @@ class OrderShopStore extends AbstractStore
return $query->findOne();
}

public function countBy(array $params = [])
public function countBy(array $params = [], $query = null)
{
$query = $this->query->create();
$query = $this->createQuery($query);

$query->selectCount();
$query = $this->applyGetByFilters($query);
$query
->selectCount()
->applyGetByFilters($query);

return $query->count();
}


public function getBy(array $params = []): array
public function getBy(array $params = [], $query = null): array
{
$query = $this->query->create();
$query = $this->createQuery($query);

$query = $this->applyGetByFilters($query);
$this->applyGetByFilters($query);

$orderShops = $query->find();

@@ -399,89 +406,21 @@ class OrderShopStore extends AbstractStore
return $query;
}



public function isReductionGiftUsed(ReductionCreditInterface $reductionGift)
public function isReductionGiftUsed(ReductionCreditInterface $reductionGift, $query = null)
{
if ($this->countValidWithReductionCredit($reductionGift)) {
if ($this->countValidWithReductionCredit($reductionGift, null, $query)) {
return true;
} else {
return false;
}
}

public function isReductionCreditUsed(ReductionCreditInterface $reductionCredit, UserInterface $user = null)
public function isReductionCreditUsed(ReductionCreditInterface $reductionCredit, UserInterface $user = null, $query = null)
{
if ($this->countValidWithReductionCredit($reductionCredit, $user)) {
if ($this->countValidWithReductionCredit($reductionCredit, $user, $query)) {
return true;
} else {
return false;
}
}

public function isReductionCreditAddedToOrder(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
) {
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) {
if ($orderReductionCredit->getReductionCredit() == $reductionCredit) {
return true;
}
}

return false;
}

/*
public function getCartCurrent(SectionInterface $section, UserInterface $user = null, VisitorInterface $visitor = null)
{
$paramsSearchOrderShop = [];

$user = $this->security->getUser();
$visitor = $this->userUtils->getVisitorCurrent();

$orderShop = null;
$orderShopUser = null;
$orderShopVisitor = null;

if ($user) {
$orderShopUser = $this->orderShopRepo->findCartCurrent(
[
'user' => $user
]
);
}

if ($visitor) {
$orderShopVisitor = $this->orderShopRepo->findCartCurrent(
[
'visitor' => $visitor
]
);
}

if ($orderShopUser || $orderShopVisitor) {
// merge
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())
&& $orderShopUser->getOrderStatus()->getAlias() == OrderStatus::ALIAS_CART) {
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->utils->addFlash(
'success',
"Votre panier visiteur vient d'être fusionné avec votre panier client."
);
} else {
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
}
// set user
if ($orderShop && $user && !$orderShop->getUser()) {
$orderShop->setUser($user);
$orderShop->setVisitor(null);
$this->em->persist($orderShop);
$this->em->flush();
}
}

return $orderShop;
}*/
}

+ 0
- 2
Repository/Product/ProductCategoryStore.php View File

@@ -16,6 +16,4 @@ class ProductCategoryStore extends AbstractStore
{
$this->query = $query;
}

}

+ 12
- 9
Repository/Reduction/ReductionCartStore.php View File

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Repository\Reduction;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Reduction\ReductionCartSolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
@@ -12,27 +13,29 @@ use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
class ReductionCartStore extends AbstractStore
{
protected ReductionCartRepositoryQuery $query;
protected ReductionCartSolver $reductionCartSolver;
protected OrderShopStore $orderShopStore;
protected PriceSolver $priceSolver;
protected FlashBagInterface $flashBag;

public function __construct(
ReductionCartRepositoryQuery $query,
ReductionCartSolver $reductionCartSolver,
OrderShopStore $orderShopStore,
PriceSolver $priceSolver,
FlashBagInterface $flashBag
FlashBagInterface $flashBag,
) {
$this->query = $query;
$this->reductionCartSolver = $reductionCartSolver;
$this->orderShopStore = $orderShopStore;
$this->priceSolver = $priceSolver;
$this->flashBag = $flashBag;
}

// getReductionCartByCode
public function getByCode(string $code)
public function getByCode(string $code, $query = null)
{
$query = $this->query->create();

$query = $this->createQuery($query);
$query->filterByCode($code);
$reductionCarts = $query->find();

@@ -77,14 +80,15 @@ class ReductionCartStore extends AbstractStore
}

// findAllAvailableForUser / getReductionCartsAvailableByUser
public function getAvailableByUser(UserInterface $user)
public function getAvailableByUser(UserInterface $user, $query = null)
{
$reductionCarts = $this->query->find();
$query = $this->createQuery($query);
$reductionCarts = $query->find();

$reductionCartsArray = [];
foreach ($reductionCarts as $reductionCart) {
if ($reductionCart->matchWithUser($user)
&& $reductionCart->matchWithGroupUser($user)
if ($this->reductionCartSolver->matchWithUser($user)
&& $this->reductionCartSolver->matchWithGroupUser($user)
&& $this->getRemainingQuantityByUser($reductionCart, $user)
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)) {
$reductionCartsArray[] = $reductionCart;
@@ -93,5 +97,4 @@ class ReductionCartStore extends AbstractStore

return $reductionCartsArray;
}

}

+ 8
- 5
Repository/Reduction/ReductionCatalogStore.php View File

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Repository\Reduction;

use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\SovBundle\Repository\AbstractStore;

class ReductionCatalogStore extends AbstractStore
@@ -13,11 +14,13 @@ class ReductionCatalogStore extends AbstractStore
$this->query = $query;
}

public function getByProductFamily($productFamily){
$query = $this->query->create();
$query->filterProductFamily($productFamily);
$query->filterIsOnline();
return $query->findOne();
public function getByProductFamily(ProductFamilyInterface $productFamily, $query = null)
{
$query = $this->createQuery($query);
$query
->filterProductFamily($productFamily)
->filterIsOnline();

return $query->findOne();
}
}

+ 2
- 2
Repository/Reduction/ReductionCreditStore.php View File

@@ -20,9 +20,9 @@ class ReductionCreditStore extends AbstractStore
}

// findReductionCreditsByUser
public function getByTypeAndUser(string $type = ReductionCreditModel::TYPE_CREDIT, UserInterface $user)
public function getByTypeAndUser(string $type, UserInterface $user, $query = null)
{
$query = $this->query->create();
$query = $this->createQuery($query);

$query
->filterByType($type)

+ 3
- 9
Repository/Reminder/ReminderStore.php View File

@@ -14,9 +14,7 @@ class ReminderStore extends SovReminderStore

public function get($params = [], $query = null)
{
if (is_null($query)) {
$query = $this->query->create();
}
$query = $this->createQuery($query);

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
@@ -31,9 +29,7 @@ class ReminderStore extends SovReminderStore

public function getByUser(UserInterface $user, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}
$query = $this->createQuery($query);

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
@@ -53,9 +49,7 @@ class ReminderStore extends SovReminderStore
int $entityId = null,
$query = null
): array {
if (is_null($query)) {
$query = $this->query->create();
}
$query = $this->createQuery($query);

if ($this->merchant) {
$query->filterByMerchant($this->merchant);

+ 3
- 3
Repository/Section/SectionStore.php View File

@@ -21,9 +21,9 @@ class SectionStore extends AbstractStore
}

// getSection
public function getOneByDevAlias(string $devAlias): ?SectionInterface
public function getOneByDevAlias(string $devAlias, $query = null): ?SectionInterface
{
$query = $this->query->create();
$query = $this->createQuery($query);

$query
->filterByMerchant($this->merchant)
@@ -38,7 +38,7 @@ class SectionStore extends AbstractStore
return $section;
}

public function countOpenDays(SectionInterface $section): int
public function countOpenDays(SectionInterface $section, $query = null): int
{
// @TODO : à implémenter avec le nouveau système d'ouverture des commandes
}

+ 2
- 6
Repository/Site/NewsStore.php View File

@@ -11,13 +11,9 @@ class NewsStore extends SovNewsStore

public function getLatests(int $maxResults = 0, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}
$query = $this->createQuery($query);

if ($this->section) {
$query->filterBySection($this->section);
}
$query->filterBySection($this->section);

return parent::getLatests($maxResults, $query);
}

+ 5
- 29
Repository/Site/PageStore.php View File

@@ -17,39 +17,15 @@ class PageStore extends SovPageStore
}

// findPage
public function getOneByDevAlias(string $devAlias): ?PageInterface
public function getOneByDevAlias(string $devAlias, $query = null): ?PageInterface
{
$query = $this->query->create();
$query = $this->createQuery($query);

$query
->filterIsOnline()
->filterByDevAlias($devAlias)
->filterBySection($this->section);
->filterIsOnline()
->filterByDevAlias($devAlias)
->filterBySection($this->section);

return $query->findOne();
}

// public function findPage($devAlias, $devAliasMerchant = false)
// {
// $merchant = false;
//
// if ($devAliasMerchant) {
// $merchant = $this->merchantUtils->getMerchantByDevAlias($devAliasMerchant);
// }
//
// if ($devAliasMerchant && $merchant) {
// $query = $this->createQueryBuilder('e')
// ->where('e.merchant = :merchant')
// ->setParameter('merchant', $merchant->getId());
// } else {
// $query = $this->findByMerchantQuery();
// }
//
// return $query->andWhere('e.status = 1')
// ->andWhere('e.devAlias = :devAlias')
// ->setParameter('devAlias', $devAlias)
// ->getQuery()
// ->getOneOrNullResult();
// }

}

+ 13
- 0
Solver/Order/OrderShopSolver.php View File

@@ -12,6 +12,7 @@ use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;

class OrderShopSolver
@@ -196,5 +197,17 @@ class OrderShopSolver
return $orderShop;
}

public function isReductionCreditAddedToOrder(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
) {
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) {
if ($orderReductionCredit->getReductionCredit() == $reductionCredit) {
return true;
}
}

return false;
}

}

Loading…
Cancel
Save