Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

44 lines
1.7KB

  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. }