Removing unused controllers/listeners.

1.10.x
Julio Montoya 11 years ago
parent d960d4264b
commit a869edf5c8
  1. 29
      src/ChamiloLMS/CoreBundle/Component/Auth/LoginListener.php
  2. 119
      src/ChamiloLMS/CoreBundle/Component/Auth/LoginSuccessHandler.php
  3. 47
      src/ChamiloLMS/CoreBundle/Component/Auth/LogoutSuccessHandler.php
  4. 530
      src/ChamiloLMS/CoreBundle/Controller/CrudController.php
  5. 37
      src/ChamiloLMS/CoreBundle/Controller/CrudControllerInterface.php
  6. 34
      src/ChamiloLMS/CoreBundle/Controller/SecurityController.php
  7. 100
      src/ChamiloLMS/CoreBundle/Listener/LegacyListener.php
  8. 139
      src/ChamiloLMS/CoreBundle/Listener/LoginSuccessHandler.php
  9. 49
      src/ChamiloLMS/CoreBundle/Listener/LogoutSuccessHandler.php
  10. 101
      src/ChamiloLMS/CoreBundle/Menu/Builder.php

@ -1,29 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\CoreBundle\Component\Auth;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
class LoginListener
{
/**
* Fired on switch user, you can remove attributes or whatever you want here.
* @param SwitchUserEvent $event
*/
public function onSecuritySwitchUser(SwitchUserEvent $event)
{
/** @var \ChamiloLMS\CoreBundle\Entity\User $user */
$user = $event->getTargetUser();
/*var_dump($user );
var_dump($event->getRequest()->getUser());
*/
$request = $event->getRequest();
$session = $request->getSession();
\ChamiloSession::setSession($session);
$session = $event->getRequest()->getSession();
//$session->remove('partThatShouldNotCarryOver');
}
}

@ -1,119 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\CoreBundle\Component\Auth;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use ChamiloLMS\CoreBundle\Entity\User;
/**
* Class LoginSuccessHandler
*/
class LoginSuccessHandler implements AuthenticationSuccessHandlerInterface
{
protected $router;
protected $security;
/**
* @param UrlGeneratorInterface $urlGenerator
* @param SecurityContext $security
*/
public function __construct(UrlGeneratorInterface $urlGenerator, SecurityContext $security)
{
$this->router = $urlGenerator;
$this->security = $security;
}
/**
* @param Request $request
* @param TokenInterface $token
* @return null|RedirectResponse|\Symfony\Component\Security\Http\Authentication\Response
*/
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
/** @var User $user */
$user = $token->getUser();
$userId = $user->getUserId();
$session = $request->getSession();
\ChamiloSession::setSession($session);
event_login($user);
// Setting last login datetime
$session->set('user_last_login_datetime', api_get_utc_datetime());
$response = null;
/* Possible values: index.php, user_portal.php, main/auth/courses.php */
$pageAfterLogin = api_get_setting('page_after_login');
$url = null;
if ($this->security->isGranted('ROLE_STUDENT') && !empty($pageAfterLogin)) {
switch ($pageAfterLogin) {
case 'index.php':
$url = $this->router->generate('index');
break;
case 'user_portal.php':
$url = $this->router->generate('userportal');
break;
case 'main/auth/courses.php':
$url = api_get_path(WEB_PUBLIC_PATH).$pageAfterLogin;
break;
}
}
// Redirecting to a course or a session
if (api_get_setting('go_to_course_after_login') == 'true') {
// Get the courses list
$personal_course_list = \UserManager::get_personal_session_course_list($userId);
$my_session_list = array();
$count_of_courses_no_sessions = 0;
$count_of_courses_with_sessions = 0;
foreach ($personal_course_list as $course) {
if (!empty($course['session_id'])) {
$my_session_list[$course['session_id']] = true;
$count_of_courses_with_sessions++;
} else {
$count_of_courses_no_sessions++;
}
}
$count_of_sessions = count($my_session_list);
if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) {
$key = array_keys($personal_course_list);
$course_info = $personal_course_list[$key[0]]['course_info'];
$id_session = isset($course_info['session_id']) ? $course_info['session_id'] : 0;
$url = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/index.php?id_session='.$id_session;
}
if ($count_of_sessions == 0 && $count_of_courses_no_sessions == 1) {
$key = array_keys($personal_course_list);
$course_info = $personal_course_list[$key[0]]['course_info'];
$url = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/index.php?id_session=0';
}
}
if (!empty($url)) {
$response = new RedirectResponse($url);
}
// Redirect the user to where they were before the login process begun.
if (empty($response)) {
$refererUrl = $request->headers->get('referer');
$response = new RedirectResponse($refererUrl);
}
return $response;
}
}

