2015-09-29 12:31:52 +00:00
|
|
|
<?php
|
|
|
|
|
2016-09-30 19:01:36 +00:00
|
|
|
namespace Wallabag\UserBundle\EventListener;
|
2015-09-29 12:31:52 +00:00
|
|
|
|
2015-10-01 20:25:23 +00:00
|
|
|
use Doctrine\ORM\EntityManager;
|
2016-09-30 19:01:36 +00:00
|
|
|
use FOS\UserBundle\Event\UserEvent;
|
2015-10-01 20:25:23 +00:00
|
|
|
use FOS\UserBundle\FOSUserEvents;
|
2015-12-22 09:16:34 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
2015-09-29 12:31:52 +00:00
|
|
|
use Wallabag\CoreBundle\Entity\Config;
|
|
|
|
|
2016-09-30 19:01:36 +00:00
|
|
|
/**
|
|
|
|
* This listener will create the associated configuration when a user register.
|
|
|
|
* This configuration will be created right after the registration (no matter if it needs an email validation).
|
|
|
|
*/
|
|
|
|
class CreateConfigListener implements EventSubscriberInterface
|
2015-09-29 12:31:52 +00:00
|
|
|
{
|
|
|
|
private $em;
|
2015-10-01 20:25:23 +00:00
|
|
|
private $theme;
|
|
|
|
private $itemsOnPage;
|
|
|
|
private $rssLimit;
|
|
|
|
private $language;
|
2016-09-30 19:01:36 +00:00
|
|
|
private $readingSpeed;
|
2016-12-12 16:41:03 +00:00
|
|
|
private $actionMarkAsRead;
|
|
|
|
private $listMode;
|
2015-09-29 12:31:52 +00:00
|
|
|
|
2016-12-12 16:41:03 +00:00
|
|
|
public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode)
|
2015-09-29 12:31:52 +00:00
|
|
|
{
|
|
|
|
$this->em = $em;
|
2015-10-01 20:25:23 +00:00
|
|
|
$this->theme = $theme;
|
|
|
|
$this->itemsOnPage = $itemsOnPage;
|
|
|
|
$this->rssLimit = $rssLimit;
|
|
|
|
$this->language = $language;
|
2016-09-30 19:01:36 +00:00
|
|
|
$this->readingSpeed = $readingSpeed;
|
2016-12-12 16:41:03 +00:00
|
|
|
$this->actionMarkAsRead = $actionMarkAsRead;
|
|
|
|
$this->listMode = $listMode;
|
2015-09-29 12:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getSubscribedEvents()
|
|
|
|
{
|
2016-04-12 09:36:01 +00:00
|
|
|
return [
|
2016-09-30 19:01:36 +00:00
|
|
|
// when a user register using the normal form
|
|
|
|
FOSUserEvents::REGISTRATION_COMPLETED => 'createConfig',
|
|
|
|
// when we manually create a user using the command line
|
|
|
|
// OR when we create it from the config UI
|
|
|
|
FOSUserEvents::USER_CREATED => 'createConfig',
|
2016-04-12 09:36:01 +00:00
|
|
|
];
|
2015-09-29 12:31:52 +00:00
|
|
|
}
|
|
|
|
|
2016-09-30 19:01:36 +00:00
|
|
|
public function createConfig(UserEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null)
|
2015-09-29 12:31:52 +00:00
|
|
|
{
|
|
|
|
$config = new Config($event->getUser());
|
2015-10-01 20:25:23 +00:00
|
|
|
$config->setTheme($this->theme);
|
|
|
|
$config->setItemsPerPage($this->itemsOnPage);
|
|
|
|
$config->setRssLimit($this->rssLimit);
|
|
|
|
$config->setLanguage($this->language);
|
2016-09-30 19:01:36 +00:00
|
|
|
$config->setReadingSpeed($this->readingSpeed);
|
2016-12-12 16:41:03 +00:00
|
|
|
$config->setActionMarkAsRead($this->actionMarkAsRead);
|
|
|
|
$config->setListMode($this->listMode);
|
2016-09-30 19:01:36 +00:00
|
|
|
|
2015-09-29 12:31:52 +00:00
|
|
|
$this->em->persist($config);
|
|
|
|
$this->em->flush();
|
|
|
|
}
|
|
|
|
}
|