|
- <?php
-
- namespace domain\Distribution\DistributionRotating;
-
- use domain\_\AbstractManager;
- use domain\Distribution\Distribution\Distribution;
- use domain\Product\RotatingProduct\RotatingProduct;
-
- class DistributionRotatingManager extends AbstractManager
- {
- protected DistributionRotatingBuilder $distributionRotatingBuilder;
- protected DistributionRotatingRepository $distributionRotatingRepository;
-
- public function loadDependencies(): void
- {
- $this->distributionRotatingBuilder = $this->loadService(DistributionRotatingBuilder::class);
- $this->distributionRotatingRepository = $this->loadService(DistributionRotatingRepository::class);
- }
-
- public function createDistributionRotating(Distribution $distribution, RotatingProduct $rotatingProduct): DistributionRotating
- {
- $distributionRotating = $this->distributionRotatingBuilder->instanciateDistributionRotating();
- $distributionRotating
- ->setDistribution($distribution)
- ->setRotating($rotatingProduct->getRotating())
- ->setRotatingProduct($rotatingProduct);
-
- return $distributionRotating;
- }
-
- public function createDistributionRotatingIfNotExist(Distribution $distribution, RotatingProduct $rotatingProduct): DistributionRotating
- {
- $distributionRotating = $this->distributionRotatingRepository->findOneDistributionRotating($distribution, $rotatingProduct->getRotating());
- if($distributionRotating) {
- $distributionRotating->setRotatingProduct($rotatingProduct);
- $distributionRotating->save();
-
- return $distributionRotating;
- }
- else {
- return $this->createDistributionRotating($distribution, $rotatingProduct);
- }
- }
- }
|