Changing the is_visible return value + fixing the api_strtotime() function in order to use the UTC value

skala
Julio Montoya 13 years ago
parent f822e12f70
commit ac34227908
  1. 13
      main/exercice/exercice.php
  2. 76
      main/exercice/exercise.class.php
  3. 4
      main/exercice/exercise.lib.php
  4. 19
      main/exercice/exercise_submit.php
  5. 13
      main/exercice/overview.php
  6. 6
      main/inc/lib/tracking.lib.php
  7. 5
      main/session/index.php

@ -460,7 +460,8 @@ if (!empty($exercise_list)) {
$time_limits = false;
if ($row['start_time'] != '0000-00-00 00:00:00' || $row['end_time'] != '0000-00-00 00:00:00') {
$time_limits = true;
}
}
if ($time_limits) {
// check if start time
$start_time = false;
@ -471,12 +472,12 @@ if (!empty($exercise_list)) {
if ($row['end_time'] != '0000-00-00 00:00:00') {
$end_time = api_strtotime($row['end_time'],'UTC');
}
$now = time();
$now = time();
$is_actived_time = false;
//If both "clocks" are enable
if ($start_time && $end_time) {
if ($now > $start_time && $end_time > $now ) {
if ($now > $start_time && $end_time > $now ) {
$is_actived_time = true;
}
} else {
@ -493,8 +494,7 @@ if (!empty($exercise_list)) {
}
}
}
//Blocking empty start times see BT#2800
global $_custom;
if (isset($_custom['exercises_hidden_when_no_start_date']) && $_custom['exercises_hidden_when_no_start_date']) {
@ -629,6 +629,7 @@ if (!empty($exercise_list)) {
// --- Student only
// if time is actived show link to exercise
if ($time_limits) {
if ($is_actived_time) {
$url = '<a '.$alt_title.' href="overview.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'">'.$cut_title.'</a>';
@ -691,6 +692,8 @@ if (!empty($exercise_list)) {
}
} else {
//Quiz not ready due to time limits
//@todo use the is_visible function
if ($row['start_time'] != '0000-00-00 00:00:00' && $row['end_time'] != '0000-00-00 00:00:00') {
$attempt_text = sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
} else {

@ -130,10 +130,10 @@ class Exercise {
$this->review_answers = (isset($object->review_answers) && $object->review_answers == 1) ? true : false;
if ($object->end_time != '0000-00-00 00:00:00') {
$this->end_time = api_get_local_time($object->end_time);
$this->end_time = $object->end_time;
}
if ($object->start_time != '0000-00-00 00:00:00') {
$this->start_time = api_get_local_time($object->start_time);
$this->start_time = $object->start_time;
}
$this->expired_time = $object->expired_time; //control time
@ -1121,12 +1121,12 @@ class Exercise {
$defaults['display_category_name'] = $this->selectDisplayCategoryName(); //
if (($this->start_time!='0000-00-00 00:00:00'))
$defaults['activate_start_date_check'] = 1;
$defaults['activate_start_date_check'] = 1;
if ($this->end_time!='0000-00-00 00:00:00')
$defaults['activate_end_date_check'] = 1;
$defaults['activate_end_date_check'] = 1;
$defaults['start_time'] = ($this->start_time!='0000-00-00 00:00:00')? $this->start_time : date('Y-m-d 12:00:00');
$defaults['end_time'] = ($this->end_time!='0000-00-00 00:00:00')?$this->end_time : date('Y-m-d 12:00:00',time()+84600);
$defaults['start_time'] = ($this->start_time!='0000-00-00 00:00:00') ? $this->start_time : date('Y-m-d 12:00:00');
$defaults['end_time'] = ($this->end_time!='0000-00-00 00:00:00') ? $this->end_time : date('Y-m-d 12:00:00',time()+84600);
//Get expired time
if($this->expired_time != '0') {
@ -3290,58 +3290,60 @@ class Exercise {
public function is_visible($lp_id = 0, $lp_item_id = 0 , $lp_item_view_id = 0) {
//1. By default the exercise is visible
$is_visible = true;
$is_visible = true;
//1.1 Admins and teachers can access to the exercise
if (api_is_platform_admin() || api_is_course_admin()) {
$is_visible = true;
return array('value' => true, 'message' => '');
}
//2. If the exercise is not active
if ($this->active == 0) {
return false;
}
return array('value' => false, 'message' => Display::return_message(get_lang('ExerciseNotAvailable'), 'warning', false));
}
//3. We check if the time limits are on
$limit_time_exists = ((!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') || (!empty($this->end_time) && $this->end_time != '0000-00-00 00:00:00')) ? true : false;
if ($limit_time_exists) {
$time_now = time();
//Do not add the UTC parameter in the api_strtotime because the $this->start_time was converted in the read() function
$time_now = time();
if (!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') {
$permission_to_start = (($time_now - api_strtotime($this->start_time)) > 0) ? true : false;
} else {
$permission_to_start = true;
}
if ($this->end_time != '0000-00-00 00:00:00') {
$exercise_timeover = (($time_now - api_strtotime($this->end_time)) > 0) ? true : false;
} else {
$exercise_timeover = false;
}
if (!$permission_to_start || $exercise_timeover) {
$is_visible = false;
}
$is_visible = (($time_now - api_strtotime($this->start_time, 'UTC')) > 0) ? true : false;
}
if ($is_visible == false) {
$message = sprintf(get_lang('ExerciseAvailableFromX'), api_convert_and_format_date($this->start_time));
}
if ($is_visible == true) {
if ($this->end_time != '0000-00-00 00:00:00') {
$is_visible = ((api_strtotime($this->end_time, 'UTC') > $time_now) > 0) ? true : false;
if ($is_visible == false) {
$message = sprintf(get_lang('ExerciseAvailableUntilX'), api_convert_and_format_date($this->end_time));
}
}
}
if ($is_visible == false && $this->start_time != '0000-00-00 00:00:00' && $this->end_time != '0000-00-00 00:00:00') {
$message = sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($this->start_time), api_convert_and_format_date($this->end_time));
}
}
// 4. We check if the student have attempts
if ($is_visible) {
if ($this->selectAttempts()) {
if ($this->selectAttempts() > 0) {
$attempt_count = get_attempt_count_not_finished(api_get_user_id(), $this->id, $lp_id, $lp_item_id, $lp_item_view_id);
if ($attempt_count >= $this->selectAttempts()) {
//Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exerciseTitle, $objExercise->selectAttempts()), false);
if ($attempt_count >= $this->selectAttempts()) {
$message = sprintf(get_lang('ReachedMaxAttempts'), $this->name, $this->selectAttempts());
$is_visible = false;
}
}
}
return $is_visible;
if (!empty($message)){
$message = Display :: return_message($message, 'warning', false);
}
return array('value' => $is_visible, 'message' => $message);
}
function save_attempt() {
@ -3499,6 +3501,6 @@ class Exercise {
}
}
return $result;
}
}
}
endif;

@ -1023,8 +1023,8 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
}
if ($start_date != "0000-00-00 00:00:00") {
$start_date_timestamp = api_strtotime($start_date);
$exe_date_timestamp = api_strtotime($results[$i]['exe_date']);
$start_date_timestamp = api_strtotime($start_date, 'UTC');
$exe_date_timestamp = api_strtotime($results[$i]['exe_date'], 'UTC');
$my_duration = ceil((($exe_date_timestamp - $start_date_timestamp) / 60));
//var_dump($start_date .' - '.$results[$i]['exdate'].' - '.$my_duration);

@ -230,7 +230,6 @@ if ($debug) { error_log("4. Setting the exe_id $exe_id");} ;
//var_dump($safe_lp_id.' - '.$safe_lp_item_id.' - '.$safe_lp_item_view_id);
$exercise_stat_info = $objExercise->get_stat_track_exercise_info($safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id);
if (empty($exercise_stat_info)) {
$total_weight = 0;
$questionList = $objExercise->get_validated_question_list();
@ -638,19 +637,27 @@ if (!empty($exercise_description)) {
}
echo Display::div($exercise_header, array('class'=>'exercise_header'));*/
$is_visible_return = $objExercise->is_visible($learnpath_id, $learnpath_item_id, $learnpath_item_view_id);
if ($is_visible_return['value'] == false) {
echo $is_visible_return['message'];
if ($origin != 'learnpath') {
Display :: display_footer();
}
exit;
}
$limit_time_exists = (($objExercise->start_time != '0000-00-00 00:00:00') || ($objExercise->end_time != '0000-00-00 00:00:00')) ? true : false;
if ($limit_time_exists) {
$exercise_start_time = api_strtotime($objExercise->start_time,'UTC');
$exercise_end_time = api_strtotime($objExercise->end_time,'UTC');
if ($limit_time_exists) {
$exercise_start_time = api_strtotime($objExercise->start_time, 'UTC');
$exercise_end_time = api_strtotime($objExercise->end_time, 'UTC');
$time_now = time();
if ($objExercise->start_time != '0000-00-00 00:00:00') {
$permission_to_start = (($time_now - $exercise_start_time) > 0) ? true : false;
} else {
$permission_to_start = true;
}
}
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
if ($objExercise->end_time != '0000-00-00 00:00:00') {
$exercise_timeover = (($time_now - $exercise_end_time) > 0) ? true : false;
@ -1043,4 +1050,4 @@ if ($origin != 'learnpath') {
Display :: display_footer();
} else {
echo '</body></html>';
}
}

@ -90,17 +90,16 @@ if (!empty($attempt_list)) {
$html .= $message;
$exercise_url_button = Display::url($label, $exercise_url, array('class'=>'a_button blue bigger round'));
if (!$objExercise->is_visible($learnpath_id, $learnpath_item_id)) {
$visible_return = $objExercise->is_visible($learnpath_id, $learnpath_item_id);
if ($visible_return['value'] == false) {
$exercise_url = api_get_path(WEB_CODE_PATH).'exercice/exercise_report.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id;
//$exercise_url_button = Display::url(get_lang('SeeResults'), $exercise_url, array('class'=>'a_button white bigger round no_link'));
if ($origin == 'learnpath') {
$exercise_url_button = Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $objExercise->title, $objExercise->selectAttempts()), 'warning');
}
$exercise_url_button = sprintf(get_lang('ReachedMaxAttempts'), $objExercise->title, $objExercise->selectAttempts());
$exercise_url_button = $visible_return['message'];
}
$options = Display::div('', array('class'=>'left_option'));
if (!empty($exercise_url_button)) {
$options .= Display::div($exercise_url_button, array('class'=>'center_option'));
$options .= $exercise_url_button;
}
$attempts = get_exercise_results_by_user(api_get_user_id(), $objExercise->id, api_get_course_id(), api_get_session_id(), $learnpath_id, $learnpath_item_id, 'desc');

@ -2276,7 +2276,8 @@ class Tracking {
foreach($exercise_list as $exercise_data) {
$exercise_obj = new Exercise($course_data['id']);
$exercise_obj->read($exercise_data['id']);
if ($exercise_obj->is_visible()) {
$visible_return = $exercise_obj->is_visible();
if ($visible_return['value'] == true) {
$best_average = intval(get_best_average_score_by_exercise($exercise_data['id'], $course_data['code'], $my_session_id, $user_count));
$exercise_graph_list[] = $best_average;
$all_exercise_graph_list[] = $best_average;
@ -2606,9 +2607,10 @@ class Tracking {
$exercise_obj = new Exercise($course_info['real_id']);
$exercise_obj->read($exercices['id']);
$visible_return = $exercise_obj->is_visible();
//just in case
if (!$exercise_obj->is_visible()) {
if ($visible_return['value'] == false) {
continue;
}

@ -72,8 +72,9 @@ if (!empty($new_session_list)) {
foreach($exercise_list as $exercise_item) {
//Loading the exercise
$exercise = new Exercise($course_info['real_id']);
$exercise->read($exercise_item['id']);
if ($exercise->is_visible()) {
$exercise->read($exercise_item['id']);
$visible_return = $exercise->is_visible();
if ($visible_return['value'] == false) {
//$exercise_course_list[$exercise_item['id']] = $exercise;
//Reading all Exercise results by user, exercise_id, code, and session
$user_results = get_exercise_results_by_user(api_get_user_id(), $exercise_item['id'], $my_course['code'], $my_session_id);

Loading…
Cancel
Save