Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

41 lines
1.2KB

  1. <?php
  2. namespace domain\Subscription\Subscription;
  3. use domain\Distribution\Distribution\DistributionRepository;
  4. use domain\Subscription\ProductSubscription\ProductSubscription;
  5. use domain\User\User\User;
  6. use domain\_\AbstractBuilder;
  7. class SubscriptionBuilder extends AbstractBuilder
  8. {
  9. protected DistributionRepository $distributionRepository;
  10. public function loadDependencies(): void
  11. {
  12. $this->distributionRepository = $this->loadService(DistributionRepository::class);
  13. }
  14. public function instanciateSubscription(User $createdBy): Subscription
  15. {
  16. $subscription = new Subscription();
  17. $subscription->auto_payment = Subscription::AUTO_PAYMENT_DEDUCTED;
  18. $subscription->populateCreatedBy($createdBy);
  19. return $subscription;
  20. }
  21. public function createSubscription(User $createdBy): Subscription
  22. {
  23. $subscription = $this->instanciateSubscription($createdBy);
  24. $this->create($subscription);
  25. return $subscription;
  26. }
  27. public function deleteSubscription(Subscription $subscription): void
  28. {
  29. ProductSubscription::deleteAll(['id_subscription' => $subscription->id]);
  30. $this->delete($subscription);
  31. }
  32. }