]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/UserBundle/EventListener/CreateConfigListener.php
Rebase & Rename all rss to feeds
[github/wallabag/wallabag.git] / src / Wallabag / UserBundle / EventListener / CreateConfigListener.php
1 <?php
2
3 namespace Wallabag\UserBundle\EventListener;
4
5 use Doctrine\ORM\EntityManager;
6 use FOS\UserBundle\Event\UserEvent;
7 use FOS\UserBundle\FOSUserEvents;
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9 use Wallabag\CoreBundle\Entity\Config;
10
11 /**
12 * This listener will create the associated configuration when a user register.
13 * This configuration will be created right after the registration (no matter if it needs an email validation).
14 */
15 class CreateConfigListener implements EventSubscriberInterface
16 {
17 private $em;
18 private $theme;
19 private $itemsOnPage;
20 private $feedLimit;
21 private $language;
22 private $readingSpeed;
23 private $actionMarkAsRead;
24 private $listMode;
25
26 public function __construct(EntityManager $em, $theme, $itemsOnPage, $feedLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode)
27 {
28 $this->em = $em;
29 $this->theme = $theme;
30 $this->itemsOnPage = $itemsOnPage;
31 $this->feedLimit = $feedLimit;
32 $this->language = $language;
33 $this->readingSpeed = $readingSpeed;
34 $this->actionMarkAsRead = $actionMarkAsRead;
35 $this->listMode = $listMode;
36 }
37
38 public static function getSubscribedEvents()
39 {
40 return [
41 // when a user register using the normal form
42 FOSUserEvents::REGISTRATION_COMPLETED => 'createConfig',
43 // when we manually create a user using the command line
44 // OR when we create it from the config UI
45 FOSUserEvents::USER_CREATED => 'createConfig',
46 ];
47 }
48
49 public function createConfig(UserEvent $event)
50 {
51 $config = new Config($event->getUser());
52 $config->setTheme($this->theme);
53 $config->setItemsPerPage($this->itemsOnPage);
54 $config->setFeedLimit($this->feedLimit);
55 $config->setLanguage($this->language);
56 $config->setReadingSpeed($this->readingSpeed);
57 $config->setActionMarkAsRead($this->actionMarkAsRead);
58 $config->setListMode($this->listMode);
59
60 $this->em->persist($config);
61 $this->em->flush();
62 }
63 }