]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\EventListener; | |
4 | ||
5 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; | |
6 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
7 | use Doctrine\ORM\EntityManager; | |
8 | use FOS\UserBundle\Event\FilterUserResponseEvent; | |
9 | use FOS\UserBundle\FOSUserEvents; | |
10 | use Wallabag\CoreBundle\Entity\Config; | |
11 | ||
12 | class RegistrationConfirmedListener implements EventSubscriberInterface | |
13 | { | |
14 | private $em; | |
15 | private $theme; | |
16 | private $itemsOnPage; | |
17 | private $rssLimit; | |
18 | private $language; | |
19 | ||
20 | public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language) | |
21 | { | |
22 | $this->em = $em; | |
23 | $this->theme = $theme; | |
24 | $this->itemsOnPage = $itemsOnPage; | |
25 | $this->rssLimit = $rssLimit; | |
26 | $this->language = $language; | |
27 | } | |
28 | ||
29 | public static function getSubscribedEvents() | |
30 | { | |
31 | return array( | |
32 | FOSUserEvents::REGISTRATION_CONFIRMED => 'authenticate', | |
33 | ); | |
34 | } | |
35 | ||
36 | public function authenticate(FilterUserResponseEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null) | |
37 | { | |
38 | if (!$event->getUser()->isEnabled()) { | |
39 | return; | |
40 | } | |
41 | ||
42 | $config = new Config($event->getUser()); | |
43 | $config->setTheme($this->theme); | |
44 | $config->setItemsPerPage($this->itemsOnPage); | |
45 | $config->setRssLimit($this->rssLimit); | |
46 | $config->setLanguage($this->language); | |
47 | $this->em->persist($config); | |
48 | $this->em->flush(); | |
49 | } | |
50 | } |