Session list with the same origin course - refs BT#8986

1.9.x
Angel Fernando Quiroz Campos 10 years ago
parent 559ffe2aba
commit baf144ed26
  1. 8
      main/coursecopy/copy_course_session_selected.php
  2. 30
      main/inc/lib/sessionmanager.lib.php

@ -112,10 +112,11 @@ function make_select_session_list($name, $sessions, $attr = array())
/**
* Show the form to copy courses
* @global string $returnLink
* @global string $courseCode
*/
function displayForm()
{
global $returnLink;
global $returnLink, $courseCode;
$courseInfo = api_get_course_info();
$sessionId = api_get_session_id();
@ -167,6 +168,11 @@ function displayForm()
if ($session['id'] == $sessionId) {
continue;
}
if (!SessionManager::sessionHasCourse($session['id'], $courseCode)) {
continue;
}
$html .= '<option value="' . $session['id'] . '">' . $session['name'] . '</option>';
}
}

@ -5012,4 +5012,34 @@ class SessionManager
return $sessions;
}
/**
* Check if the course belongs to the session
* @param int $sessionId The session id
* @param string $courseCode The course code
*/
public static function sessionHasCourse($sessionId, $courseCode) {
$sessionId = intval($sessionId);
$courseCode = Database::escape_string($courseCode);
$courseTablee = Database::get_main_table(TABLE_MAIN_COURSE);
$sessionRelCourseTable = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$sql = "SELECT COUNT(1) AS qty FROM $courseTablee c "
. "INNER JOIN $sessionRelCourseTable src "
. "ON c.code = src.course_code "
. "WHERE src.id_session = $sessionId "
. "AND c.code = '$courseCode'";
$result = Database::query($sql);
if ($result !== false) {
$data = Database::fetch_assoc($result);
if ($data['qty'] > 0) {
return true;
}
}
return false;
}
}

Loading…
Cancel
Save