]> git.immae.eu Git - github/wallabag/wallabag.git/blame_incremental - src/Wallabag/UserBundle/EventListener/CreateConfigListener.php
Merge pull request #2616 from mathieui/doc-https-links
[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\EventDispatcherInterface;
9use Symfony\Component\EventDispatcher\EventSubscriberInterface;
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
27 public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode)
28 {
29 $this->em = $em;
30 $this->theme = $theme;
31 $this->itemsOnPage = $itemsOnPage;
32 $this->rssLimit = $rssLimit;
33 $this->language = $language;
34 $this->readingSpeed = $readingSpeed;
35 $this->actionMarkAsRead = $actionMarkAsRead;
36 $this->listMode = $listMode;
37 }
38
39 public static function getSubscribedEvents()
40 {
41 return [
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',
47 ];
48 }
49
50 public function createConfig(UserEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null)
51 {
52 $config = new Config($event->getUser());
53 $config->setTheme($this->theme);
54 $config->setItemsPerPage($this->itemsOnPage);
55 $config->setRssLimit($this->rssLimit);
56 $config->setLanguage($this->language);
57 $config->setReadingSpeed($this->readingSpeed);
58 $config->setActionMarkAsRead($this->actionMarkAsRead);
59 $config->setListMode($this->listMode);
60
61 $this->em->persist($config);
62 $this->em->flush();
63 }
64}