@ -1,47 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\CoreBundle\Listener;
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* Class LogoutSuccessHandler
*/
class LogoutSuccessHandler implements LogoutSuccessHandlerInterface
{
protected $router;
protected $security;
/**
* @param UrlGeneratorInterface $urlGenerator
* @param SecurityContext $security
*/
public function __construct(UrlGeneratorInterface $urlGenerator, SecurityContext $security)
{
$this->router = $urlGenerator;
$this->security = $security;
}
/**
* @param Request $request
* @return null|RedirectResponse
*/
public function onLogoutSuccess(Request $request)
{
$session = $request->getSession();
\ChamiloSession::setSession($session);
// Chamilo logout
$userId = api_get_user_id();
\Online::logout($userId, false);
$login = $this->router->generate('index');
$response = new RedirectResponse($login);
return $response;
}
}

@ -1,530 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\CoreBundle\Controller;
use Doctrine\ORM\Query;
use Doctrine\ORM\NoResultException;
use MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\stdClass;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Pagerfanta\Pagerfanta;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\View\TwitterBootstrap3View;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
/**
* Class CrudController
* @package ChamiloLMS\CoreBundle\Controller
*/
abstract class CrudController extends BaseController implements CrudControllerInterface
{
public $maxPerPage = 2;
//public $crudController = true;
/**
* Returns the entity's repository.
*
* @abstract
* @return \Doctrine\ORM\EntityRepository
*/
public function getRepository()
{
return $this->get('orm.em')->getRepository($this->getClass());
}
/**
* Returns a new entity instance to be used for the "create/edit" actions.
*
* @return stdClass
*/
public function getNewEntity()
{
$class = $this->getClass();
return new $class;
}
/**
* Returns a new Form Type
* @return \Symfony\Component\Form\AbstractType
*/
public function getFormType()
{
$class = $this->getType();
return new $class;
}
/**
*
* @Route("/")
* @Method({"GET"})
*/
public function indexAction()
{
$breadcrumbs = array(
array(
'name' => get_lang('Curriculum'),
'url' => array(
'route' => 'curriculum_user.controller:indexAction',
'routeParameters' => array(
//'course' => $this->getCourse()->getCode()
)
)
),
array(
'name' => get_lang('Categories')
)
);
//$this->setBreadcrumb(array());
return $this->listingAction();
}
/**
* @Route("/")
* @Method({"GET"})
*/
public function listingAction()
{
$template = $this->getTemplate();
// Getting query
$qb = $this->getRepository()->createQueryBuilder('e');
$query = $qb->getQuery();
// Process query in a pagination mode.
$adapter = new DoctrineORMAdapter($query);
$pager = new Pagerfanta($adapter);
$page = $this->getRequest()->get('page');
if (empty($page)) {
$page = 1;
}
$routeGenerator = function ($page) {
return $this->generateControllerUrl('listingAction', array('page' => $page));
};
$pager->setMaxPerPage($this->maxPerPage);
$pager->setCurrentPage($page);
$view = new TwitterBootstrap3View();
$pagination = $view->render($pager, $routeGenerator, array(
'proximity' => 3,
));
$template->assign('items', $pager);
$template->assign('grid_pagination', $pagination);
$template->assign('links', $this->generateLinks());
$response = $this->renderTemplate('list.tpl');
return new Response($response, 200, array());
}
/**
* {@inheritdoc}
*/
protected function generateLinks()
{
return $this->generateDefaultCrudRoutes();
}
protected function generateDefaultCrudRoutes()
{
$className = $this->getControllerAlias();
return
array(
'create_link' => $className.':addAction',
'read_link' => $className.':readAction',
'update_link' => $className.':editAction',
'delete_link' => $className.':deleteAction',
'list_link' => $className.':indexAction'
);
}
public function getLink($action)
{
}
/**
* @Route("/add")
* @Method({"GET"})
*/
public function addAction()
{
$request = $this->getRequest();
$form = $this->createForm($this->getFormType(), $this->getNewEntity());
$form->handleRequest($request);
if ($form->isValid()) {
$item = $form->getData();
$this->createAction($item);
$this->addMessage('Added', 'success');
$url = $this->generateControllerUrl('listingAction');
return $this->redirect($url);
}
$template = $this->getTemplate();
$template->assign('links', $this->generateLinks());
$template->assign('form', $form->createView());
$response = $this->renderTemplate('add.tpl');
return new Response($response, 200, array());
}
/**
*
* @Route("/{id}", requirements={"id" = "\d+"})
* @Method({"GET"})
*/
public function readAction($id)
{
$template = $this->getTemplate();
$template->assign('links', $this->generateLinks());
return $this->readEntity($id);
}
/**
* @Route("/{id}/edit", requirements={"id" = "\d+"})
* @Method({"GET"})
*/
public function editAction($id)
{
$repo = $this->getRepository();
$request = $this->getRequest();
$item = $repo->findOneById($id);
if ($item) {
$form = $this->createForm($this->getFormType(), $item);
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
$this->updateAction($data);
$this->addMessage('Updated', 'success');
$url = $this->generateControllerUrl('listingAction');
return $this->redirect($url);
}
$template = $this->getTemplate();
$template->assign('item', $item);
$template->assign('form', $form->createView());
$template->assign('links', $this->generateLinks());
$response = $this->renderTemplate('edit.tpl');
return new Response($response, 200, array());
} else {
return $this->createNotFoundException();
}
}
/**
* @Route("/{id}/delete", requirements={"id" = "\d+"})
* @Method({"GET"})
*/
public function deleteAction($id)
{
$result = $this->removeEntity($id);
if ($result) {
$url = $this->generateControllerUrl('listingAction');
$this->addMessage('Deleted', 'success');
return $this->redirect($url);
}
}
/**
* @Route("/export/{format}")
* @Method({"GET"})
*/
public function exportAction($format = 'csv')
{
$qb = $this->getRepository()->createQueryBuilder('e');
$query = $qb->getQuery();
$source = new \Exporter\Source\DoctrineORMQuerySourceIterator($query, array('id'));
// Prepare the writer
$writer = new \Exporter\Writer\CsvWriter('data2.csv');
$filename = sprintf('export_%s_%s.%s',
strtolower(substr($this->getClassNameLabel(), strripos($this->getClassNameLabel(), '\\') + 1)),
date('Y_m_d_H_i_s', strtotime('now')),
$format
);
return $this->get('exporter')->getResponse(
$format,
$filename,
$this->getDataSourceIterator()
);
}
public function getDataSourceIterator()
{
}
/**
* Base "read" action.
*
* @param int $id
* @return JsonResponse|NotFoundHttpException
*/
protected function readEntity($id)
{
$entityInstance = $this->getEntityForJson($id);
if (false === $entityInstance) {
return $this->createNotFoundException();
}
return new JsonResponse($entityInstance);
}
/**
* Base "delete" action.
* @param int id
* @return JsonResponse|NotFoundHttpException
*/
protected function removeEntity($id)
{
$object = $this->getEntity($id);
if (false === $object) {
return $this->createNotFoundException();
}
$em = $this->getManager();
$em->remove($object);
$em->flush();
return new JsonResponse(array());
}
/**
* Base "list" action.
* @param string format
* @return JsonResponse
*/
protected function listAction($format = 'json')
{
return $this->getList($format);
}
/**
* @param string $format
* @return JsonResponse
*/
protected function getList($format = 'json')
{
$qb = $this->getRepository()->createQueryBuilder('e');
$list = $qb->getQuery()->getResult(Query::HYDRATE_ARRAY);
switch ($format) {
case 'json':
return new JsonResponse($list);
break;
default:
return $list;
break;
}
}
/**
* Base "read" action.
*
* @param int $id
* @param string format
*
* @return JsonResponse|NotFoundHttpException
*/
protected function readActionByFormat($id, $format = 'array')
{
$entityInstance = $this->getEntityForJson($id);
if (false === $entityInstance) {
return $this->createNotFoundException();
}
switch($format) {
case 'json':
return new JsonResponse($entityInstance);
case 'array':
return $entityInstance;
}
return $entityInstance;
}
/**
* Base "create" action.
* @param stdClass $object
*
* @throws \Exception
*/
protected function createAction($object)
{
if (false === $object) {
throw new \Exception('Unable to create the entity');
}
$em = $this->getManager();
$em->persist($object);
$em->flush();
}
/**
* Base "upload" action.
* @param int id
* @return JsonResponse|NotFoundHttpException
*/
protected function updateAction($object)
{
if (false === $object) {
return $this->createNotFoundException();
}
$this->getManager()->flush($object);
}
/**
* Returns an entity from its ID, or FALSE in case of error.
*
* @param int $id
* @return Object|boolean
*/
protected function getEntity($id)
{
try {
return $this->getRepository()->find($id);
} catch (NoResultException $ex) {
return false;
}
return false;
}
// json actions
/**
* Base "create" action.
*
* @return JsonResponse|NotFoundHttpException
*/
protected function createJsonAction()
{
$json = $this->getJsonDataFromRequest();
if (false === $json) {
throw new \Exception('Invalid JSON');
}
$object = $this->updateEntity($this->getNewEntity(), $json);
if (false === $object) {
throw new \Exception('Unable to create the entity');
}
$em = $this->getManager();
$em->persist($object);
$em->flush();
return new JsonResponse($this->getEntityForJson($object->getId()));
}
/**
* Returns an entity from its ID as an associative array, false in error.
*
* @param int $id
* @return array|boolean
*/
protected function getEntityForJson($id)
{
try {
return $this->getRepository()->createQueryBuilder('e')
->where('e.id = :id')
->setParameter('id', $id)
->getQuery()
->getSingleResult(Query::HYDRATE_ARRAY);
} catch (NoResultException $ex) {
return false;
}
return false;
}
/**
* Returns the request's JSON content, or FALSE in case of error.
*
* @return string|boolean
*/
protected function getJsonDataFromRequest()
{
$data = $this->getRequest()->getContent();
if (!$data) {
return false;
}
return $data;
}
/**
* Base "upload" action.
* @param int id
* @return JsonResponse|NotFoundHttpException
*/
protected function updateJsonAction($id, $data)
{
$object = $this->getEntity($id);
if (false === $object) {
return $this->createNotFoundException();
}
$json = $this->getJsonDataFromRequest();
if (false === $json) {
throw new \Exception('Invalid JSON');
}
if (false === $this->updateEntity($object, $json)) {
throw new \Exception('Unable to update the entity');
}
$this->getManager()->flush($object);
return new JsonResponse($this->getEntityForJson($object->getId()));
}
/**
* Updates an entity with data from a JSON string.
* Returns the entity, or FALSE in case of error.
*
* @param Object $entity
* @param string $data
* @return Object|boolean
*/
protected function updateEntity($entity, $data)
{
$data = json_decode($data, true);
if ($data == null) {
return false;
}
foreach ($data as $name => $value) {
if ($name != 'id') {
$setter = 'set'.ucfirst($name);
if (method_exists($entity, $setter)) {
call_user_func_array(array($entity, $setter), array($value));
}
}
}
return $entity;
}
}

