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\EventSubscriberInterface
;
9 use Symfony\Component\HttpFoundation\Session\Session
;
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;
28 public function __construct(EntityManager
$em, $theme, $itemsOnPage, $feedLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode, Session
$session)
31 $this->theme
= $theme;
32 $this->itemsOnPage
= $itemsOnPage;
33 $this->feedLimit
= $feedLimit;
34 $this->language
= $language;
35 $this->readingSpeed
= $readingSpeed;
36 $this->actionMarkAsRead
= $actionMarkAsRead;
37 $this->listMode
= $listMode;
38 $this->session
= $session;
41 public static function getSubscribedEvents()
44 // when a user register using the normal form
45 FOSUserEvents
::REGISTRATION_COMPLETED
=> 'createConfig',
46 // when we manually create a user using the command line
47 // OR when we create it from the config UI
48 FOSUserEvents
::USER_CREATED
=> 'createConfig',
52 public function createConfig(UserEvent
$event)
54 $config = new Config($event->getUser());
55 $config->setTheme($this->theme
);
56 $config->setItemsPerPage($this->itemsOnPage
);
57 $config->setFeedLimit($this->feedLimit
);
58 $config->setLanguage($this->session
->get('_locale', $this->language
));
59 $config->setReadingSpeed($this->readingSpeed
);
60 $config->setActionMarkAsRead($this->actionMarkAsRead
);
61 $config->setListMode($this->listMode
);
63 $this->em
->persist($config);