您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

40 行
1.2KB

  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. if($lastRotatingProduct) {
  25. $rotatingProduct->setPosition($lastRotatingProduct->getPosition() + 1);
  26. }
  27. else {
  28. $rotatingProduct->setPosition(1);
  29. }
  30. return $rotatingProduct;
  31. }
  32. }