You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.1KB

  1. <?php
  2. namespace domain\Product\RotatingProduct;
  3. use domain\_\AbstractBuilder;
  4. use domain\_\StatusInterface;
  5. use domain\Product\Rotating\Rotating;
  6. class RotatingProductBuilder extends AbstractBuilder
  7. {
  8. protected RotatingProductRepository $rotatingProductRepository;
  9. public function loadDependencies(): void
  10. {
  11. $this->rotatingProductRepository = $this->loadService(RotatingProductRepository::class);
  12. }
  13. public function instanciateRotatingProduct(Rotating $rotating): RotatingProduct
  14. {
  15. $rotatingProduct = new RotatingProduct();
  16. $rotatingProduct
  17. ->setRotating($rotating)
  18. ->setStatus(StatusInterface::STATUS_ONLINE);
  19. return $rotatingProduct;
  20. }
  21. public function initRotatingProductPosition(RotatingProduct $rotatingProduct): RotatingProduct
  22. {
  23. $lastRotatingProduct = $this->rotatingProductRepository->findOneLastRotatingProduct($rotatingProduct->getRotating());
  24. $rotatingProduct->setPosition($lastRotatingProduct->getPosition() + 1);
  25. return $rotatingProduct;
  26. }
  27. }