Fix "ALL" random question option see BT#14030

pull/2525/head
jmontoyaa 8 years ago
parent 24e2cbb4e3
commit 85d0d4feca
  1. 28
      main/exercise/exercise.class.php
  2. 9
      main/exercise/exercise_submit.php

@ -520,11 +520,12 @@ class Exercise
*
* @author Olivier Brouckaert
*
* @return int - 0 if not random, otherwise the draws
* @return bool
*/
public function isRandom()
{
$isRandom = false;
// "-1" means all questions will be random
if ($this->random > 0 || $this->random == -1) {
$isRandom = true;
}
@ -1047,7 +1048,7 @@ class Exercise
if ($this->random == 0 || $nbQuestions < 2) {
$questionList = $this->getQuestionOrderedList();
} else {
$questionList = $this->selectRandomList($adminView);
$questionList = $this->getRandomList($adminView);
}
break;
default:
@ -1107,22 +1108,29 @@ class Exercise
* @return array - if the exercise is not set to take questions randomly, returns the question list
* without randomizing, otherwise, returns the list with questions selected randomly
*/
public function selectRandomList($adminView = false)
public function getRandomList($adminView = false)
{
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$quizRelQuestion = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$random = isset($this->random) && !empty($this->random) ? $this->random : 0;
// Random with limit
$randomLimit = "ORDER BY RAND() LIMIT $random";
// Random all questions so no limit
if ($random == -1 || $adminView === true) {
// Random with no limit
if ($random == -1) {
$randomLimit = "ORDER BY RAND() ";
}
// Admin see the list in default order
if ($adminView === true) {
// If viewing it as admin for edition, don't show it randomly, use title + id
$randomLimit = 'ORDER BY e.question_order';
}
$sql = "SELECT e.question_id
FROM $TBL_EXERCISE_QUESTION e
INNER JOIN $TBL_QUESTIONS q
FROM $quizRelQuestion e
INNER JOIN $question q
ON (e.question_id= q.id AND e.c_id = q.c_id)
WHERE
e.c_id = {$this->course_id} AND
@ -6452,7 +6460,7 @@ class Exercise
$isRandomByCategory = $this->isRandomByCat();
if ($isRandomByCategory == 0) {
if ($this->isRandom()) {
$result = $this->selectRandomList();
$result = $this->getRandomList();
} else {
$result = $this->selectQuestionList();
}

@ -491,7 +491,10 @@ if ($time_control) {
if ($debug) {
error_log('7.1. Time control is enabled');
error_log('7.2. $current_expired_time_key '.$current_expired_time_key);
error_log('7.3. $_SESSION[expired_time][$current_expired_time_key] '.$_SESSION['expired_time'][$current_expired_time_key]);
error_log(
'7.3. $_SESSION[expired_time][$current_expired_time_key] '.
$_SESSION['expired_time'][$current_expired_time_key]
);
}
if (!isset($_SESSION['expired_time'][$current_expired_time_key])) {
@ -510,7 +513,9 @@ if ($time_control) {
the track_et_attempt see #2069 */
if (empty($last_attempt_date)) {
$diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC');
$last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'], 'UTC') + $diff);
$last_attempt_date = api_get_utc_datetime(
api_strtotime($exercise_stat_info['start_date'], 'UTC') + $diff
);
} else {
//Recalculate the time control due #2069
$diff = $current_timestamp - api_strtotime($last_attempt_date, 'UTC');

Loading…
Cancel
Save