]> git.immae.eu Git - github/wallabag/wallabag.git/blame_incremental - src/Wallabag/UserBundle/EventListener/CreateConfigListener.php
Merge remote-tracking branch 'origin/master' into 2.4
[github/wallabag/wallabag.git] / src / Wallabag / UserBundle / EventListener / CreateConfigListener.php
... / ...
CommitLineData
1<?php
2
3namespace Wallabag\UserBundle\EventListener;
4
5use Doctrine\ORM\EntityManager;
6use FOS\UserBundle\Event\UserEvent;
7use FOS\UserBundle\FOSUserEvents;
8use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9use Symfony\Component\HttpFoundation\Session\Session;
10use Wallabag\CoreBundle\Entity\Config;
11
12/**
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).
15 */
16class CreateConfigListener implements EventSubscriberInterface
17{
18 private $em;
19 private $theme;
20 private $itemsOnPage;
21 private $rssLimit;
22 private $language;
23 private $readingSpeed;
24 private $actionMarkAsRead;
25 private $listMode;
26 private $session;
27
28 public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode, Session $session)
29 {
30 $this->em = $em;
31 $this->theme = $theme;
32 $this->itemsOnPage = $itemsOnPage;
33 $this->rssLimit = $rssLimit;
34 $this->language = $language;
35 $this->readingSpeed = $readingSpeed;
36 $this->actionMarkAsRead = $actionMarkAsRead;
37 $this->listMode = $listMode;
38 $this->session = $session;
39 }
40
41 public static function getSubscribedEvents()
42 {
43 return [
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',
49 ];
50 }
51
52 public function createConfig(UserEvent $event)
53 {
54 $config = new Config($event->getUser());
55 $config->setTheme($this->theme);
56 $config->setItemsPerPage($this->itemsOnPage);
57 $config->setRssLimit($this->rssLimit);
58 $config->setLanguage($this->session->get('_locale', $this->language));
59 $config->setReadingSpeed($this->readingSpeed);
60 $config->setActionMarkAsRead($this->actionMarkAsRead);
61 $config->setListMode($this->listMode);
62
63 $this->em->persist($config);
64 $this->em->flush();
65 }
66}