Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DistributionRotatingManager.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace domain\Distribution\DistributionRotating;
  3. use domain\_\AbstractManager;
  4. use domain\Distribution\Distribution\Distribution;
  5. use domain\Product\RotatingProduct\RotatingProduct;
  6. class DistributionRotatingManager extends AbstractManager
  7. {
  8. protected DistributionRotatingBuilder $distributionRotatingBuilder;
  9. protected DistributionRotatingRepository $distributionRotatingRepository;
  10. public function loadDependencies(): void
  11. {
  12. $this->distributionRotatingBuilder = $this->loadService(DistributionRotatingBuilder::class);
  13. $this->distributionRotatingRepository = $this->loadService(DistributionRotatingRepository::class);
  14. }
  15. public function createDistributionRotating(Distribution $distribution, RotatingProduct $rotatingProduct): DistributionRotating
  16. {
  17. $distributionRotating = $this->distributionRotatingBuilder->instanciateDistributionRotating();
  18. $distributionRotating
  19. ->setDistribution($distribution)
  20. ->setRotating($rotatingProduct->getRotating())
  21. ->setRotatingProduct($rotatingProduct);
  22. return $distributionRotating;
  23. }
  24. public function createDistributionRotatingIfNotExist(Distribution $distribution, RotatingProduct $rotatingProduct): DistributionRotating
  25. {
  26. $distributionRotating = $this->distributionRotatingRepository->findOneDistributionRotating($distribution, $rotatingProduct->getRotating());
  27. if($distributionRotating) {
  28. $distributionRotating->setRotatingProduct($rotatingProduct);
  29. $distributionRotating->save();
  30. return $distributionRotating;
  31. }
  32. else {
  33. return $this->createDistributionRotating($distribution, $rotatingProduct);
  34. }
  35. }
  36. }