diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index e5d1be3b4e..cf1710dfc5 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -49,7 +49,7 @@ class Exercise public $feedback_type; public $end_time; public $start_time; - public $questionList; // array with the list of this exercise's questions + public $questionList; public $results_disabled; public $expired_time; public $course; @@ -558,6 +558,7 @@ class Exercise } /** + * Get question count per exercise from DB (any special treatment) * @return int */ public function getQuestionCount() @@ -636,7 +637,8 @@ class Exercise * Select N values from the questions per category array * @param array $question_list * @param array $questions_by_category per category - * @param int custom N value + * @param array + * @param bool flat result * @return array */ private function pickQuestionsPerCategory($question_list, $questions_by_category, $categoryCountArray = array(), $flatResult = true) @@ -685,7 +687,7 @@ class Exercise * Selecting question list depending in the exercise-category * relationship (category table in exercise settings) * - * @param $question_list + * @param array $question_list * @return array */ public function getQuestionListWithCategoryListFilteredByCategorySettings($question_list) @@ -826,7 +828,7 @@ class Exercise } /** - * Returns the array with the question ID list ordered by question order, + * Returns the array with the question ID list ordered by question order (with the uncompressed media list) * * @author Olivier Brouckaert * @param bool $from_db @@ -918,7 +920,7 @@ class Exercise * * @return boolean - true if in the list, otherwise false */ - function isInList($questionId) + public function isInList($questionId) { if (is_array($this->questionList)) { return in_array($questionId, $this->questionList); @@ -933,7 +935,7 @@ class Exercise * @author - Olivier Brouckaert * @param - string $title - exercise title */ - function updateTitle($title) + public function updateTitle($title) { $this->exercise = $title; } @@ -943,12 +945,12 @@ class Exercise * * @param - numeric $attempts - exercise max attempts */ - function updateAttempts($attempts) + public function updateAttempts($attempts) { $this->attempts = $attempts; } - function updateActive($active) + public function updateActive($active) { $this->active = $active; } @@ -958,7 +960,7 @@ class Exercise * * @param - numeric $attempts - exercise max attempts */ - function updateFeedbackType($feedback_type) + public function updateFeedbackType($feedback_type) { $this->feedback_type = $feedback_type; } @@ -969,7 +971,7 @@ class Exercise * @author - Olivier Brouckaert * @param - string $description - exercise description */ - function updateDescription($description) + public function updateDescription($description) { $this->description = $description; } @@ -980,12 +982,12 @@ class Exercise * @author - Isaac flores * @param - int The expired time of the quiz */ - function updateExpiredTime($expired_time) + public function updateExpiredTime($expired_time) { $this->expired_time = $expired_time; } - function updatePropagateNegative($value) + public function updatePropagateNegative($value) { $this->propagate_neg = $value; } @@ -993,7 +995,7 @@ class Exercise /** * @param $value */ - function updateReviewAnswers($value) + public function updateReviewAnswers($value) { $this->review_answers = (isset($value) && $value) ? true : false; } @@ -1001,7 +1003,7 @@ class Exercise /** * @param $value */ - function updatePassPercentage($value) + public function updatePassPercentage($value) { $this->pass_percentage = $value; } @@ -1022,7 +1024,7 @@ class Exercise /** * @param array $categories */ - function updateCategories($categories) + public function updateCategories($categories) { if (!empty($categories)) { $categories = array_map('intval', $categories); @@ -1037,7 +1039,7 @@ class Exercise * @param - string $sound - exercise sound file * @param - string $delete - ask to delete the file */ - function updateSound($sound, $delete) + public function updateSound($sound, $delete) { global $audioPath, $documentPath; $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); @@ -1080,7 +1082,7 @@ class Exercise * @author - Olivier Brouckaert * @param - integer $type - exercise type */ - function updateType($type) + public function updateType($type) { $this->type = $type; } @@ -1092,7 +1094,7 @@ class Exercise * @author - Olivier Brouckaert * @param - integer $random - 0 if not random, otherwise the draws */ - function setRandom($random) + public function setRandom($random) { $this->random = $random; } @@ -1103,7 +1105,7 @@ class Exercise * @author - Juan Carlos Ra�a * @param - integer $random_answers - random answers */ - function updateRandomAnswers($random_answers) + public function updateRandomAnswers($random_answers) { $this->random_answers = $random_answers; } @@ -1113,7 +1115,7 @@ class Exercise * * @author - Olivier Brouckaert */ - function enable() + public function enable() { $this->active = 1; } @@ -1123,22 +1125,22 @@ class Exercise * * @author - Olivier Brouckaert */ - function disable() + public function disable() { $this->active = 0; } - function disable_results() + public function disable_results() { $this->results_disabled = true; } - function enable_results() + public function enable_results() { $this->results_disabled = false; } - function updateResultsDisabled($results_disabled) + public function updateResultsDisabled($results_disabled) { $this->results_disabled = intval($results_disabled); } @@ -1171,7 +1173,7 @@ class Exercise $pass_percentage = intval($this->pass_percentage); $session_id = api_get_session_id(); - //If direct we do not show results + // If direct we do not show results if ($feedback_type == EXERCISE_FEEDBACK_TYPE_DIRECT) { $results_disabled = 0; } else { @@ -1323,8 +1325,8 @@ class Exercise * removes a question from the question list * * @author - Olivier Brouckaert - * @param - integer $questionId - question ID - * @return - boolean - true if the question has been removed, otherwise false + * @param integer $questionId - question ID + * @return boolean - true if the question has been removed, otherwise false */ public function removeFromList($questionId) { @@ -2536,10 +2538,17 @@ class Exercise return $id; } + /** + * @param int $question_id + * @param int $questionNum + * @param array $questions_in_media + * @param array $remindList + * @return string + */ public function show_button($question_id, $questionNum, $questions_in_media = array(), $remindList = array()) { global $origin, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id; - $nbrQuestions = $this->get_count_question_list(); + $nbrQuestions = $this->getCountCompressedQuestionList(); $all_button = $html = $label = ''; $hotspot_get = isset($_POST['hotspot']) ? Security::remove_XSS($_POST['hotspot']) : null; @@ -5179,7 +5188,6 @@ class Exercise $teacher_answer_list = $this->fill_in_blank_answer_to_array($answer); $result = ''; if (!empty($teacher_answer_list)) { - $i = 0; foreach ($teacher_answer_list as $teacher_item) { $value = null; //Cleaning student answer list @@ -5215,9 +5223,10 @@ class Exercise } /** + * Get question list (including question ids of the media) * @return int */ - function get_count_question_list() + public function getCountUncompressedQuestionList() { //Real question count $question_count = 0; @@ -5229,6 +5238,24 @@ class Exercise return $question_count; } + /** + * Get question list (excluding question ids of the media) + * @return int + */ + public function getCountCompressedQuestionList() + { + $mediaQuestions = $this->getMediaList(); + $questionCount = 0; + foreach ($mediaQuestions as $mediaKey => $questionList) { + if ($mediaKey == 999) { + $questionCount += count($questionList); + } else { + $questionCount++; + } + } + return $questionCount; + } + /** * @return array */ @@ -5600,7 +5627,7 @@ class Exercise /** * Renders a question list * - * @param array $questionList + * @param array $questionList (with media questions compressed) * @param int $currentQuestion * @param array $exerciseResult * @param array $attemptList @@ -5611,7 +5638,7 @@ class Exercise $mediaQuestions = $this->getMediaList(); $i = 0; - // Normal question list render + // Normal question list render (medias compressed) foreach ($questionList as $questionId) { $i++; // For sequential exercises @@ -5797,7 +5824,7 @@ class Exercise case ALL_ON_ONE_PAGE : $button = ''.get_lang('SaveForNow').''; $button .= ' '; - $exercise_actions .= Display::div($button, array('class'=>'exercise_save_now_button')); + $exercise_actions .= Display::div($button, array('class'=>'exercise_save_now_button')); break; } @@ -5806,7 +5833,7 @@ class Exercise if ($count_of_questions_inside_media > 1) { $button = ''.get_lang('SaveForNow').''; $button .= ' '; - $exercise_actions = Display::div($button, array('class'=>'exercise_save_now_button')); + $exercise_actions = Display::div($button, array('class'=>'exercise_save_now_button')); } if ($last_question_in_media && $this->type == ONE_PER_PAGE) { @@ -5822,18 +5849,18 @@ class Exercise echo Display::div(' ', array('class'=>'clear')); - $paginator = null; + $paginationCounter = null; if ($this->type == ONE_PER_PAGE) { if (empty($questions_in_media)) { - $paginator = Display::paginationIndicator($current_question, count($realQuestionList)); + $paginationCounter = Display::paginationIndicator($current_question, count($realQuestionList)); } else { if ($last_question_in_media) { - $paginator = Display::paginationIndicator($current_question, count($realQuestionList)); + $paginationCounter = Display::paginationIndicator($current_question, count($realQuestionList)); } } } - echo '
'.$paginator.'
'; + echo '
'.$paginationCounter.'
'; echo Display::div($exercise_actions, array('class'=>'form-actions')); echo ''; } diff --git a/main/exercice/exercise_submit.php b/main/exercice/exercise_submit.php index 93176823b9..24e86ef364 100644 --- a/main/exercice/exercise_submit.php +++ b/main/exercice/exercise_submit.php @@ -335,7 +335,7 @@ if (api_is_allowed_to_edit(null,true) && isset($_GET['preview']) && $_GET['previ // 1. Loading the $objExercise variable if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) { // Construction of Exercise - /** @var \Exercise $objExercise */ + /** @var Exercise $objExercise */ $objExercise = new Exercise(); if ($debug) {error_log('1. Setting the $objExercise variable'); }; unset($_SESSION['questionList']); @@ -396,11 +396,14 @@ if ($time_control) { $total_seconds = $objExercise->expired_time * 60; } +$exercise_title = $objExercise->selectTitle(); +$exercise_sound = $objExercise->selectSound(); + $show_clock = true; $user_id = api_get_user_id(); if ($objExercise->selectAttempts() > 0) { - $attempt_html = null; - $attempt_count = get_attempt_count($user_id, $exerciseId, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id); + $attempt_html = null; + $attempt_count = get_attempt_count($user_id, $exerciseId, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id); if ($attempt_count >= $objExercise->selectAttempts()) { $show_clock = false; @@ -600,12 +603,9 @@ if ($time_control) { //Sends the exercise form when the expired time is finished $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left); } -$exercise_title = $objExercise->selectTitle(); -$exercise_sound = $objExercise->selectSound(); - if ($debug) error_log('8. Question list loaded '.print_r($questionList, 1)); -$question_count = $objExercise->get_count_question_list(); +$question_count = $objExercise->getCountCompressedQuestionList(); if ($formSent && isset($_POST)) { if ($debug) { error_log('9. $formSent was sent'); } @@ -1176,16 +1176,6 @@ if (!empty($error)) { } '; - echo '
- - - - - - - - '; - // Show list of questions. $attempt_list = array(); if (isset($exe_id)) { @@ -1196,6 +1186,17 @@ if (!empty($error)) { if (isset($exercise_stat_info['questions_to_check']) && !empty($exercise_stat_info['questions_to_check'])) { $remind_list = explode(',', $exercise_stat_info['questions_to_check']); } + + echo ' + + + + + + + + '; + $objExercise->renderQuestionList($questionList, $current_question, $exerciseResult, $attempt_list, $remind_list); echo '
';