diff options
author | Paulino Michelazzo <paulino@michelazzo.com.br> | 2016-10-18 22:48:23 +0200 |
---|---|---|
committer | Paulino Michelazzo <paulino@michelazzo.com.br> | 2016-10-18 22:48:23 +0200 |
commit | 99731f0bb1f6fd2815eeb9af504ce86df927657b (patch) | |
tree | b080efc608d2bbd52b77a4a0067402007f50c5a8 /src/Wallabag/UserBundle/EventListener | |
parent | 3a3c6b866b52721431bed22426d9abfcd0d2dfe0 (diff) | |
parent | 7180aaed45dce62e40620a9e4b202526ebd6a3bb (diff) | |
download | wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.gz wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.zst wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.zip |
Merge remote-tracking branch 'wallabag/master'
Diffstat (limited to 'src/Wallabag/UserBundle/EventListener')
-rw-r--r-- | src/Wallabag/UserBundle/EventListener/CreateConfigListener.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php b/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php new file mode 100644 index 00000000..8e2f04e9 --- /dev/null +++ b/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php | |||
@@ -0,0 +1,58 @@ | |||
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\EventDispatcherInterface; | ||
9 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
10 | use 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 | */ | ||
16 | class CreateConfigListener implements EventSubscriberInterface | ||
17 | { | ||
18 | private $em; | ||
19 | private $theme; | ||
20 | private $itemsOnPage; | ||
21 | private $rssLimit; | ||
22 | private $language; | ||
23 | private $readingSpeed; | ||
24 | |||
25 | public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed) | ||
26 | { | ||
27 | $this->em = $em; | ||
28 | $this->theme = $theme; | ||
29 | $this->itemsOnPage = $itemsOnPage; | ||
30 | $this->rssLimit = $rssLimit; | ||
31 | $this->language = $language; | ||
32 | $this->readingSpeed = $readingSpeed; | ||
33 | } | ||
34 | |||
35 | public static function getSubscribedEvents() | ||
36 | { | ||
37 | return [ | ||
38 | // when a user register using the normal form | ||
39 | FOSUserEvents::REGISTRATION_COMPLETED => 'createConfig', | ||
40 | // when we manually create a user using the command line | ||
41 | // OR when we create it from the config UI | ||
42 | FOSUserEvents::USER_CREATED => 'createConfig', | ||
43 | ]; | ||
44 | } | ||
45 | |||
46 | public function createConfig(UserEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null) | ||
47 | { | ||
48 | $config = new Config($event->getUser()); | ||
49 | $config->setTheme($this->theme); | ||
50 | $config->setItemsPerPage($this->itemsOnPage); | ||
51 | $config->setRssLimit($this->rssLimit); | ||
52 | $config->setLanguage($this->language); | ||
53 | $config->setReadingSpeed($this->readingSpeed); | ||
54 | |||
55 | $this->em->persist($config); | ||
56 | $this->em->flush(); | ||
57 | } | ||
58 | } | ||