|
|
|
@ -5,11 +5,13 @@ |
|
|
|
|
namespace Chamilo\CoreBundle\EventListener; |
|
|
|
|
|
|
|
|
|
use Chamilo\CoreBundle\Framework\Container; |
|
|
|
|
use Chamilo\UserBundle\Entity\User; |
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
use Symfony\Component\HttpKernel\Event\ControllerEvent; |
|
|
|
|
use Symfony\Component\HttpKernel\Event\RequestEvent; |
|
|
|
|
use Symfony\Component\HttpKernel\Event\ResponseEvent; |
|
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Class LegacyListener |
|
|
|
@ -38,9 +40,12 @@ class LegacyListener |
|
|
|
|
|
|
|
|
|
// Legacy way of detect current access_url |
|
|
|
|
$installed = $container->getParameter('installed'); |
|
|
|
|
|
|
|
|
|
$urlId = 1; |
|
|
|
|
if (empty($installed)) { |
|
|
|
|
throw new \Exception('Chamilo is not installed'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($installed)) { |
|
|
|
|
$twig = $container->get('twig'); |
|
|
|
|
|
|
|
|
|
// Set legacy twig globals _p, _u, _s |
|
|
|
@ -52,22 +57,20 @@ class LegacyListener |
|
|
|
|
$token = $container->get('security.token_storage')->getToken(); |
|
|
|
|
$userObject = null; |
|
|
|
|
if (null !== $token) { |
|
|
|
|
/** @var User $userObject */ |
|
|
|
|
$userObject = $container->get('security.token_storage')->getToken()->getUser(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$userInfo = []; |
|
|
|
|
$userInfo['is_anonymous'] = true; |
|
|
|
|
$isAdmin = false; |
|
|
|
|
$allowedCreateCourse = false; |
|
|
|
|
$userStatus = null; |
|
|
|
|
$userId = $session->get('_uid'); |
|
|
|
|
|
|
|
|
|
if (null !== $userObject && !empty($userId)) { |
|
|
|
|
$userInfo = api_get_user_info(); |
|
|
|
|
//$userId = $session->get('_uid'); |
|
|
|
|
if ($userObject instanceof UserInterface) { |
|
|
|
|
$userInfo = api_get_user_info($userObject->getId()); |
|
|
|
|
if ($userInfo) { |
|
|
|
|
$userStatus = $userInfo['status']; |
|
|
|
|
$isAdmin = $userInfo['is_admin']; |
|
|
|
|
$userInfo['is_anonymous'] = false; |
|
|
|
|
$userStatus = $userObject->getStatus(); |
|
|
|
|
$isAdmin = $userObject->hasGroup('ROLE_ADMIN'); |
|
|
|
|
} |
|
|
|
|
$allowedCreateCourse = 1 === $userStatus; |
|
|
|
|
} |
|
|
|
@ -114,7 +117,7 @@ class LegacyListener |
|
|
|
|
$extraHeader = trim(api_get_setting('header_extra_content')); |
|
|
|
|
} |
|
|
|
|
$twig->addGlobal('header_extra_content', $extraHeader); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We set cid_reset = true if we enter inside a main/admin url |
|
|
|
|
// CourseListener check this variable and deletes the course session |
|
|
|
|