]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/UserBundle/EventListener/CreateConfigListener.php
Rebase & Rename all rss to feeds
[github/wallabag/wallabag.git] / src / Wallabag / UserBundle / EventListener / CreateConfigListener.php
CommitLineData
fcb1fba5
NL
1<?php
2
ca17abce 3namespace Wallabag\UserBundle\EventListener;
fcb1fba5 4
772d8c4b 5use Doctrine\ORM\EntityManager;
ca17abce 6use FOS\UserBundle\Event\UserEvent;
772d8c4b 7use FOS\UserBundle\FOSUserEvents;
619cc453 8use Symfony\Component\EventDispatcher\EventSubscriberInterface;
fcb1fba5
NL
9use Wallabag\CoreBundle\Entity\Config;
10
ca17abce
JB
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 */
15class CreateConfigListener implements EventSubscriberInterface
fcb1fba5
NL
16{
17 private $em;
772d8c4b
JB
18 private $theme;
19 private $itemsOnPage;
1554eb0a 20 private $feedLimit;
772d8c4b 21 private $language;
ca17abce 22 private $readingSpeed;
24879db1
JB
23 private $actionMarkAsRead;
24 private $listMode;
fcb1fba5 25
1554eb0a 26 public function __construct(EntityManager $em, $theme, $itemsOnPage, $feedLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode)
fcb1fba5 27 {
fcb1fba5 28 $this->em = $em;
772d8c4b
JB
29 $this->theme = $theme;
30 $this->itemsOnPage = $itemsOnPage;
1554eb0a 31 $this->feedLimit = $feedLimit;
772d8c4b 32 $this->language = $language;
ca17abce 33 $this->readingSpeed = $readingSpeed;
24879db1
JB
34 $this->actionMarkAsRead = $actionMarkAsRead;
35 $this->listMode = $listMode;
fcb1fba5
NL
36 }
37
38 public static function getSubscribedEvents()
39 {
4094ea47 40 return [
ca17abce
JB
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',
4094ea47 46 ];
fcb1fba5
NL
47 }
48
10bf812a 49 public function createConfig(UserEvent $event)
fcb1fba5 50 {
fcb1fba5 51 $config = new Config($event->getUser());
772d8c4b
JB
52 $config->setTheme($this->theme);
53 $config->setItemsPerPage($this->itemsOnPage);
1554eb0a 54 $config->setFeedLimit($this->feedLimit);
772d8c4b 55 $config->setLanguage($this->language);
ca17abce 56 $config->setReadingSpeed($this->readingSpeed);
24879db1
JB
57 $config->setActionMarkAsRead($this->actionMarkAsRead);
58 $config->setListMode($this->listMode);
ca17abce 59
fcb1fba5
NL
60 $this->em->persist($config);
61 $this->em->flush();
62 }
63}