|
1234567891011121314151617181920212223242526272829 |
- <?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)
- {
- if ($subscribeNewsletter) {
- $user->addNewsletter($newsletter);
- } else {
- $user->removeNewsletter($newsletter);
- }
-
- $this->entityManager->persist($user);
- $this->entityManager->flush();
- }
- }
|