@ -1,37 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\CoreBundle\Controller;
/**
* Interface CrudControllerInterface
* @package ChamiloLMS\CoreBundle\Controller
*/
interface CrudControllerInterface
{
/**
* Returns the entity class example: 'ChamiloLMS\CoreBundle\Entity\Role'
* @return string
*/
public function getClass();
/**
* Returns the form type name example: 'ChamiloLMS\CoreBundle\Form\RoleType'
* @return string
*/
public function getType();
/**
* Returns the controller alias loaded in the routes ex : 'role.controller'
* @return string
*/
public function getControllerAlias();
/**
* Returns the path of the templates located in
* src/ChamiloLMS/Resources/views/default
* example : admin/administrator/role/
* @return string
*/
public function getTemplatePath();
}

@ -1,34 +0,0 @@
<?php
namespace ChamiloLMS\CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContextInterface;
class SecurityController extends Controller
{
public function loginAction(Request $request)
{
$session = $request->getSession();
// get the login error if there is one
if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(
SecurityContextInterface::AUTHENTICATION_ERROR
);
} else {
$error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR);
$session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
}
return $this->render(
'ChamiloLMSCoreBundle:Security:login.html.twig',
array(
// last username entered by the user
'last_username' => $session->get(SecurityContextInterface::LAST_USERNAME),
'error' => $error,
)
);
}
}

