1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace JaiUneIdee\UtilisateurBundle\Listener;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Events;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use FOS\UserBundle\Model\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Doctrine ORM listener updating the canonical fields and the password.
*
* @author Christophe Coevoet <stof@notk.org>
*/
class UserListener implements EventSubscriber
{
/**
* @var \FOS\UserBundle\Model\UserManagerInterface
*/
private $userManager;
/**
* @var ContainerInterface
*/
private $container;
/*
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
*/
public function getSubscribedEvents()
{
return array(
Events::prePersist,
);
}
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof UserInterface) {
if (null === $this->userManager) {
//$this->userManager = $this->container->get('fos_user.user_manager');
$em = $args->getEntityManager();
$dommage = $em->getRepository('JaiUneIdeeUtilisateurBundle:Dommage')->getUserDefaultDommage();
$entity->setDommage($dommage);
}
}
}
} |
Partager