From b07ef13be28826efad413764fb231ff97e59be55 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Thu, 19 Sep 2013 14:26:37 +0800 Subject: [PATCH] MDL-41885 modules now declare use of question bank * FEATURE_USES_QUESTION_BANK is now a module_supports flag which declares that an activity uses the question engine. * question_module_uses_questions can be used to determine if a module uses the question bank. --- lib/moodlelib.php | 3 +++ lib/questionlib.php | 20 ++++++++++++++++++++ mod/quiz/lib.php | 1 + mod/upgrade.txt | 4 ++++ question/upgrade.txt | 6 +++++- 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 0190090ce93..dd596a4a699 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -433,6 +433,9 @@ define('FEATURE_BACKUP_MOODLE2', 'backup_moodle2'); /** True if module can show description on course main page */ define('FEATURE_SHOW_DESCRIPTION', 'showdescription'); +/** True if module uses the question bank */ +define('FEATURE_USES_QUESTIONS', 'usesquestions'); + /** Unspecified module archetype */ define('MOD_ARCHETYPE_OTHER', 0); /** Resource-like type module */ diff --git a/lib/questionlib.php b/lib/questionlib.php index 9984b71cd59..5cdfb69ba9c 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -2054,3 +2054,23 @@ function question_page_type_list($pagetype, $parentcontext, $currentcontext) { return $types; } } + +/** + * Does an activity module use the question bank? + * + * @param string $modname The name of the module (without mod_ prefix). + * @return bool true if the module uses questions. + */ +function question_module_uses_questions($modname) { + if (plugin_supports('mod', $modname, FEATURE_USES_QUESTIONS)) { + return true; + } + + $component = 'mod_'.$modname; + if (component_callback_exists($component, 'question_pluginfile')) { + debugging("{$component} uses questions but doesn't declare FEATURE_USES_QUESTIONS", DEBUG_DEVELOPER); + return true; + } + + return false; +} diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index c6394adf596..7aa48c5a73d 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -1547,6 +1547,7 @@ function quiz_supports($feature) { case FEATURE_BACKUP_MOODLE2: return true; case FEATURE_SHOW_DESCRIPTION: return true; case FEATURE_CONTROLS_GRADE_VISIBILITY: return true; + case FEATURE_USES_QUESTIONS: return true; default: return null; } diff --git a/mod/upgrade.txt b/mod/upgrade.txt index bc46994f7d1..0f669360cb4 100644 --- a/mod/upgrade.txt +++ b/mod/upgrade.txt @@ -1,6 +1,10 @@ This files describes API changes in /mod/* - activity modules, information provided here is intended especially for developers. +=== 2.6 === + +* Modules using the question bank MUST now declare their use of it with the xxx_supports() + flag FEATURE_USES_QUESTIONS. === 2.5 === diff --git a/question/upgrade.txt b/question/upgrade.txt index 32ad8f22eb6..4b4a9ba2064 100644 --- a/question/upgrade.txt +++ b/question/upgrade.txt @@ -2,7 +2,11 @@ This files describes API changes for code that uses the question API. === 2.6 === -1) It is sometimes necessary to display bits of question content without having +1) Modules using the question bank MUST now declare their use of it with the xxx_supports() + flag FEATURE_USES_QUESTIONS. question_module_uses_questions() should be used to determine + if a module uses questions. + +2) It is sometimes necessary to display bits of question content without having and attempt (question_usage) in progress. Two examples of this are the option in the question bank to display the questiontext, and in the quiz statistics report, where it displays the question text above the report.