@ -1,100 +0,0 @@
<?php
namespace ChamiloLMS\CoreBundle\Listener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\DependencyInjection\ContainerInterface;
use \ChamiloSession as Session;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
class LegacyListener
{
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function onKernelRequest(GetResponseEvent $event)
{
$kernel = $event->getKernel();
$request = $event->getRequest();
$container = $this->container;
// Loading legacy variables
Session::setSession($request->getSession());
$dbConnection = $this->container->get('database_connection');
$database = new \Database($dbConnection, array());
\Database::setManager($this->container->get('doctrine')->getManager());
Session::$urlGenerator = $this->container->get('router');
Session::$security = $this->container->get('security.context');
Session::$translator = $this->container->get('translator');
Session::$rootDir = $this->container->get('kernel')->getRealRootDir();
Session::$logDir = $this->container->get('kernel')->getLogDir();
Session::$dataDir = $this->container->get('kernel')->getDataDir();
Session::$tempDir = $this->container->get('kernel')->getCacheDir();
Session::$courseDir = $this->container->get('kernel')->getDataDir();
Session::$configDir = $this->container->get('kernel')->getConfigDir();
// Injecting course in twig
$courseCode = $request->get('code');
if (empty($courseCode)) {
$courseCodeFromRequest = $request->get('cidReq');
$courseCode = $courseCodeFromRequest;
}
if (!empty($courseCode)) {
$em = $this->container->get('doctrine')->getManager();
$course = $em->getRepository('ChamiloLMSCoreBundle:Course')->findOneByCode($courseCode);
$this->container->get('twig')->addGlobal('course', $course);
$request->getSession()->set('_real_cid', $course->getId());
$request->getSession()->set('_cid', $course->getCode());
$courseInfo = api_get_course_info($course->getCode());
$request->getSession()->set('_course', $courseInfo);
}
// Loading portal settings from DB.
$settingsRefreshInfo = api_get_settings_params_simple(array('variable = ?' => 'settings_latest_update'));
$settingsLatestUpdate = $settingsRefreshInfo ? $settingsRefreshInfo['selected_value'] : null;
$settings = Session::read('_setting');
if (empty($settings)) {
api_set_settings_and_plugins();
} else {
if (isset($settings['settings_latest_update']) && $settings['settings_latest_update'] != $settingsLatestUpdate) {
api_set_settings_and_plugins();
}
}
}
public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
$request = $event->getRequest();
$kernel = $event->getKernel();
$container = $this->container;
/*switch ($request->query->get('option')) {
case 2:
$response->setContent('Blah');
break;
case 3:
$response->headers->setCookie(new Cookie('test', 1));
break;
}*/
}
public function onKernelController(FilterControllerEvent $event)
{
}
}

