Adding 23:59:59 as end_date limit see BT#7740

Conflicts:
	main/inc/lib/main_api.lib.php
	main/inc/lib/userportal.lib.php
1.9.x
Julio Montoya 11 years ago committed by Daniel Barreto
parent e62d826dda
commit 3b49ecae7d
  1. 24
      main/inc/lib/main_api.lib.php
  2. 42
      main/inc/lib/userportal.lib.php

@ -1942,7 +1942,6 @@ function api_get_session_visibility($session_id, $course_code = null, $ignore_vi
} }
$now = time(); $now = time();
if (!empty($session_id)) { if (!empty($session_id)) {
$session_id = intval($session_id); $session_id = intval($session_id);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
@ -1975,7 +1974,9 @@ function api_get_session_visibility($session_id, $course_code = null, $ignore_vi
//if date_end is set //if date_end is set
if (!empty($row['date_end']) && $row['date_end'] != '0000-00-00') { if (!empty($row['date_end']) && $row['date_end'] != '0000-00-00') {
// End date finish at midnight.
$row['date_end'] = $row['date_end'].' 23:59:59'; $row['date_end'] = $row['date_end'].' 23:59:59';
// Only if date_start said that it was ok // Only if date_start said that it was ok
if ($visibility == SESSION_AVAILABLE) { if ($visibility == SESSION_AVAILABLE) {
$visibility = $row['visibility']; $visibility = $row['visibility'];
@ -1995,10 +1996,13 @@ function api_get_session_visibility($session_id, $course_code = null, $ignore_vi
$is_coach = api_is_coach($session_id, $course_code); $is_coach = api_is_coach($session_id, $course_code);
if ($is_coach) { if ($is_coach) {
// Test end date.
//Test end date if (isset($row['date_end']) &&
if (isset($row['date_end']) && !empty($row['date_end']) && $row['date_end'] != '0000-00-00' && $row['nb_days_access_after_end'] != '0') { !empty($row['date_end']) &&
$end_date_for_coach = new DateTime($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'].' 23:59:59');
$number_of_days = "P".intval($row['nb_days_access_after_end']).'D'; $number_of_days = "P".intval($row['nb_days_access_after_end']).'D';
$end_date_for_coach->add(new DateInterval($number_of_days)); $end_date_for_coach->add(new DateInterval($number_of_days));
@ -2009,9 +2013,13 @@ function api_get_session_visibility($session_id, $course_code = null, $ignore_vi
} }
} }
//Test start date // Test start date.
if (isset($row['date_start']) && !empty($row['date_start']) && $row['date_start'] != '0000-00-00' && $row['nb_days_access_before_beginning'] != '0') { if (isset($row['date_start']) &&
$start_date_for_coach = new DateTime($row['date_start']); !empty($row['date_start']) &&
$row['date_start'] != '0000-00-00' &&
$row['nb_days_access_before_beginning'] != '0'
) {
$start_date_for_coach = new DateTime($row['date_start'].' 00:00:00');
$number_of_days = "P".intval($row['nb_days_access_before_beginning']).'D'; $number_of_days = "P".intval($row['nb_days_access_before_beginning']).'D';
$start_date_for_coach->sub(new DateInterval($number_of_days)); $start_date_for_coach->sub(new DateInterval($number_of_days));
if ($start_date_for_coach->getTimestamp() < $now) { if ($start_date_for_coach->getTimestamp() < $now) {

@ -990,9 +990,10 @@ class IndexManager {
// Courses inside the current session. // Courses inside the current session.
$date_session_start = $session['date_start']; $date_session_start = $session['date_start'];
$date_session_end = $session['date_end'];
$days_access_before_beginning = $session['nb_days_access_before_beginning']; $days_access_before_beginning = $session['nb_days_access_before_beginning'];
$days_access_after_end = $session['nb_days_access_after_end']; $days_access_after_end = $session['nb_days_access_after_end'];
$date_session_end = $session['date_end'];
$session_now = time(); $session_now = time();
$count_courses_session = 0; $count_courses_session = 0;
@ -1003,18 +1004,23 @@ class IndexManager {
$allowed_time = 0; $allowed_time = 0;
$dif_time_after = 0; $dif_time_after = 0;
if ($date_session_start != '0000-00-00') { if ($date_session_start != '0000-00-00') {
if ($is_coach_course) { if ($is_coach_course && !isset($_GET['history'])) {
$allowed_time = api_strtotime($date_session_start) - ($days_access_before_beginning*86400); $allowed_time = api_strtotime($date_session_start.' 00:00:00') - ($days_access_before_beginning * 86400);
if ($session_now > $date_session_end) { if ($date_session_end != '0000-00-00') {
$dif_time_after = $session_now - api_strtotime($date_session_end); $endSessionToTms = api_strtotime($date_session_end.' 23:59:59');
$dif_time_after = round($dif_time_after/86400); if ($session_now > $endSessionToTms) {
$dif_time_after = $session_now - $endSessionToTms;
$dif_time_after = round($dif_time_after/86400);
}
} }
} else { } else {
$allowed_time = api_strtotime($date_session_start); $allowed_time = api_strtotime($date_session_start.' 00:00:00');
} }
} }
if ($session_now > $allowed_time && $days_access_after_end >= $dif_time_after-1) {
//read only and accesible if ($session_now > $allowed_time && $days_access_after_end > $dif_time_after - 1) {
// Read only and accessible.
if (api_get_setting('hide_courses_in_sessions') == 'false') { if (api_get_setting('hide_courses_in_sessions') == 'false') {
$c = CourseManager::get_logged_user_course_html($course, $session_id, 'session_course_item', true, $this->load_directories_preview); $c = CourseManager::get_logged_user_course_html($course, $session_id, 'session_course_item', true, $this->load_directories_preview);
$html_courses_session .= $c[1]; $html_courses_session .= $c[1];
@ -1073,10 +1079,11 @@ class IndexManager {
if (count($session['courses']) < 1) { if (count($session['courses']) < 1) {
continue; continue;
} }
$date_session_start = $session['date_start']; $date_session_start = $session['date_start'];
$date_session_end = $session['date_end'];
$days_access_before_beginning = $session['nb_days_access_before_beginning']; $days_access_before_beginning = $session['nb_days_access_before_beginning'];
$days_access_after_end = $session['nb_days_access_after_end']; $days_access_after_end = $session['nb_days_access_after_end'];
$date_session_end = $session['date_end'];
$session_now = time(); $session_now = time();
$html_courses_session = ''; $html_courses_session = '';
$count = 0; $count = 0;
@ -1089,19 +1096,20 @@ class IndexManager {
if ($is_coach_course) { if ($is_coach_course) {
// 24 hours = 86400 // 24 hours = 86400
if ($date_session_start != '0000-00-00') { if ($date_session_start != '0000-00-00') {
$allowed_time = api_strtotime($date_session_start) - ($days_access_before_beginning*86400); $allowed_time = api_strtotime($date_session_start.' 00:00:00') - ($days_access_before_beginning*86400);
} }
if ($date_session_end != '0000-00-00') { if ($date_session_end != '0000-00-00') {
if ($session_now > $date_session_end) { $endSessionToTms = api_strtotime($date_session_end.' 23:59:59');
$dif_time_after = $session_now - api_strtotime($date_session_end); if ($session_now > $endSessionToTms) {
$dif_time_after = round($dif_time_after/86400); $dif_time_after = $session_now - $endSessionToTms;
$dif_time_after = round($dif_time_after / 86400);
} }
} }
} else { } else {
$allowed_time = api_strtotime($date_session_start); $allowed_time = api_strtotime($date_session_start.' 00:00:00');
} }
if ($session_now > $allowed_time && $days_access_after_end >= $dif_time_after - 1) { if ($session_now > $allowed_time && $days_access_after_end > $dif_time_after - 1) {
if (api_get_setting('hide_courses_in_sessions') == 'false') { if (api_get_setting('hide_courses_in_sessions') == 'false') {
$c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item'); $c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item');
$html_courses_session .= $c[1]; $html_courses_session .= $c[1];

Loading…
Cancel
Save