Selaa lähdekoodia

Produits tournants

feature/rotating_product
Guillaume Bourgeois 5 kuukautta sitten
vanhempi
commit
e146ad98f7
4 muutettua tiedostoa jossa 48 lisäystä ja 8 poistoa
  1. +6
    -1
      common/config/main.php
  2. +6
    -0
      domain/Distribution/DistributionRotating/DistributionRotatingModule.php
  3. +19
    -0
      domain/Product/Rotating/Event/RotatingObserver.php
  4. +17
    -7
      domain/Product/Rotating/RotatingManager.php

+ 6
- 1
common/config/main.php Näytä tiedosto

@@ -45,6 +45,7 @@ use domain\Order\Order\Order;
use domain\Payment\Payment;
use domain\Producer\Producer\Producer;
use domain\Product\Product\Product;
use domain\Product\Rotating\Rotating;
use domain\Ticket\Ticket\Ticket;
use domain\Ticket\TicketMessage\TicketMessage;
use domain\User\User\User;
@@ -231,7 +232,11 @@ return [
Producer::class => [
// Envoi d'un email à l'administrateur quand un nouveau témoignage est saisi par un producteur
domain\Producer\Producer\Event\ProducerObserver::class
]
],
Rotating::class => [
// Initialisation des produits tournants dans les distributions à venir
domain\Product\Rotating\Event\RotatingObserver::class
],
],
],
],

+ 6
- 0
domain/Distribution/DistributionRotating/DistributionRotatingModule.php Näytä tiedosto

@@ -12,6 +12,7 @@ class DistributionRotatingModule extends AbstractModule
DistributionRotatingDefinition::class,
DistributionRotatingRepository::class,
DistributionRotatingBuilder::class,
DistributionRotatingManager::class
];
}

@@ -29,4 +30,9 @@ class DistributionRotatingModule extends AbstractModule
{
return DistributionRotatingBuilder::getInstance();
}

public function getManager(): DistributionRotatingManager
{
return DistributionRotatingManager::getInstance();
}
}

+ 19
- 0
domain/Product/Rotating/Event/RotatingObserver.php Näytä tiedosto

@@ -0,0 +1,19 @@
<?php

namespace domain\Product\Rotating\Event;

use domain\Product\Rotating\RotatingModule;
use justcoded\yii2\eventlistener\observers\ActiveRecordObserver;

class RotatingObserver extends ActiveRecordObserver
{
public function inserted(\yii\db\AfterSaveEvent $event)
{
RotatingModule::getInstance()->getManager()->initializeRotatingInDistributionsIncoming($event->sender);
}

public function updated(\yii\db\AfterSaveEvent $event)
{
RotatingModule::getInstance()->getManager()->initializeRotatingInDistributionsIncoming($event->sender);
}
}

+ 17
- 7
domain/Product/Rotating/RotatingManager.php Näytä tiedosto

@@ -4,6 +4,7 @@ namespace domain\Product\Rotating;

use common\components\Date;
use domain\_\AbstractManager;
use domain\Distribution\Distribution\Distribution;
use domain\Distribution\Distribution\DistributionRepository;
use domain\Distribution\Distribution\DistributionResolver;
use domain\Distribution\DistributionRotating\DistributionRotatingManager;
@@ -20,8 +21,10 @@ class RotatingManager extends AbstractManager
protected DistributionRepository $distributionRepository;
protected DistributionRotatingManager $distributionRotatingManager;
protected RotatingResolver $rotatingResolver;
protected DistributionResolver $distributionResolver;

/**
* @throws ErrorException
*/
public function loadDependencies(): void
{
$this->rotatingBuilder = $this->loadService(RotatingBuilder::class);
@@ -30,7 +33,6 @@ class RotatingManager extends AbstractManager
$this->distributionRepository = $this->loadService(DistributionRepository::class);
$this->distributionRotatingManager = $this->loadService(DistributionRotatingManager::class);
$this->rotatingResolver = $this->loadService(RotatingResolver::class);
$this->distributionResolver = $this->loadService(DistributionResolver::class);
}

public function createRotating(Producer $producer, string $name, int $day, array $productsIdsArray): Rotating
@@ -67,15 +69,23 @@ class RotatingManager extends AbstractManager
$dateLastDistributionIncoming = $this->distributionResolver->getDateLastDistributionIncoming();

while($distribution && $date < $dateLastDistributionIncoming) {
$rotatingProduct = $this->rotatingResolver->deductNextRotatingProductOfDistribution($rotating, $distribution);
$this->distributionRotatingManager->createDistributionRotatingIfNotExist(
$distribution,
$rotatingProduct
);
$this->initializeRotatingInDistribution($rotating, $distribution);
$distribution = $this->rotatingResolver->getNextDistribution($rotating, $date);
}
}

/**
* @throws ErrorException
*/
public function initializeRotatingInDistribution(Rotating $rotating, Distribution $distribution)
{
$rotatingProduct = $this->rotatingResolver->deductNextRotatingProductOfDistribution($rotating, $distribution);
$this->distributionRotatingManager->createDistributionRotatingIfNotExist(
$distribution,
$rotatingProduct
);
}

public function deleteRotating(Rotating $rotating): bool
{
$this->deleteAllRotatingProducts($rotating);

Loading…
Peruuta
Tallenna