Add js count down, if quiz extra field "results_available_for_x_minutes"

See BT#15743
pull/2958/head
Julio Montoya 7 years ago
parent b9944096ab
commit 9e5469bf4e
  1. 126
      main/exercise/exercise.class.php
  2. 4
      main/exercise/exercise_reminder.php
  3. 7
      main/exercise/exercise_result.php
  4. 18
      main/exercise/exercise_submit.php
  5. 4
      main/exercise/overview.php
  6. 9
      main/exercise/result.php
  7. 9
      main/inc/lib/exercise.lib.php

@ -3275,17 +3275,79 @@ class Exercise
return $html;
}
/**
* @param int $timeLeft in seconds
* @param string $url
*
* @return string
*/
public function showSimpleTimeControl($timeLeft, $url = '')
{
$timeLeft = (int) $timeLeft;
$url = Security::remove_XSS($url);
return "<script>
function openClockWarning() {
$('#clock_warning').dialog({
modal:true,
height:250,
closeOnEscape: false,
resizable: false,
buttons: {
'".addslashes(get_lang('Close'))."': function() {
$('#clock_warning').dialog('close');
}
},
close: function() {
window.location.href = '$url';
}
});
$('#clock_warning').dialog('open');
$('#counter_to_redirect').epiclock({
mode: $.epiclock.modes.countdown,
offset: {seconds: 5},
format: 's'
}).bind('timer', function () {
window.location.href = '$url';
});
}
function onExpiredTimeExercise() {
$('#wrapper-clock').hide();
$('#expired-message-id').show();
// Fixes bug #5263
$('#num_current_id').attr('value', '".$this->selectNbrQuestions()."');
openClockWarning();
}
$(function() {
// time in seconds when using minutes there are some seconds lost
var time_left = parseInt(".$timeLeft.");
$('#exercise_clock_warning').epiclock({
mode: $.epiclock.modes.countdown,
offset: {seconds: time_left},
format: 'x:i:s',
renderer: 'minute'
}).bind('timer', function () {
onExpiredTimeExercise();
});
$('#submit_save').click(function () {});
});
</script>";
}
/**
* So the time control will work.
*
* @param string $time_left
* @param int $timeLeft
*
* @return string
*/
public function showTimeControlJS($time_left)
public function showTimeControlJS($timeLeft)
{
$time_left = (int) $time_left;
$script = "redirectExerciseToResult();";
$timeLeft = (int) $timeLeft;
$script = 'redirectExerciseToResult();';
if ($this->type == ALL_ON_ONE_PAGE) {
$script = "save_now_all('validate');";
}
@ -3298,7 +3360,7 @@ class Exercise
closeOnEscape: false,
resizable: false,
buttons: {
'".addslashes(get_lang("EndTest"))."': function() {
'".addslashes(get_lang('EndTest'))."': function() {
$('#clock_warning').dialog('close');
}
},
@ -3336,7 +3398,7 @@ class Exercise
$(function() {
// time in seconds when using minutes there are some seconds lost
var time_left = parseInt(".$time_left.");
var time_left = parseInt(".$timeLeft.");
$('#exercise_clock_warning').epiclock({
mode: $.epiclock.modes.countdown,
offset: {seconds: time_left},
@ -3346,7 +3408,7 @@ class Exercise
onExpiredTimeExercise();
});
$('#submit_save').click(function () {});
});
});
</script>";
}
@ -6937,7 +6999,7 @@ class Exercise
/**
* @return string
*/
public function return_time_left_div()
public function returnTimeLeftDiv()
{
$html = '<div id="clock_warning" style="display:none">';
$html .= Display::return_message(
@ -6996,7 +7058,7 @@ class Exercise
if (Database::num_rows($result)) {
$row = Database::fetch_array($result);
return $row['count_questions'];
return (int) $row['count_questions'];
}
}
@ -9409,35 +9471,63 @@ class Exercise
}
}
//$content .= '<div class="table-responsive">';
$content .= $table->return_table();
//$content .= '</div>';
}
return $content;
}
/**
* @param array $exerciseResultInfo
*
* @return bool
* @return int value in minutes
*/
public function hasResultsAccess($exerciseResultInfo)
public function getResultAccess()
{
$extraFieldValue = new ExtraFieldValue('exercise');
$value = $extraFieldValue->get_values_by_handler_and_field_variable(
$this->iId,
'results_available_for_x_minutes'
);
if (!empty($value)) {
return (int) $value;
}
return 0;
}
/**
* @param array $exerciseResultInfo
*
* @return bool
*/
public function getResultAccessTimeDiff($exerciseResultInfo)
{
$value = $this->getResultAccess();
if (!empty($value)) {
$value = (int) $value;
$endDate = new DateTime($exerciseResultInfo['exe_date'], new DateTimeZone('UTC'));
$endDate->add(new DateInterval('PT'.$value.'M'));
if (time() > $endDate->getTimestamp()) {
return false;
$now = time();
if ($endDate->getTimestamp() > $now) {
return (int) $endDate->getTimestamp() - $now;
}
}
return 0;
}
/**
* @param array $exerciseResultInfo
*
* @return bool
*/
public function hasResultsAccess($exerciseResultInfo)
{
$diff = $this->getResultAccessTimeDiff($exerciseResultInfo);
if ($diff === 0) {
return false;
}
return true;
}

@ -131,7 +131,7 @@ if (api_is_course_admin() && !$hideHeaderAndFooter) {
echo Display::page_header(get_lang('QuestionsToReview'));
if ($time_control) {
echo $objExercise->return_time_left_div();
echo $objExercise->returnTimeLeftDiv();
}
echo Display::div('', ['id' => 'message']);
@ -139,7 +139,7 @@ echo '<script>
var lp_data = $.param({"learnpath_id": '.$learnpath_id.', "learnpath_item_id" : '.$learnpath_item_id.', "learnpath_item_view_id": '.$learnpath_item_view_id.'});
function final_submit() {
//Normal inputs
// Normal inputs
window.location = "'.api_get_path(WEB_CODE_PATH).'exercise/exercise_result.php?'.api_get_cidreq().'&exe_id='.$exe_id.'&" + lp_data;
}

@ -78,6 +78,13 @@ if (api_get_configuration_value('quiz_prevent_copy_paste')) {
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery.nocopypaste.js"></script>';
}
if (!empty($objExercise->getResultAccess())) {
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
$htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
$htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
$htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
}
if (!in_array($origin, ['learnpath', 'embeddable'])) {
// So we are not in learnpath tool
Display::display_header($nameTools, get_lang('Exercise'));

@ -575,10 +575,6 @@ if ($time_control) {
} else {
$clock_expired_time = $_SESSION['expired_time'][$current_expired_time_key];
}
} else {
if ($debug) {
error_log("7 No time control");
}
}
// Get time left for expiring time
@ -755,10 +751,6 @@ if ($formSent && isset($_POST)) {
if ($debug) {
error_log('11. $formSent was set - end');
}
} else {
if ($debug) {
error_log('9. $formSent was NOT sent');
}
}
// If questionNum comes from POST and not from GET
@ -845,7 +837,7 @@ if ($question_count != 0) {
$error = get_lang('ThereAreNoQuestionsForThisExercise');
// if we are in the case where user select random by category, but didn't choose the number of random question
if ($objExercise->getRandomByCategory() > 0 && $objExercise->random <= 0) {
$error .= "<br/>".get_lang('PleaseSelectSomeRandomQuestion');
$error .= '<br/>'.get_lang('PleaseSelectSomeRandomQuestion');
}
}
@ -857,10 +849,10 @@ if (api_is_in_gradebook()) {
}
$interbreadcrumb[] = [
"url" => "exercise.php?".api_get_cidreq(),
"name" => get_lang('Exercises'),
'url' => 'exercise.php?'.api_get_cidreq(),
'name' => get_lang('Exercises'),
];
$interbreadcrumb[] = ["url" => "#", "name" => $objExercise->selectTitle(true)];
$interbreadcrumb[] = ['url' => '#', 'name' => $objExercise->selectTitle(true)];
if (!in_array($origin, ['learnpath', 'embeddable'])) { //so we are not in learnpath tool
if (!api_is_allowed_to_session_edit()) {
@ -976,7 +968,7 @@ if (isset($_custom['exercises_hidden_when_no_start_date']) &&
// Timer control
if ($time_control) {
echo $objExercise->return_time_left_div();
echo $objExercise->returnTimeLeftDiv();
echo '<div style="display:none" class="warning-message" id="expired-message-id">'.
get_lang('ExerciseExpiredTimeMessage').'</div>';
}

@ -29,7 +29,7 @@ $htmlHeadXtra[] = $js;
api_protect_course_script(true);
$sessionId = api_get_session_id();
$courseCode = api_get_course_id();
$exercise_id = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
$exercise_id = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : 0;
$objExercise = new Exercise();
$result = $objExercise->read($exercise_id, true);
@ -404,7 +404,7 @@ if ($objExercise->selectAttempts()) {
}
if ($time_control) {
$html .= $objExercise->return_time_left_div();
$html .= $objExercise->returnTimeLeftDiv();
}
$html .= $message;

@ -10,7 +10,7 @@ use ChamiloSession as Session;
*/
require_once __DIR__.'/../inc/global.inc.php';
$id = isset($_REQUEST['id']) ? (int) $_GET['id'] : null; //exe id
$id = isset($_REQUEST['id']) ? (int) $_GET['id'] : 0; // exe id
$show_headers = isset($_REQUEST['show_headers']) ? (int) $_REQUEST['show_headers'] : null;
$origin = api_get_origin();
@ -58,6 +58,13 @@ $htmlHeadXtra[] = '<link rel="stylesheet" href="'.api_get_path(WEB_LIBRARY_JS_PA
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'hotspot/js/hotspot.js"></script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'annotation/js/annotation.js"></script>';
if (!empty($objExercise->getResultAccess())) {
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
$htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
$htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
$htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
}
if ($show_headers) {
$interbreadcrumb[] = [
'url' => 'exercise.php?'.api_get_cidreq(),

@ -4388,7 +4388,6 @@ EOT;
) {
$origin = api_get_origin();
$courseCode = api_get_course_id();
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
// Getting attempt info
@ -4421,6 +4420,14 @@ EOT;
return false;
}
if (!empty($objExercise->getResultAccess())) {
echo $objExercise->returnTimeLeftDiv();
echo $objExercise->showSimpleTimeControl(
$objExercise->getResultAccessTimeDiff($exercise_stat_info),
api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id
);
}
$counter = 1;
$total_score = $total_weight = 0;
$exercise_content = null;

Loading…
Cancel
Save