mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-67947 questions: questions_in_use should ask all components
Previously it was only checking mods.
This commit is contained in:
parent
4e90332195
commit
887daf932c
3 changed files with 32 additions and 22 deletions
|
@ -287,7 +287,7 @@ $string['questiondoesnotexist'] = 'This question does not exist';
|
||||||
$string['questionname'] = 'Question name';
|
$string['questionname'] = 'Question name';
|
||||||
$string['questionno'] = 'Question {$a}';
|
$string['questionno'] = 'Question {$a}';
|
||||||
$string['questionsaveerror'] = 'Errors occur during saving question - ({$a})';
|
$string['questionsaveerror'] = 'Errors occur during saving question - ({$a})';
|
||||||
$string['questionsinuse'] = '(* Questions marked by an asterisk are already in use in some quizzes. These questions will not be deleted from these quizzes but only from the category list.)';
|
$string['questionsinuse'] = '(* Questions marked with an asterisk are used somewhere, for example in a quiz. Therefore, if you proceed, these questions will not really be deleted, they will just be hidden.)';
|
||||||
$string['questionsmovedto'] = 'Questions still in use moved to "{$a}" in the parent course category.';
|
$string['questionsmovedto'] = 'Questions still in use moved to "{$a}" in the parent course category.';
|
||||||
$string['questionsrescuedfrom'] = 'Questions saved from context {$a}.';
|
$string['questionsrescuedfrom'] = 'Questions saved from context {$a}.';
|
||||||
$string['questionsrescuedfrominfo'] = 'These questions (some of which may be hidden) were saved when context {$a} was deleted because they are still used by some quizzes or other activities.';
|
$string['questionsrescuedfrominfo'] = 'These questions (some of which may be hidden) were saved when context {$a} was deleted because they are still used by some quizzes or other activities.';
|
||||||
|
|
|
@ -119,34 +119,35 @@ function question_save_qtype_order($neworder, $config = null) {
|
||||||
* @return boolean whether any of these questions are being used by any part of Moodle.
|
* @return boolean whether any of these questions are being used by any part of Moodle.
|
||||||
*/
|
*/
|
||||||
function questions_in_use($questionids) {
|
function questions_in_use($questionids) {
|
||||||
global $CFG;
|
|
||||||
|
|
||||||
|
// Are they used by the core question system?
|
||||||
if (question_engine::questions_in_use($questionids)) {
|
if (question_engine::questions_in_use($questionids)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (core_component::get_plugin_list('mod') as $module => $path) {
|
// Check if any plugins are using these questions.
|
||||||
$lib = $path . '/lib.php';
|
$callbacksbytype = get_plugins_with_function('questions_in_use');
|
||||||
if (is_readable($lib)) {
|
foreach ($callbacksbytype as $callbacks) {
|
||||||
include_once($lib);
|
foreach ($callbacks as $function) {
|
||||||
|
if ($function($questionids)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$fn = $module . '_questions_in_use';
|
// Finally check legacy callback.
|
||||||
if (function_exists($fn)) {
|
$legacycallbacks = get_plugin_list_with_function('mod', 'question_list_instances');
|
||||||
if ($fn($questionids)) {
|
foreach ($legacycallbacks as $plugin => $function) {
|
||||||
return true;
|
debugging($plugin . ' implements deprecated method ' . $function .
|
||||||
}
|
'. ' . $plugin . '_questions_in_use should be implemented instead.', DEBUG_DEVELOPER);
|
||||||
} else {
|
|
||||||
|
|
||||||
// Fallback for legacy modules.
|
if (isset($callbacksbytype['mod'][substr($plugin, 4)])) {
|
||||||
$fn = $module . '_question_list_instances';
|
continue; // Already done.
|
||||||
if (function_exists($fn)) {
|
}
|
||||||
foreach ($questionids as $questionid) {
|
|
||||||
$instances = $fn($questionid);
|
foreach ($questionids as $questionid) {
|
||||||
if (!empty($instances)) {
|
if (!empty($function($questionid))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
This files describes API changes for code that uses the question API.
|
This files describes API changes for code that uses the question API.
|
||||||
|
|
||||||
|
=== 3.9 ==
|
||||||
|
|
||||||
|
For years, the ..._questions_in_use callback has been the right way for plugins to
|
||||||
|
tell the core question system if questions are required. Previously this callback
|
||||||
|
only worked in mods. Now it works in all plugins.
|
||||||
|
|
||||||
|
At the same time, if you are still relying on the legacy ..._question_list_instances
|
||||||
|
callback for this, you will now get a debugging warning telling you to upgrade.
|
||||||
|
|
||||||
=== 3.8 ===
|
=== 3.8 ===
|
||||||
|
|
||||||
If you have customised the display of the question bank (using $CFG->questionbankcolumns)
|
If you have customised the display of the question bank (using $CFG->questionbankcolumns)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue