From debe8d15ea4a100f2cb502fb6552e0f416a22b7e Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 17 Aug 2015 16:42:54 -0500 Subject: [PATCH] Redirect when session has one course only - refs BT#10175 --- main/session/index.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/main/session/index.php b/main/session/index.php index 7a816b8dc8..273e50770d 100755 --- a/main/session/index.php +++ b/main/session/index.php @@ -11,6 +11,11 @@ use ChamiloSession as Session; $cidReset = true; require_once '../inc/global.inc.php'; + +if (empty($_GET['session_id'])) { + api_not_allowed(); +} + $session_id = isset($_GET['session_id']) ? intval($_GET['session_id']): null; $sessionField = new ExtraFieldValue('session'); @@ -26,10 +31,6 @@ if (!$allowVisitors) { $this_section = SECTION_COURSES; $htmlHeadXtra[] = api_get_jqgrid_js(); -if (empty($_GET['session_id'])) { - api_not_allowed(); -} - $course_id = isset($_GET['course_id']) ? intval($_GET['course_id']) : null; $_SESSION['id_session'] = $session_id; @@ -235,6 +236,25 @@ if (!api_is_allowed_to_session_edit()) { api_not_allowed(); } +$entityManager = Database::getManager(); +$session = $entityManager->find('ChamiloCoreBundle:Session', $session_id); + +if (!empty($session)) { + $sessionCourses = $session->getCourses(); + + if (count($sessionCourses) === 1) { + $sessionCourse = $sessionCourses[0]->getCourse(); + + $courseUrl = $sessionCourse->getDirectory() . '/index.php?'; + $courseUrl .= http_build_query([ + 'session_id' => $session->getId() + ]); + + header('Location: ' . api_get_path(WEB_COURSE_PATH) . $courseUrl); + exit; + } +} + Display::display_header(get_lang('Session')); $session_select = array();