@ -1,139 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\CoreBundle\Listener;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use ChamiloLMS\CoreBundle\Entity\User;
/**
* Class LoginSuccessHandler
*/
class LoginSuccessHandler implements AuthenticationSuccessHandlerInterface
{
protected $router;
protected $security;
/**
* @param Router $urlGenerator
* @param SecurityContext $security
*/
public function __construct($dbConnection, Router $urlGenerator, SecurityContext $security)
{
//$dbConnection = $this->container->get('database_connection');
$database = new \Database($dbConnection, array());
$this->router = $urlGenerator;
$this->security = $security;
}
/**
* @param Request $request
* @param TokenInterface $token
* @return null|RedirectResponse|\Symfony\Component\Security\Http\Authentication\Response
*/
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
/** @var User $user */
$user = $token->getUser();
$userId = $user->getUserId();
$session = $request->getSession();
\ChamiloSession::setSession($session);
\ChamiloSession::$urlGenerator = $this->router;
event_login($user);
$userInfo = api_get_user_info($user->getUserId());
$userInfo['is_anonymous'] = false;
$request->getSession()->set('_user', $userInfo);
// Setting admin permissions.
if ($this->security->isGranted('ROLE_ADMIN')) {
$request->getSession()->set('is_platformAdmin', true);
}
// Setting teachers permissions.
if ($this->security->isGranted('ROLE_TEACHER')) {
$request->getSession()->set('is_allowedCreateCourse', true);
}
// Setting last login datetime
$session->set('user_last_login_datetime', api_get_utc_datetime());
$response = null;
/* Possible values: index.php, user_portal.php, main/auth/courses.php */
$pageAfterLogin = api_get_setting('page_after_login');
$url = null;
if ($this->security->isGranted('ROLE_STUDENT') && !empty($pageAfterLogin)) {
switch ($pageAfterLogin) {
case 'index.php':
$url = $this->router->generate('index');
break;
case 'user_portal.php':
$url = $this->router->generate('userportal');
break;
case 'main/auth/courses.php':
$url = api_get_path(WEB_PUBLIC_PATH).$pageAfterLogin;
break;
}
}
// Redirecting to a course or a session
if (api_get_setting('go_to_course_after_login') == 'true') {
// Get the courses list
$personal_course_list = \UserManager::get_personal_session_course_list($userId);
$my_session_list = array();
$count_of_courses_no_sessions = 0;
$count_of_courses_with_sessions = 0;
foreach ($personal_course_list as $course) {
if (!empty($course['session_id'])) {
$my_session_list[$course['session_id']] = true;
$count_of_courses_with_sessions++;
} else {
$count_of_courses_no_sessions++;
}
}
$count_of_sessions = count($my_session_list);
if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) {
$key = array_keys($personal_course_list);
$course_info = $personal_course_list[$key[0]]['course_info'];
$id_session = isset($course_info['session_id']) ? $course_info['session_id'] : 0;
$url = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/index.php?id_session='.$id_session;
}
if ($count_of_sessions == 0 && $count_of_courses_no_sessions == 1) {
$key = array_keys($personal_course_list);
$course_info = $personal_course_list[$key[0]]['course_info'];
$url = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/index.php?id_session=0';
}
}
if (!empty($url)) {
$response = new RedirectResponse($url);
}
// Redirect the user to where they were before the login process begun.
if (empty($response)) {
$refererUrl = $request->headers->get('referer');
$response = new RedirectResponse($refererUrl);
}
return $response;
}
}

