]>
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 JB |
8 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
9 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
fcb1fba5 NL |
10 | use Wallabag\CoreBundle\Entity\Config; |
11 | ||
ca17abce JB |
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 | */ | |
16 | class CreateConfigListener implements EventSubscriberInterface | |
fcb1fba5 NL |
17 | { |
18 | private $em; | |
772d8c4b JB |
19 | private $theme; |
20 | private $itemsOnPage; | |
21 | private $rssLimit; | |
22 | private $language; | |
ca17abce | 23 | private $readingSpeed; |
24879db1 JB |
24 | private $actionMarkAsRead; |
25 | private $listMode; | |
fcb1fba5 | 26 | |
24879db1 | 27 | public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode) |
fcb1fba5 | 28 | { |
fcb1fba5 | 29 | $this->em = $em; |
772d8c4b JB |
30 | $this->theme = $theme; |
31 | $this->itemsOnPage = $itemsOnPage; | |
32 | $this->rssLimit = $rssLimit; | |
33 | $this->language = $language; | |
ca17abce | 34 | $this->readingSpeed = $readingSpeed; |
24879db1 JB |
35 | $this->actionMarkAsRead = $actionMarkAsRead; |
36 | $this->listMode = $listMode; | |
fcb1fba5 NL |
37 | } |
38 | ||
39 | public static function getSubscribedEvents() | |
40 | { | |
4094ea47 | 41 | return [ |
ca17abce JB |
42 | // when a user register using the normal form |
43 | FOSUserEvents::REGISTRATION_COMPLETED => 'createConfig', | |
44 | // when we manually create a user using the command line | |
45 | // OR when we create it from the config UI | |
46 | FOSUserEvents::USER_CREATED => 'createConfig', | |
4094ea47 | 47 | ]; |
fcb1fba5 NL |
48 | } |
49 | ||
ca17abce | 50 | public function createConfig(UserEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null) |
fcb1fba5 | 51 | { |
fcb1fba5 | 52 | $config = new Config($event->getUser()); |
772d8c4b JB |
53 | $config->setTheme($this->theme); |
54 | $config->setItemsPerPage($this->itemsOnPage); | |
55 | $config->setRssLimit($this->rssLimit); | |
56 | $config->setLanguage($this->language); | |
ca17abce | 57 | $config->setReadingSpeed($this->readingSpeed); |
24879db1 JB |
58 | $config->setActionMarkAsRead($this->actionMarkAsRead); |
59 | $config->setListMode($this->listMode); | |
ca17abce | 60 | |
fcb1fba5 NL |
61 | $this->em->persist($config); |
62 | $this->em->flush(); | |
63 | } | |
64 | } |