3 namespace Wallabag\UserBundle\EventListener
;
5 use Doctrine\ORM\EntityManager
;
6 use FOS\UserBundle\Event\UserEvent
;
7 use FOS\UserBundle\FOSUserEvents
;
8 use Symfony\Component\EventDispatcher\EventDispatcherInterface
;
9 use Symfony\Component\EventDispatcher\EventSubscriberInterface
;
10 use Wallabag\CoreBundle\Entity\Config
;
13 * This listener will create the associated configuration when a user register.
14 * This configuration will be created right after the registration (no matter if it needs an email validation).
16 class CreateConfigListener
implements EventSubscriberInterface
23 private $readingSpeed;
24 private $actionMarkAsRead;
27 public function __construct(EntityManager
$em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode)
30 $this->theme
= $theme;
31 $this->itemsOnPage
= $itemsOnPage;
32 $this->rssLimit
= $rssLimit;
33 $this->language
= $language;
34 $this->readingSpeed
= $readingSpeed;
35 $this->actionMarkAsRead
= $actionMarkAsRead;
36 $this->listMode
= $listMode;
39 public static function getSubscribedEvents()
42 // when a user register using the normal form
43 FOSUserEvents
::REGISTRATION_COMPLETED
=> 'createConfig',
44 // when we manually create a user using the command line
45 // OR when we create it from the config UI
46 FOSUserEvents
::USER_CREATED
=> 'createConfig',
50 public function createConfig(UserEvent
$event, $eventName = null, EventDispatcherInterface
$eventDispatcher = null)
52 $config = new Config($event->getUser());
53 $config->setTheme($this->theme
);
54 $config->setItemsPerPage($this->itemsOnPage
);
55 $config->setRssLimit($this->rssLimit
);
56 $config->setLanguage($this->language
);
57 $config->setReadingSpeed($this->readingSpeed
);
58 $config->setActionMarkAsRead($this->actionMarkAsRead
);
59 $config->setListMode($this->listMode
);
61 $this->em
->persist($config);