2012-07-31 23:15:10 +00:00
< ? php
namespace KekRozsak\SecurityBundle\Twig ;
use Symfony\Component\Security\Core\SecurityContextInterface ;
2012-08-01 06:48:16 +00:00
use Symfony\Bundle\FrameworkBundle\Routing\Router ;
2012-08-16 17:06:00 +00:00
use JMS\DiExtraBundle\Annotation as DI ;
2012-07-31 23:15:10 +00:00
use KekRozsak\SecurityBundle\Entity\User ;
2012-08-16 17:06:00 +00:00
/**
* @ DI\Service
* @ DI\Tag ( " twig.extension " )
*/
2012-07-31 23:15:10 +00:00
class UserDataSpanExtension extends \Twig_Extension
{
2012-08-16 13:52:41 +00:00
protected $_securityContext ;
protected $_router ;
2012-08-16 17:06:00 +00:00
/**
* @ DI\InjectParams ({
* " router " = @ DI\Inject ( " router " ),
* " security " = @ DI\Inject ( " security.context " )
* })
*
* @ param \Symfony\Bundle\FrameworkBundle\Routing\Router $router
* @ param \Symfony\Component\Security\Core\SecurityContextInterface $security
*/
2012-08-16 13:52:41 +00:00
public function __construct ( Router $router , SecurityContextInterface $security )
{
$this -> _router = $router ;
$this -> _securityContext = $security ;
}
public function getFilters ()
{
return array (
'userdataspan' => new \Twig_Filter_Method (
$this ,
'getUserDataSpan' ,
array ( 'is_safe' => array ( 'html' ))
),
);
}
public function getUserDataSpan ( User $user )
{
if (
! is_object ( $this -> _securityContext -> getToken ())
|| ! is_object ( $this -> _securityContext -> getToken () -> getUser ())
) {
return '<span class="userdata-secret" title="|Felhasználó|A felhasználóink kiléte szigorúan bizalmas, csak a tagok számára elérhető.">[nem jelenhet meg]</span>' ;
}
return '<span class="userdata" rel="' . $this -> _router -> generate ( 'KekRozsakSecurityBundle_ajaxUserdata' , array ( 'id' => $user -> getId (), '_format' => 'html' )) . '"><a href="">' . $user -> getDisplayName () . '</a></span>' ;
}
public function getName ()
{
return 'twig_userdataspan' ;
}
2012-07-31 23:15:10 +00:00
}