Browse Source

Produits tournants

feature/rotating_product
Guillaume Bourgeois 6 months ago
parent
commit
e146ad98f7
4 changed files with 48 additions and 8 deletions
  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 View File

use domain\Payment\Payment; use domain\Payment\Payment;
use domain\Producer\Producer\Producer; use domain\Producer\Producer\Producer;
use domain\Product\Product\Product; use domain\Product\Product\Product;
use domain\Product\Rotating\Rotating;
use domain\Ticket\Ticket\Ticket; use domain\Ticket\Ticket\Ticket;
use domain\Ticket\TicketMessage\TicketMessage; use domain\Ticket\TicketMessage\TicketMessage;
use domain\User\User\User; use domain\User\User\User;
Producer::class => [ Producer::class => [
// Envoi d'un email à l'administrateur quand un nouveau témoignage est saisi par un producteur // Envoi d'un email à l'administrateur quand un nouveau témoignage est saisi par un producteur
domain\Producer\Producer\Event\ProducerObserver::class 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 View File

DistributionRotatingDefinition::class, DistributionRotatingDefinition::class,
DistributionRotatingRepository::class, DistributionRotatingRepository::class,
DistributionRotatingBuilder::class, DistributionRotatingBuilder::class,
DistributionRotatingManager::class
]; ];
} }


{ {
return DistributionRotatingBuilder::getInstance(); return DistributionRotatingBuilder::getInstance();
} }

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

+ 19
- 0
domain/Product/Rotating/Event/RotatingObserver.php View File

<?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 View File



use common\components\Date; use common\components\Date;
use domain\_\AbstractManager; use domain\_\AbstractManager;
use domain\Distribution\Distribution\Distribution;
use domain\Distribution\Distribution\DistributionRepository; use domain\Distribution\Distribution\DistributionRepository;
use domain\Distribution\Distribution\DistributionResolver; use domain\Distribution\Distribution\DistributionResolver;
use domain\Distribution\DistributionRotating\DistributionRotatingManager; use domain\Distribution\DistributionRotating\DistributionRotatingManager;
protected DistributionRepository $distributionRepository; protected DistributionRepository $distributionRepository;
protected DistributionRotatingManager $distributionRotatingManager; protected DistributionRotatingManager $distributionRotatingManager;
protected RotatingResolver $rotatingResolver; protected RotatingResolver $rotatingResolver;
protected DistributionResolver $distributionResolver;


/**
* @throws ErrorException
*/
public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->rotatingBuilder = $this->loadService(RotatingBuilder::class); $this->rotatingBuilder = $this->loadService(RotatingBuilder::class);
$this->distributionRepository = $this->loadService(DistributionRepository::class); $this->distributionRepository = $this->loadService(DistributionRepository::class);
$this->distributionRotatingManager = $this->loadService(DistributionRotatingManager::class); $this->distributionRotatingManager = $this->loadService(DistributionRotatingManager::class);
$this->rotatingResolver = $this->loadService(RotatingResolver::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 public function createRotating(Producer $producer, string $name, int $day, array $productsIdsArray): Rotating
$dateLastDistributionIncoming = $this->distributionResolver->getDateLastDistributionIncoming(); $dateLastDistributionIncoming = $this->distributionResolver->getDateLastDistributionIncoming();


while($distribution && $date < $dateLastDistributionIncoming) { 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); $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 public function deleteRotating(Rotating $rotating): bool
{ {
$this->deleteAllRotatingProducts($rotating); $this->deleteAllRotatingProducts($rotating);

Loading…
Cancel
Save