@ -1,49 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\CoreBundle\Listener;
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* Class LogoutSuccessHandler
*/
class LogoutSuccessHandler implements LogoutSuccessHandlerInterface
{
protected $router;
protected $security;
/**
* @param Router $urlGenerator
* @param SecurityContext $security
*/
public function __construct($dbConnection, Router $urlGenerator, SecurityContext $security)
{
$database = new \Database($dbConnection, array());
$this->router = $urlGenerator;
$this->security = $security;
}
/**
* @param Request $request
* @return null|RedirectResponse
*/
public function onLogoutSuccess(Request $request)
{
$session = $request->getSession();
\ChamiloSession::setSession($session);
// Chamilo logout
$userId = api_get_user_id();
//\Online::logout($userId, false);
$login = $this->router->generate('index');
$response = new RedirectResponse($login);
return $response;
}
}

@ -1,101 +0,0 @@
<?php
namespace ChamiloLMS\CoreBundle\Menu;
use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
class Builder extends ContainerAware
{
/**
* Top menu left
* @param FactoryInterface $factory
* @param array $options
* @return \Knp\Menu\ItemInterface
*/
public function leftMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$menu->setChildrenAttribute('class', 'nav navbar-nav');
$menu->addChild($this->container->get('translator')->trans('Home'), array('route' => 'root'));
$menu->addChild('Administration', array(
'route' => 'administration'
//'routeParameters' => array('id' => 42)
));
// ... add more children
return $menu;
}
/**
* Top menu right
* @param FactoryInterface $factory
* @param array $options
* @return \Knp\Menu\ItemInterface
*/
public function rightMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$menu->setChildrenAttribute('class', 'nav navbar-nav navbar-right');
$menu->addChild('User');
/* {% if is_granted('IS_AUTHENTICATED_FULLY') == true %}
<li>
<a id="logout_button" class="logout" title="{{ "Logout"|trans }}" href="{{ url('logout') }}" >
<i class="fa fa-power-off"></i>
</a>
</li>
{% endif %}
*/
if ($this->container->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) {
$logoutLink = $menu->addChild('Logout', array('route' => 'logout'));
$logoutLink
->setLinkAttributes(array(
'id' => 'logout_button',
'class' => 'fa fa-power-off'
))
->setAttributes(array(
/*'id' => 'signin',
'class' => 'dropdown'*/
))
;
//$logoutLink->addChild($this->templating->render('ApplicationSonataUserBundle:Security:login_options.html.twig'));
}
return $menu;
}
public function profileMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$security = $this->container->get('security.context');
if ($security->isGranted('IS_AUTHENTICATED_FULLY')) {
$menu->setChildrenAttribute('class', 'nav nav-pills nav-stacked');
$menu->addChild('Inbox', array('route' => 'logout'));
$menu->addChild('Compose', array('route' => 'logout'));
$menu->addChild('Edit', array('route' => 'logout'));
}
return $menu;
}
public function courseMenu(FactoryInterface $factory, array $options)
{
$security = $this->container->get('security.context');
$menu = $factory->createItem('root');
if ($security->isGranted('IS_AUTHENTICATED_FULLY')) {
$menu->setChildrenAttribute('class', 'nav nav-pills nav-stacked');
$menu->addChild('Create course', array('route' => 'logout'));
$menu->addChild('Catalog', array('route' => 'logout'));
$menu->addChild('History', array('route' => 'logout'));
}
return $menu;
}
}
Loading…
Cancel
Save