]>
Commit | Line | Data |
---|---|---|
fcb1fba5 NL |
1 | <?php |
2 | ||
ca17abce | 3 | namespace Wallabag\UserBundle\EventListener; |
fcb1fba5 | 4 | |
772d8c4b | 5 | use Doctrine\ORM\EntityManager; |
ca17abce | 6 | use FOS\UserBundle\Event\UserEvent; |
772d8c4b | 7 | use FOS\UserBundle\FOSUserEvents; |
619cc453 | 8 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
fcb1fba5 NL |
9 | use 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 | */ | |
15 | class CreateConfigListener implements EventSubscriberInterface | |
fcb1fba5 NL |
16 | { |
17 | private $em; | |
772d8c4b JB |
18 | private $theme; |
19 | private $itemsOnPage; | |
20 | private $rssLimit; | |
21 | private $language; | |
ca17abce | 22 | private $readingSpeed; |
24879db1 JB |
23 | private $actionMarkAsRead; |
24 | private $listMode; | |
fcb1fba5 | 25 | |
24879db1 | 26 | public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode) |
fcb1fba5 | 27 | { |
fcb1fba5 | 28 | $this->em = $em; |
772d8c4b JB |
29 | $this->theme = $theme; |
30 | $this->itemsOnPage = $itemsOnPage; | |
31 | $this->rssLimit = $rssLimit; | |
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); | |
54 | $config->setRssLimit($this->rssLimit); | |
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 | } |