|
|
|
|
@ -8,6 +8,7 @@ namespace Chamilo\CoreBundle\EventListener; |
|
|
|
|
|
|
|
|
|
use Chamilo\CoreBundle\Entity\User; |
|
|
|
|
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository; |
|
|
|
|
use Chamilo\CoreBundle\Settings\SettingsManager; |
|
|
|
|
use Symfony\Component\HttpKernel\Event\RequestEvent; |
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
|
|
|
@ -19,18 +20,22 @@ class TwigListener |
|
|
|
|
private SerializerInterface $serializer; |
|
|
|
|
private Environment $twig; |
|
|
|
|
private TokenStorageInterface $tokenStorage; |
|
|
|
|
private IllustrationRepository $illustrationRepository; |
|
|
|
|
private SettingsManager $settingsManager; |
|
|
|
|
|
|
|
|
|
//private IllustrationRepository $illustrationRepository; |
|
|
|
|
|
|
|
|
|
public function __construct( |
|
|
|
|
Environment $twig, |
|
|
|
|
SerializerInterface $serializer, |
|
|
|
|
TokenStorageInterface $tokenStorage, |
|
|
|
|
IllustrationRepository $illustrationRepository |
|
|
|
|
SettingsManager $settingsManager |
|
|
|
|
//IllustrationRepository $illustrationRepository |
|
|
|
|
) { |
|
|
|
|
$this->twig = $twig; |
|
|
|
|
$this->tokenStorage = $tokenStorage; |
|
|
|
|
$this->serializer = $serializer; |
|
|
|
|
$this->illustrationRepository = $illustrationRepository; |
|
|
|
|
$this->settingsManager = $settingsManager; |
|
|
|
|
//$this->illustrationRepository = $illustrationRepository; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function __invoke(RequestEvent $event): void |
|
|
|
|
@ -39,7 +44,6 @@ class TwigListener |
|
|
|
|
$token = $this->tokenStorage->getToken(); |
|
|
|
|
|
|
|
|
|
$data = null; |
|
|
|
|
$avatar = null; |
|
|
|
|
$isAuth = false; |
|
|
|
|
if (null !== $token) { |
|
|
|
|
$user = $token->getUser(); |
|
|
|
|
@ -49,15 +53,31 @@ class TwigListener |
|
|
|
|
$data = $this->serializer->serialize($userClone, 'jsonld', [ |
|
|
|
|
'groups' => ['user_json:read'], |
|
|
|
|
]); |
|
|
|
|
$avatar = $this->illustrationRepository->getIllustrationUrl($userClone); |
|
|
|
|
$isAuth = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$settings = [ |
|
|
|
|
'platform.site_name', |
|
|
|
|
'platform.timezone', |
|
|
|
|
'platform.theme', |
|
|
|
|
'platform.administrator_name', |
|
|
|
|
'platform.administrator_surname', |
|
|
|
|
|
|
|
|
|
'editor.enabled_mathjax', |
|
|
|
|
//'editor.translate_html', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$config = []; |
|
|
|
|
foreach ($settings as $variable) { |
|
|
|
|
$value = $this->settingsManager->getSetting($variable); |
|
|
|
|
$config[$variable] = $value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//$this->twig->addGlobal('text_direction', api_get_text_direction()); |
|
|
|
|
$this->twig->addGlobal('from_vue', $request->request->get('from_vue') ? 1 : 0); |
|
|
|
|
$this->twig->addGlobal('is_authenticated', json_encode($isAuth)); |
|
|
|
|
$this->twig->addGlobal('user_json', $data ?? json_encode([])); |
|
|
|
|
$this->twig->addGlobal('user_avatar', $avatar); |
|
|
|
|
$this->twig->addGlobal('config_json', json_encode($config)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|