You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 satır
773B

  1. <?php
  2. namespace Lc\SovBundle\Builder\User;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
  5. use Lc\SovBundle\Model\User\UserInterface;
  6. class UserBuilder
  7. {
  8. protected EntityManagerInterface $entityManager;
  9. public function __construct(EntityManagerInterface $entityManager)
  10. {
  11. $this->entityManager = $entityManager;
  12. }
  13. public function setNewsletter(UserInterface $user, NewsletterInterface $newsletter, bool $subscribeNewsletter)
  14. {
  15. if ($subscribeNewsletter) {
  16. $user->addNewsletter($newsletter);
  17. } else {
  18. $user->removeNewsletter($newsletter);
  19. }
  20. $this->entityManager->persist($user);
  21. $this->entityManager->flush();
  22. }
  23. }