mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-74255 quiz: Remove un-needed method question_array_sort
This commit is contained in:
parent
f62cd4484e
commit
37e8faf0ed
5 changed files with 19 additions and 35 deletions
|
@ -152,8 +152,8 @@ class quiz {
|
|||
if (!empty($questionids)) {
|
||||
$questiondata = \mod_quiz\question\bank\qbank_helper::get_question_structure_data($this->quiz->id, $questionids, true);
|
||||
}
|
||||
$allquestiondata = \mod_quiz\question\bank\qbank_helper::question_array_sort(
|
||||
\mod_quiz\question\bank\qbank_helper::question_load_random_questions($this->quiz->id, $questiondata), 'slot');
|
||||
$allquestiondata = \mod_quiz\question\bank\qbank_helper::question_load_random_questions(
|
||||
$this->quiz->id, $questiondata);
|
||||
$this->questions = $allquestiondata;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,23 +68,6 @@ class qbank_helper {
|
|||
return $DB->get_records_sql($sql, [$questionid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the elements of an array according to a key.
|
||||
*
|
||||
* @param array $arrays
|
||||
* @param string $on
|
||||
* @param int $order
|
||||
* @return array
|
||||
*/
|
||||
public static function question_array_sort($arrays, $on, $order = SORT_ASC): array {
|
||||
$element = [];
|
||||
foreach ($arrays as $array) {
|
||||
$element[$array->$on] = $array;
|
||||
}
|
||||
ksort($element, $order);
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the question id from slot id.
|
||||
*
|
||||
|
@ -204,10 +187,10 @@ class qbank_helper {
|
|||
/**
|
||||
* Get the question structure data for the given quiz or question ids.
|
||||
*
|
||||
* @param null $quizid
|
||||
* @param int $quizid ID of the quiz to load data for.
|
||||
* @param array $questionids
|
||||
* @param bool $attempt
|
||||
* @return array
|
||||
* @param bool $attempt if false (default) array key is slot number, else array key is question.id.
|
||||
* @return array the question data, ordered by slot number.
|
||||
*/
|
||||
public static function get_question_structure_data($quizid, $questionids = [], $attempt = false) {
|
||||
global $DB;
|
||||
|
@ -245,16 +228,14 @@ class qbank_helper {
|
|||
LEFT JOIN {question_categories} qc ON qc.id = qbe.questioncategoryid
|
||||
LEFT JOIN {question} q ON q.id = qv.questionid
|
||||
WHERE slot.quizid = :quizid
|
||||
$condition";
|
||||
$condition
|
||||
ORDER BY slot.slot";
|
||||
$questiondatas = $DB->get_records_sql($sql, $params);
|
||||
foreach ($questiondatas as $questiondata) {
|
||||
$questiondata->_partiallyloaded = true;
|
||||
}
|
||||
if (!empty($questiondatas)) {
|
||||
return $questiondatas;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get question structure.
|
||||
|
@ -274,7 +255,9 @@ class qbank_helper {
|
|||
}
|
||||
}
|
||||
|
||||
return self::question_array_sort(array_merge($firstslotsets, $secondslotsets), 'slot');
|
||||
$data = array_merge($firstslotsets, $secondslotsets);
|
||||
ksort($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -329,7 +312,7 @@ class qbank_helper {
|
|||
}
|
||||
|
||||
foreach ($randomquestions as $randomquestion) {
|
||||
// Should not add if there is no question found from the ramdom question loader, maybe empty category.
|
||||
// Should not add if there is no question found from the random question loader, maybe empty category.
|
||||
if ($randomquestion->questionid === null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -346,6 +329,8 @@ class qbank_helper {
|
|||
$questiondata[$question->id] = $question;
|
||||
}
|
||||
|
||||
uasort($questiondata, function (\stdClass $a, \stdClass $b): int { return ($a->slot <=> $b->slot); });
|
||||
|
||||
return $questiondata;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ function quiz_report_get_significant_questions($quiz) {
|
|||
}
|
||||
$qsbyslot[$slotreport->slot] = $slotreport;
|
||||
}
|
||||
$qsbyslot = \mod_quiz\question\bank\qbank_helper::question_array_sort($qsbyslot, 'slot');
|
||||
ksort($qsbyslot);
|
||||
$number = 1;
|
||||
foreach ($qsbyslot as $question) {
|
||||
$question->number = $number;
|
||||
|
|
|
@ -856,7 +856,8 @@ class quiz_statistics_report extends quiz_default_report {
|
|||
foreach ($randomquestions as $randomquestion) {
|
||||
$questiondata[$randomquestion->slot] = $randomquestion;
|
||||
}
|
||||
return \mod_quiz\question\bank\qbank_helper::question_array_sort($questiondata, 'slot');
|
||||
ksort($questiondata);
|
||||
return $questiondata;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -80,7 +80,6 @@ class qbank_helper_test extends \advanced_testcase {
|
|||
* @covers ::get_question_for_redo
|
||||
* @covers ::get_always_latest_version_question_ids
|
||||
* @covers ::question_load_random_questions
|
||||
* @covers ::question_array_sort
|
||||
*/
|
||||
public function test_reference_records() {
|
||||
$this->resetAfterTest();
|
||||
|
@ -130,7 +129,6 @@ class qbank_helper_test extends \advanced_testcase {
|
|||
*
|
||||
* @covers ::get_question_structure
|
||||
* @covers ::get_question_structure_data
|
||||
* @covers ::question_array_sort
|
||||
* @covers ::get_always_latest_version_question_ids
|
||||
* @covers ::question_load_random_questions
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue