From 75a31c9039b1f06f6d1dca7b07282117de83aa41 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Wed, 2 Nov 2011 17:13:11 +0000 Subject: [PATCH] MDL-29808 qbehaviours: update to use ->dependencies in version.php --- admin/qbehaviours.php | 23 ++++++------ lib/pluginlib.php | 18 +-------- question/behaviour/adaptive/version.php | 33 +++++++++++++++++ .../behaviour/adaptivenopenalty/behaviour.php | 4 -- .../behaviour/adaptivenopenalty/version.php | 36 ++++++++++++++++++ question/behaviour/behaviourbase.php | 4 -- question/behaviour/deferredcbm/behaviour.php | 4 -- question/behaviour/deferredcbm/version.php | 36 ++++++++++++++++++ .../behaviour/deferredfeedback/version.php | 33 +++++++++++++++++ question/behaviour/immediatecbm/behaviour.php | 4 -- question/behaviour/immediatecbm/version.php | 37 +++++++++++++++++++ .../behaviour/immediatefeedback/version.php | 33 +++++++++++++++++ .../behaviour/informationitem/version.php | 33 +++++++++++++++++ question/behaviour/interactive/version.php | 33 +++++++++++++++++ .../interactivecountback/behaviour.php | 4 -- .../interactivecountback/version.php | 36 ++++++++++++++++++ question/behaviour/manualgraded/version.php | 33 +++++++++++++++++ question/behaviour/missing/version.php | 33 +++++++++++++++++ question/behaviour/upgrade.txt | 11 ++++++ question/engine/lib.php | 11 ------ 20 files changed, 399 insertions(+), 60 deletions(-) create mode 100644 question/behaviour/adaptive/version.php create mode 100644 question/behaviour/adaptivenopenalty/version.php create mode 100644 question/behaviour/deferredcbm/version.php create mode 100644 question/behaviour/deferredfeedback/version.php create mode 100644 question/behaviour/immediatecbm/version.php create mode 100644 question/behaviour/immediatefeedback/version.php create mode 100644 question/behaviour/informationitem/version.php create mode 100644 question/behaviour/interactive/version.php create mode 100644 question/behaviour/interactivecountback/version.php create mode 100644 question/behaviour/manualgraded/version.php create mode 100644 question/behaviour/missing/version.php create mode 100644 question/behaviour/upgrade.txt diff --git a/admin/qbehaviours.php b/admin/qbehaviours.php index db76b95f01d..5c6524bf5b0 100644 --- a/admin/qbehaviours.php +++ b/admin/qbehaviours.php @@ -28,6 +28,7 @@ require_once(dirname(__FILE__) . '/../config.php'); require_once($CFG->libdir . '/questionlib.php'); require_once($CFG->libdir . '/adminlib.php'); +require_once($CFG->libdir . '/pluginlib.php'); require_once($CFG->libdir . '/tablelib.php'); // Check permissions. @@ -39,6 +40,7 @@ admin_externalpage_setup('manageqbehaviours'); $thispageurl = new moodle_url('/admin/qbehaviours.php'); $behaviours = get_plugin_list('qbehaviour'); +$pluginmanager = plugin_manager::instance(); // Get some data we will need - question counts and which types are needed. $counts = $DB->get_records_sql_menu(" @@ -50,15 +52,11 @@ foreach ($behaviours as $behaviour => $notused) { if (!array_key_exists($behaviour, $counts)) { $counts[$behaviour] = 0; } - $needed[$behaviour] = $counts[$behaviour] > 0; + $needed[$behaviour] = ($counts[$behaviour] > 0) && + $pluginmanager->other_plugins_that_require('qbehaviour_' . $behaviour); $archetypal[$behaviour] = question_engine::is_behaviour_archetypal($behaviour); } -foreach ($behaviours as $behaviour => $notused) { - foreach (question_engine::get_behaviour_required_behaviours($behaviour) as $reqbehaviour) { - $needed[$reqbehaviour] = true; - } -} foreach ($counts as $behaviour => $count) { if (!array_key_exists($behaviour, $behaviours)) { $counts['missingtype'] += $count; @@ -238,13 +236,14 @@ foreach ($sortedbehaviours as $behaviour => $behaviourname) { } // Other question types required by this one. - $requiredbehaviours = question_engine::get_behaviour_required_behaviours($behaviour); - if (!empty($requiredbehaviours)) { - $strrequiredbehaviours = array(); - foreach ($requiredbehaviours as $required) { - $strrequiredbehaviours[] = $sortedbehaviours[$required]; + $plugin = $pluginmanager->get_plugin_info('qbehaviour_' . $behaviour); + $required = $plugin->get_other_required_plugins(); + if (!empty($required)) { + $strrequired = array(); + foreach ($required as $component => $notused) { + $strrequired[] = $pluginmanager->plugin_name($component); } - $row[] = implode(', ', $strrequiredbehaviours); + $row[] = implode(', ', $strrequired); } else { $row[] = ''; } diff --git a/lib/pluginlib.php b/lib/pluginlib.php index e49500c8055..9c51d5be364 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -1382,25 +1382,9 @@ class plugintype_mod extends plugintype_base implements plugin_information { * Class for question behaviours. */ class plugintype_qbehaviour extends plugintype_base implements plugin_information { - /** - * @see plugintype_base::load_other_required_plugins(). + * @see plugin_information::get_uninstall_url() */ - protected function load_other_required_plugins() { - parent::load_other_required_plugins(); - if (!empty($this->dependencies)) { - return; - } - - // Standard mechanism did not find anything, so try the legacy way. - global $CFG; - require_once($CFG->libdir . '/questionlib.php'); - $required = question_engine::get_behaviour_required_behaviours($this->name); - foreach ($required as $other) { - $this->dependencies['qbehaviour_' . $other] = ANY_VERSION; - } - } - public function get_uninstall_url() { return new moodle_url('/admin/qbehaviours.php', array('delete' => $this->name, 'sesskey' => sesskey())); diff --git a/question/behaviour/adaptive/version.php b/question/behaviour/adaptive/version.php new file mode 100644 index 00000000000..f238f80d018 --- /dev/null +++ b/question/behaviour/adaptive/version.php @@ -0,0 +1,33 @@ +. + +/** + * Version information for the calculated question type. + * + * @package qbehaviour + * @subpackage adaptive + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'qbehaviour_adaptive'; +$plugin->version = 2011102700; + +$plugin->requires = 2011102700; + +$plugin->maturity = MATURITY_STABLE; diff --git a/question/behaviour/adaptivenopenalty/behaviour.php b/question/behaviour/adaptivenopenalty/behaviour.php index 09f36b4544b..0740fa6b192 100644 --- a/question/behaviour/adaptivenopenalty/behaviour.php +++ b/question/behaviour/adaptivenopenalty/behaviour.php @@ -40,10 +40,6 @@ require_once(dirname(__FILE__) . '/../adaptive/behaviour.php'); class qbehaviour_adaptivenopenalty extends qbehaviour_adaptive { const IS_ARCHETYPAL = true; - public static function get_required_behaviours() { - return array('adaptive'); - } - protected function adjusted_fraction($fraction, $prevtries) { return $fraction; } diff --git a/question/behaviour/adaptivenopenalty/version.php b/question/behaviour/adaptivenopenalty/version.php new file mode 100644 index 00000000000..7128c7983f4 --- /dev/null +++ b/question/behaviour/adaptivenopenalty/version.php @@ -0,0 +1,36 @@ +. + +/** + * Version information for the calculated question type. + * + * @package qbehaviour + * @subpackage adaptivenopenalty + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'qbehaviour_adaptivenopenalty'; +$plugin->version = 2011102700; + +$plugin->requires = 2011102700; +$plugin->dependencies = array( + 'qbehaviour_adaptive' => 2011102700 +); + +$plugin->maturity = MATURITY_STABLE; diff --git a/question/behaviour/behaviourbase.php b/question/behaviour/behaviourbase.php index 0f79988e72f..95c0e2a4dfe 100644 --- a/question/behaviour/behaviourbase.php +++ b/question/behaviour/behaviourbase.php @@ -77,10 +77,6 @@ abstract class question_behaviour { } } - public static function get_required_behaviours() { - return array(); - } - /** * Most behaviours can only work with {@link question_definition}s * of a particular subtype, or that implement a particular interface. diff --git a/question/behaviour/deferredcbm/behaviour.php b/question/behaviour/deferredcbm/behaviour.php index bd533356a22..1c6bcf2e2d1 100644 --- a/question/behaviour/deferredcbm/behaviour.php +++ b/question/behaviour/deferredcbm/behaviour.php @@ -45,10 +45,6 @@ require_once(dirname(__FILE__) . '/../deferredfeedback/behaviour.php'); class qbehaviour_deferredcbm extends qbehaviour_deferredfeedback { const IS_ARCHETYPAL = true; - public static function get_required_behaviours() { - return array('deferredfeedback'); - } - public static function get_unused_display_options() { return array('correctness', 'marks', 'specificfeedback', 'generalfeedback', 'rightanswer'); diff --git a/question/behaviour/deferredcbm/version.php b/question/behaviour/deferredcbm/version.php new file mode 100644 index 00000000000..f4145923a15 --- /dev/null +++ b/question/behaviour/deferredcbm/version.php @@ -0,0 +1,36 @@ +. + +/** + * Version information for the calculated question type. + * + * @package qbehaviour + * @subpackage deferredcbm + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'qbehaviour_deferredcbm'; +$plugin->version = 2011102700; + +$plugin->requires = 2011102700; +$plugin->dependencies = array( + 'qbehaviour_deferredfeedback' => 2011102700 +); + +$plugin->maturity = MATURITY_STABLE; diff --git a/question/behaviour/deferredfeedback/version.php b/question/behaviour/deferredfeedback/version.php new file mode 100644 index 00000000000..bf26541be7b --- /dev/null +++ b/question/behaviour/deferredfeedback/version.php @@ -0,0 +1,33 @@ +. + +/** + * Version information for the calculated question type. + * + * @package qbehaviour + * @subpackage deferredfeedback + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'qbehaviour_deferredfeedback'; +$plugin->version = 2011102700; + +$plugin->requires = 2011102700; + +$plugin->maturity = MATURITY_STABLE; diff --git a/question/behaviour/immediatecbm/behaviour.php b/question/behaviour/immediatecbm/behaviour.php index 852547c9bca..a188c2c871a 100644 --- a/question/behaviour/immediatecbm/behaviour.php +++ b/question/behaviour/immediatecbm/behaviour.php @@ -45,10 +45,6 @@ require_once(dirname(__FILE__) . '/../immediatefeedback/behaviour.php'); class qbehaviour_immediatecbm extends qbehaviour_immediatefeedback { const IS_ARCHETYPAL = true; - public static function get_required_behaviours() { - return array('immediatefeedback', 'deferredcbm'); - } - public function get_min_fraction() { return question_cbm::adjust_fraction(parent::get_min_fraction(), question_cbm::HIGH); } diff --git a/question/behaviour/immediatecbm/version.php b/question/behaviour/immediatecbm/version.php new file mode 100644 index 00000000000..0f7f6e8a6e3 --- /dev/null +++ b/question/behaviour/immediatecbm/version.php @@ -0,0 +1,37 @@ +. + +/** + * Version information for the calculated question type. + * + * @package qbehaviour + * @subpackage immediatecbm + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'qbehaviour_immediatecbm'; +$plugin->version = 2011102700; + +$plugin->requires = 2011102700; +$plugin->dependencies = array( + 'qbehaviour_immediatefeedback' => 2011102700, + 'qbehaviour_deferredcbm' => 2011102700 +); + +$plugin->maturity = MATURITY_STABLE; diff --git a/question/behaviour/immediatefeedback/version.php b/question/behaviour/immediatefeedback/version.php new file mode 100644 index 00000000000..253b820e4a2 --- /dev/null +++ b/question/behaviour/immediatefeedback/version.php @@ -0,0 +1,33 @@ +. + +/** + * Version information for the calculated question type. + * + * @package qbehaviour + * @subpackage immediatefeedback + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'qbehaviour_immediatefeedback'; +$plugin->version = 2011102700; + +$plugin->requires = 2011102700; + +$plugin->maturity = MATURITY_STABLE; diff --git a/question/behaviour/informationitem/version.php b/question/behaviour/informationitem/version.php new file mode 100644 index 00000000000..9e1e70036d3 --- /dev/null +++ b/question/behaviour/informationitem/version.php @@ -0,0 +1,33 @@ +. + +/** + * Version information for the calculated question type. + * + * @package qbehaviour + * @subpackage informationitem + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'qbehaviour_informationitem'; +$plugin->version = 2011102700; + +$plugin->requires = 2011102700; + +$plugin->maturity = MATURITY_STABLE; diff --git a/question/behaviour/interactive/version.php b/question/behaviour/interactive/version.php new file mode 100644 index 00000000000..4a37847106c --- /dev/null +++ b/question/behaviour/interactive/version.php @@ -0,0 +1,33 @@ +. + +/** + * Version information for the calculated question type. + * + * @package qbehaviour + * @subpackage interactive + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'qbehaviour_interactive'; +$plugin->version = 2011102700; + +$plugin->requires = 2011102700; + +$plugin->maturity = MATURITY_STABLE; diff --git a/question/behaviour/interactivecountback/behaviour.php b/question/behaviour/interactivecountback/behaviour.php index 13e74c95b4d..5b3e7f44164 100644 --- a/question/behaviour/interactivecountback/behaviour.php +++ b/question/behaviour/interactivecountback/behaviour.php @@ -64,10 +64,6 @@ require_once(dirname(__FILE__) . '/../interactive/behaviour.php'); class qbehaviour_interactivecountback extends qbehaviour_interactive { const IS_ARCHETYPAL = false; - public static function get_required_behaviours() { - return array('interactive'); - } - public function required_question_definition_type() { return 'question_automatically_gradable_with_countback'; } diff --git a/question/behaviour/interactivecountback/version.php b/question/behaviour/interactivecountback/version.php new file mode 100644 index 00000000000..75b6602e58d --- /dev/null +++ b/question/behaviour/interactivecountback/version.php @@ -0,0 +1,36 @@ +. + +/** + * Version information for the calculated question type. + * + * @package qbehaviour + * @subpackage interactivecountback + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'qbehaviour_interactivecountback'; +$plugin->version = 2011102700; + +$plugin->requires = 2011102700; +$plugin->dependencies = array( + 'qbehaviour_interactive' => 2011102700 +); + +$plugin->maturity = MATURITY_STABLE; diff --git a/question/behaviour/manualgraded/version.php b/question/behaviour/manualgraded/version.php new file mode 100644 index 00000000000..bae67130626 --- /dev/null +++ b/question/behaviour/manualgraded/version.php @@ -0,0 +1,33 @@ +. + +/** + * Version information for the calculated question type. + * + * @package qbehaviour + * @subpackage manualgraded + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'qbehaviour_manualgraded'; +$plugin->version = 2011102700; + +$plugin->requires = 2011102700; + +$plugin->maturity = MATURITY_STABLE; diff --git a/question/behaviour/missing/version.php b/question/behaviour/missing/version.php new file mode 100644 index 00000000000..03002acf661 --- /dev/null +++ b/question/behaviour/missing/version.php @@ -0,0 +1,33 @@ +. + +/** + * Version information for the calculated question type. + * + * @package qbehaviour + * @subpackage missing + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'qbehaviour_missing'; +$plugin->version = 2011102700; + +$plugin->requires = 2011102700; + +$plugin->maturity = MATURITY_STABLE; diff --git a/question/behaviour/upgrade.txt b/question/behaviour/upgrade.txt new file mode 100644 index 00000000000..db780e8dbcd --- /dev/null +++ b/question/behaviour/upgrade.txt @@ -0,0 +1,11 @@ +This files describes API changes for question behaviour plugins. + +=== 2.2 === + +* The old + public static function get_required_behaviours() +method is no more. Instead use the ->dependencies facility in version.php. E.g. +$plugin->dependencies = array( + 'qbehaviour_immediatefeedback' => 2011102700, + 'qbehaviour_deferredcbm' => 2011102700 +); diff --git a/question/engine/lib.php b/question/engine/lib.php index 5f9d4bf0dd5..d9c7d0fe19f 100644 --- a/question/engine/lib.php +++ b/question/engine/lib.php @@ -328,17 +328,6 @@ abstract class question_engine { return get_string('pluginname', 'qbehaviour_' . $behaviour); } - /** - * Get the translated name of an behaviour, for display in the UI. - * @param string $behaviour the internal name of the model. - * @return string name from the current language pack. - */ - public static function get_behaviour_required_behaviours($behaviour) { - self::load_behaviour_class($behaviour); - $class = 'qbehaviour_' . $behaviour; - return $class::get_required_behaviours(); - } - /** * @return array all the file area names that may contain response files. */