Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

49 linhas
1.5KB

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