Skip to content

Commit

Permalink
MDL-78025 quiz: fix the quiz_questions_in_use logic
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Apr 26, 2023
1 parent 62fdb2d commit 4806994
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions mod/quiz/lib.php
Expand Up @@ -1431,25 +1431,15 @@ function quiz_get_post_actions() {
}

/**
* Standard callback used by questions_in_use.
*
* @param array $questionids of question ids.
* @return bool whether any of these questions are used by any instance of this module.
*/
function quiz_questions_in_use($questionids) {
global $DB;
list($test, $params) = $DB->get_in_or_equal($questionids);
$params['component'] = 'mod_quiz';
$params['questionarea'] = 'slot';
$sql = "SELECT qs.id
FROM {quiz_slots} qs
JOIN {question_references} qr ON qr.itemid = qs.id
JOIN {question_bank_entries} qbe ON qbe.id = qr.questionbankentryid
JOIN {question_versions} qv ON qv.questionbankentryid = qbe.id
WHERE qv.questionid $test
AND qr.component = ?
AND qr.questionarea = ?";
return $DB->record_exists_sql($sql, $params) || question_engine::questions_in_use(
$questionids, new qubaid_join('{quiz_attempts} quiza',
'quiza.uniqueid', 'quiza.preview = 0'));
return question_engine::questions_in_use($questionids,
new qubaid_join('{quiz_attempts} quiza', 'quiza.uniqueid',
'quiza.preview = 0'));
}

/**
Expand Down

0 comments on commit 4806994

Please sign in to comment.