Fixing session coach start/end date see #5353

skala
Julio Montoya 12 years ago
parent 1fe55f634c
commit b341bd7624
  1. 41
      main/inc/lib/main_api.lib.php
  2. 48
      main/inc/lib/sessionmanager.lib.php
  3. 23
      main/inc/lib/usermanager.lib.php
  4. 3
      main/newscorm/lp_controller.php

@ -1823,12 +1823,14 @@ function api_get_session_info($session_id) {
* @param int session id
* @return int 0 = session still available, SESSION_VISIBLE_READ_ONLY = 1, SESSION_VISIBLE = 2, SESSION_INVISIBLE = 3
*/
function api_get_session_visibility($session_id) {
function api_get_session_visibility($session_id, $course_code = null, $ignore_visibility_for_admins = true) {
$visibility = 0; //means that the session is still available
if (api_is_platform_admin()) {
return SESSION_AVAILABLE;
}
$now = time();
if (!empty($session_id)) {
$session_id = intval($session_id);
@ -1840,20 +1842,19 @@ function api_get_session_visibility($session_id) {
$result = Database::query($sql);
if (Database::num_rows($result) > 0 ) {
$row = Database::fetch_array($result, 'ASSOC');
$visibility = $row['visibility'];
$row = Database::fetch_array($result, 'ASSOC');
$visibility = $original_visibility = $row['visibility'];
//I don't care the field visibility
if ($row['date_start'] == '0000-00-00' && $row['date_end'] == '0000-00-00') {
return SESSION_AVAILABLE;
} else {
$time = time();
//If datestart is set
if (!empty($row['date_start']) && $row['date_start'] != '0000-00-00') {
$row['date_start'] = $row['date_start'].' 00:00:00';
if ($time > api_strtotime($row['date_start'], 'UTC')) {
if ($now > api_strtotime($row['date_start'], 'UTC')) {
$visibility = SESSION_AVAILABLE;
} else {
$visibility = SESSION_INVISIBLE;
@ -1868,7 +1869,7 @@ function api_get_session_visibility($session_id) {
if ($visibility == SESSION_AVAILABLE) {
$visibility = $row['visibility'];
if ($time < api_strtotime($row['date_end'], 'UTC')) {
if ($now < api_strtotime($row['date_end'], 'UTC')) {
//date still available
$visibility = SESSION_AVAILABLE;
} else {
@ -1879,21 +1880,17 @@ function api_get_session_visibility($session_id) {
}
}
//If I'm a coach the visibility can change in my favor depending in the nb_days_access_after_end and nb_days_access_before_beginning values
$is_coach = api_is_coach($session_id);
//If I'm a coach the visibility can change in my favor depending in the nb_days_access_after_end and nb_days_access_before_beginning values
$is_coach = api_is_coach($session_id, $course_code);
if ($is_coach) {
//Test end date
if (isset($row['date_end']) && !empty($row['date_end']) && $row['date_end'] != '0000-00-00' && $row['nb_days_access_after_end'] != '0') {
$end_date_for_coach = new DateTime($row['date_end']);
$number_of_days = "P".intval($row['nb_days_access_after_end']).'D';
$end_date_for_coach->add(new DateInterval($number_of_days));
$today = new DateTime();
if ($end_date_for_coach >= $today) {
$number_of_days = "P".intval($row['nb_days_access_after_end']).'D';
$end_date_for_coach->add(new DateInterval($number_of_days));
if ($end_date_for_coach->getTimestamp() >= $now) {
$visibility = SESSION_AVAILABLE;
} else {
$visibility = SESSION_INVISIBLE;
@ -1905,9 +1902,7 @@ function api_get_session_visibility($session_id) {
$start_date_for_coach = new DateTime($row['date_start']);
$number_of_days = "P".intval($row['nb_days_access_before_beginning']).'D';
$start_date_for_coach->sub(new DateInterval($number_of_days));
$today = new DateTime();
if ($start_date_for_coach < $today) {
if ($start_date_for_coach->getTimestamp() < $now) {
$visibility = SESSION_AVAILABLE;
} else {
$visibility = SESSION_INVISIBLE;
@ -2256,11 +2251,7 @@ function api_get_user_platform_status($user_id = false) {
* @param string - optional, course code
* @return boolean True if current user is a course or session coach
*/
function api_is_coach($session_id = 0, $course_code = '') {
//@todo Not sure about this one
/*if (api_is_platform_admin()) {
return true;
}*/
function api_is_coach($session_id = 0, $course_code = null) {
if (!empty($session_id)) {
$session_id = intval($session_id);
} else {

@ -228,7 +228,7 @@ class SessionManager {
if (api_is_session_admin() && api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false') {
$where.=" AND s.session_admin_id = $user_id ";
}
}
$coach_name = " CONCAT (u.lastname , ' ', u.firstname) as coach_name ";
@ -237,24 +237,32 @@ class SessionManager {
}
$today = api_get_utc_datetime();
$today = api_strtotime($today, 'UTC');
$today = date('Y-m-d', $today);
$today = api_strtotime($today, 'UTC');
$today = date('Y-m-d', $today);
$select = "SELECT * FROM (SELECT
IF (
(s.date_start <= '$today' AND '$today' < s.date_end) OR
(DATEDIFF(s.date_start,'".$today."' ".") <= s.nb_days_access_before_beginning) OR
(s.date_start = '0000-00-00' AND s.date_end = '0000-00-00' ) OR
(s.date_start <= '$today' AND '0000-00-00' = s.date_end) OR
('$today' < s.date_end AND '0000-00-00' = s.date_start)
, 1, 0)
IF (
(s.date_start <= '$today' AND '$today' < s.date_end) OR
(s.date_start = '0000-00-00' AND s.date_end = '0000-00-00' ) OR
(s.date_start <= '$today' AND '0000-00-00' = s.date_end) OR
('$today' < s.date_end AND '0000-00-00' = s.date_start)
, 1, 0)
as session_active,
s.name, nbr_courses, nbr_users, s.date_start, s.date_end, $coach_name, sc.name as category_name, s.visibility, u.user_id, s.id";
s.name,
nbr_courses,
nbr_users,
s.date_start,
s.date_end,
$coach_name,
sc.name as category_name,
s.visibility,
u.user_id, s.id";
$query = "$select FROM $tbl_session s
LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
INNER JOIN $tbl_user u ON s.id_coach = u.user_id ".
$where;
$where;
global $_configuration;
if ($_configuration['multiple_access_urls']) {
$table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
@ -262,13 +270,13 @@ class SessionManager {
if ($access_url_id != -1) {
$where.= " AND ar.access_url_id = $access_url_id ";
$query = "$select
FROM $tbl_session s
LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
INNER JOIN $tbl_user u ON s.id_coach = u.user_id
INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
$where";
FROM $tbl_session s
LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
INNER JOIN $tbl_user u ON s.id_coach = u.user_id
INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
$where ";
}
}
}
$query .= ") AS session_table";
if (!empty($options['where'])) {

@ -1942,7 +1942,12 @@ class UserManager {
if ($is_time_over) {
$condition_date_end = " AND (session.date_end < '$now' AND session.date_end != '0000-00-00') ";
} else {
$condition_date_end = " AND (session.date_end >= '$now' OR session.date_end = '0000-00-00') ";
if (api_is_allowed_to_create_course()) {
//Teachers can access the session depending in the access_coach date
$condition_date_end = null;
} else {
$condition_date_end = " AND (session.date_end >= '$now' OR session.date_end = '0000-00-00') ";
}
}
//ORDER BY session_category_id, date_start, date_end
@ -1969,7 +1974,21 @@ class UserManager {
$categories[$row['session_category_id']]['session_category']['id'] = $row['session_category_id'];
$categories[$row['session_category_id']]['session_category']['name'] = $row['session_category_name'];
$categories[$row['session_category_id']]['session_category']['date_start'] = $row['session_category_date_start'];
$categories[$row['session_category_id']]['session_category']['date_end'] = $row['session_category_date_end'];
$categories[$row['session_category_id']]['session_category']['date_end'] = $row['session_category_date_end'];
$session_id = $row['id'];
//Checking session visibility
$visibility = api_get_session_visibility($session_id, null, false);
switch ($visibility) {
case SESSION_VISIBLE_READ_ONLY:
case SESSION_VISIBLE:
case SESSION_AVAILABLE:
break;
case SESSION_INVISIBLE:
continue(2);
}
$categories[$row['session_category_id']]['sessions'][$row['id']]['session_name'] = $row['name'];
$categories[$row['session_category_id']]['sessions'][$row['id']]['session_id'] = $row['id'];

@ -913,10 +913,11 @@ switch ($action) {
break;
case 'return_to_course_homepage':
if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
else {
else {
$_SESSION['oLP']->save_current();
$_SESSION['oLP']->save_last();
header('location: '.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/?id_session='.api_get_session_id());
exit;
}
break;
case 'search':

Loading…
Cancel
Save