|
- <?php
-
- namespace Lc\SovBundle\Builder\User;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
- use Lc\SovBundle\Model\User\UserInterface;
-
- class UserBuilder
- {
- protected EntityManagerInterface $entityManager;
-
- public function __construct(EntityManagerInterface $entityManager)
- {
- $this->entityManager = $entityManager;
- }
-
- public function setNewsletter(UserInterface $user, NewsletterInterface $newsletter, bool $subscribeNewsletter): void
- {
- if ($subscribeNewsletter) {
- $user->addNewsletter($newsletter);
- } else {
- $user->removeNewsletter($newsletter);
- }
-
- $this->entityManager->persist($user);
- $this->entityManager->flush();
- }
- }
|