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

40 lines
1.2KB

  1. <?php
  2. namespace common\logic\PointSale\UserPointSale;
  3. use common\logic\BaseService;
  4. use common\logic\BuilderInterface;
  5. use common\logic\PointSale\PointSale\PointSale;
  6. use common\logic\User\User\User;
  7. class UserPointSaleBuilder extends BaseService implements BuilderInterface
  8. {
  9. public function instanciateUserPointSale(User $user, PointSale $pointSale, string $comment = null): UserPointSale
  10. {
  11. $userPointSale = new UserPointSale();
  12. $userPointSale->id_user = $user->id;
  13. $userPointSale->populateRelation('user', $user);
  14. $userPointSale->id_point_sale = $pointSale->id;
  15. $userPointSale->populateRelation('pointSale', $pointSale);
  16. if($comment) {
  17. $userPointSale->comment = $comment;
  18. }
  19. return $userPointSale;
  20. }
  21. public function createUserPointSale(User $user, PointSale $pointSale, string $comment = null): UserPointSale
  22. {
  23. $userPointSale = $this->instanciateUserPointSale($user, $pointSale, $comment);
  24. $userPointSale->save();
  25. return $userPointSale;
  26. }
  27. public function deleteByPointSale(PointSale $pointSale): void
  28. {
  29. UserPointSale::deleteAll(['id_point_sale' => $pointSale->id]);
  30. }
  31. }