Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace common\logic\PointSale\UserPointSale\Service;
  3. use common\logic\AbstractBuilder;
  4. use common\logic\PointSale\PointSale\Model\PointSale;
  5. use common\logic\PointSale\UserPointSale\Model\UserPointSale;
  6. use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository;
  7. use common\logic\User\User\Model\User;
  8. class UserPointSaleBuilder extends AbstractBuilder
  9. {
  10. protected UserPointSaleRepository $userPointSaleRepository;
  11. public function loadDependencies(): void
  12. {
  13. $this->userPointSaleRepository = $this->loadService(UserPointSaleRepository::class);
  14. }
  15. public function instanciateUserPointSale(User $user, PointSale $pointSale, string $comment = null): UserPointSale
  16. {
  17. $userPointSale = new UserPointSale();
  18. $userPointSale->populatePointSale($pointSale);
  19. $userPointSale->populateUser($user);
  20. if($comment) {
  21. $userPointSale->comment = $comment;
  22. }
  23. return $userPointSale;
  24. }
  25. public function createUserPointSale(User $user, PointSale $pointSale, string $comment = null): UserPointSale
  26. {
  27. $userPointSale = $this->instanciateUserPointSale($user, $pointSale, $comment);
  28. $this->saveCreate($userPointSale);
  29. return $userPointSale;
  30. }
  31. public function createUserPointSaleIfNotExist(User $user, PointSale $pointSale, string $comment = null): UserPointSale
  32. {
  33. return $this->userPointSaleRepository->findOneUserPointSale($user, $pointSale)
  34. ?? $this->createUserPointSale($user, $pointSale);
  35. }
  36. public function deleteUserPointSalesByPointSale(PointSale $pointSale): void
  37. {
  38. UserPointSale::deleteAll(['id_point_sale' => $pointSale->id]);
  39. }
  40. }