|
|
@ -5,11 +5,13 @@ |
|
|
|
namespace Chamilo\CoreBundle\EventListener; |
|
|
|
namespace Chamilo\CoreBundle\EventListener; |
|
|
|
|
|
|
|
|
|
|
|
use Chamilo\CoreBundle\Framework\Container; |
|
|
|
use Chamilo\CoreBundle\Framework\Container; |
|
|
|
|
|
|
|
use Chamilo\UserBundle\Entity\User; |
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
use Symfony\Component\HttpKernel\Event\ControllerEvent; |
|
|
|
use Symfony\Component\HttpKernel\Event\ControllerEvent; |
|
|
|
use Symfony\Component\HttpKernel\Event\RequestEvent; |
|
|
|
use Symfony\Component\HttpKernel\Event\RequestEvent; |
|
|
|
use Symfony\Component\HttpKernel\Event\ResponseEvent; |
|
|
|
use Symfony\Component\HttpKernel\Event\ResponseEvent; |
|
|
|
|
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Class LegacyListener |
|
|
|
* Class LegacyListener |
|
|
@ -38,83 +40,84 @@ class LegacyListener |
|
|
|
|
|
|
|
|
|
|
|
// Legacy way of detect current access_url |
|
|
|
// Legacy way of detect current access_url |
|
|
|
$installed = $container->getParameter('installed'); |
|
|
|
$installed = $container->getParameter('installed'); |
|
|
|
|
|
|
|
|
|
|
|
$urlId = 1; |
|
|
|
$urlId = 1; |
|
|
|
|
|
|
|
if (empty($installed)) { |
|
|
|
|
|
|
|
throw new \Exception('Chamilo is not installed'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($installed)) { |
|
|
|
$twig = $container->get('twig'); |
|
|
|
$twig = $container->get('twig'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set legacy twig globals _p, _u, _s |
|
|
|
// Set legacy twig globals _p, _u, _s |
|
|
|
/*$globals = \Template::getGlobals(); |
|
|
|
/*$globals = \Template::getGlobals(); |
|
|
|
foreach ($globals as $index => $value) { |
|
|
|
foreach ($globals as $index => $value) { |
|
|
|
$twig->addGlobal($index, $value); |
|
|
|
$twig->addGlobal($index, $value); |
|
|
|
}*/ |
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
$token = $container->get('security.token_storage')->getToken(); |
|
|
|
$token = $container->get('security.token_storage')->getToken(); |
|
|
|
$userObject = null; |
|
|
|
$userObject = null; |
|
|
|
if (null !== $token) { |
|
|
|
if (null !== $token) { |
|
|
|
$userObject = $container->get('security.token_storage')->getToken()->getUser(); |
|
|
|
/** @var User $userObject */ |
|
|
|
} |
|
|
|
$userObject = $container->get('security.token_storage')->getToken()->getUser(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$userInfo = []; |
|
|
|
$userInfo = []; |
|
|
|
$userInfo['is_anonymous'] = true; |
|
|
|
$isAdmin = false; |
|
|
|
$isAdmin = false; |
|
|
|
$allowedCreateCourse = false; |
|
|
|
$allowedCreateCourse = false; |
|
|
|
$userStatus = null; |
|
|
|
$userStatus = null; |
|
|
|
//$userId = $session->get('_uid'); |
|
|
|
$userId = $session->get('_uid'); |
|
|
|
if ($userObject instanceof UserInterface) { |
|
|
|
|
|
|
|
$userInfo = api_get_user_info($userObject->getId()); |
|
|
|
if (null !== $userObject && !empty($userId)) { |
|
|
|
if ($userInfo) { |
|
|
|
$userInfo = api_get_user_info(); |
|
|
|
$userStatus = $userObject->getStatus(); |
|
|
|
if ($userInfo) { |
|
|
|
$isAdmin = $userObject->hasGroup('ROLE_ADMIN'); |
|
|
|
$userStatus = $userInfo['status']; |
|
|
|
|
|
|
|
$isAdmin = $userInfo['is_admin']; |
|
|
|
|
|
|
|
$userInfo['is_anonymous'] = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$allowedCreateCourse = 1 === $userStatus; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$session->set('_user', $userInfo); |
|
|
|
|
|
|
|
$session->set('is_platformAdmin', $isAdmin); |
|
|
|
|
|
|
|
$session->set('is_allowedCreateCourse', $allowedCreateCourse); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*$adminInfo = [ |
|
|
|
|
|
|
|
'email' => api_get_setting('emailAdministrator'), |
|
|
|
|
|
|
|
'surname' => api_get_setting('administratorSurname'), |
|
|
|
|
|
|
|
'name' => api_get_setting('administratorName'), |
|
|
|
|
|
|
|
'telephone' => api_get_setting('administratorTelephone'), |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$twig->addGlobal('_admin', $adminInfo);*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Theme icon is loaded in the TwigListener src/ThemeBundle/EventListener/TwigListener.php |
|
|
|
|
|
|
|
//$theme = api_get_visual_theme(); |
|
|
|
|
|
|
|
$languages = api_get_languages(); |
|
|
|
|
|
|
|
$languageList = []; |
|
|
|
|
|
|
|
foreach ($languages as $isoCode => $language) { |
|
|
|
|
|
|
|
$languageList[languageToCountryIsoCode($isoCode)] = $language; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$allowedCreateCourse = 1 === $userStatus; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$session->set('_user', $userInfo); |
|
|
|
|
|
|
|
$session->set('is_platformAdmin', $isAdmin); |
|
|
|
|
|
|
|
$session->set('is_allowedCreateCourse', $allowedCreateCourse); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*$adminInfo = [ |
|
|
|
|
|
|
|
'email' => api_get_setting('emailAdministrator'), |
|
|
|
|
|
|
|
'surname' => api_get_setting('administratorSurname'), |
|
|
|
|
|
|
|
'name' => api_get_setting('administratorName'), |
|
|
|
|
|
|
|
'telephone' => api_get_setting('administratorTelephone'), |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$twig->addGlobal('_admin', $adminInfo);*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Theme icon is loaded in the TwigListener src/ThemeBundle/EventListener/TwigListener.php |
|
|
|
|
|
|
|
//$theme = api_get_visual_theme(); |
|
|
|
|
|
|
|
$languages = api_get_languages(); |
|
|
|
|
|
|
|
$languageList = []; |
|
|
|
|
|
|
|
foreach ($languages as $isoCode => $language) { |
|
|
|
|
|
|
|
$languageList[languageToCountryIsoCode($isoCode)] = $language; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$isoFixed = languageToCountryIsoCode($request->getLocale()); |
|
|
|
$isoFixed = languageToCountryIsoCode($request->getLocale()); |
|
|
|
|
|
|
|
|
|
|
|
if (!isset($languageList[$isoFixed])) { |
|
|
|
if (!isset($languageList[$isoFixed])) { |
|
|
|
$isoFixed = 'en'; |
|
|
|
$isoFixed = 'en'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$twig->addGlobal( |
|
|
|
$twig->addGlobal( |
|
|
|
'current_locale_info', |
|
|
|
'current_locale_info', |
|
|
|
[ |
|
|
|
[ |
|
|
|
'flag' => $isoFixed, |
|
|
|
'flag' => $isoFixed, |
|
|
|
'text' => $languageList[$isoFixed] ?? 'English', |
|
|
|
'text' => $languageList[$isoFixed] ?? 'English', |
|
|
|
] |
|
|
|
] |
|
|
|
); |
|
|
|
); |
|
|
|
$twig->addGlobal('current_locale', $request->getLocale()); |
|
|
|
$twig->addGlobal('current_locale', $request->getLocale()); |
|
|
|
$twig->addGlobal('available_locales', $languages); |
|
|
|
$twig->addGlobal('available_locales', $languages); |
|
|
|
$twig->addGlobal('show_toolbar', \Template::isToolBarDisplayedForUser() ? 1 : 0); |
|
|
|
$twig->addGlobal('show_toolbar', \Template::isToolBarDisplayedForUser() ? 1 : 0); |
|
|
|
|
|
|
|
|
|
|
|
// Extra content |
|
|
|
// Extra content |
|
|
|
$extraHeader = ''; |
|
|
|
$extraHeader = ''; |
|
|
|
if (!api_is_platform_admin()) { |
|
|
|
if (!api_is_platform_admin()) { |
|
|
|
$extraHeader = trim(api_get_setting('header_extra_content')); |
|
|
|
$extraHeader = trim(api_get_setting('header_extra_content')); |
|
|
|
} |
|
|
|
|
|
|
|
$twig->addGlobal('header_extra_content', $extraHeader); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$twig->addGlobal('header_extra_content', $extraHeader); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We set cid_reset = true if we enter inside a main/admin url |
|
|
|
// We set cid_reset = true if we enter inside a main/admin url |
|
|
|
// CourseListener check this variable and deletes the course session |
|
|
|
// CourseListener check this variable and deletes the course session |
|
|
|