Commit 75a31c90 authored by Tim Hunt's avatar Tim Hunt
Browse files

MDL-29808 qbehaviours: update to use ->dependencies in version.php

parent 828788f0
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
require_once(dirname(__FILE__) . '/../config.php'); require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->libdir . '/questionlib.php'); require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/pluginlib.php');
require_once($CFG->libdir . '/tablelib.php'); require_once($CFG->libdir . '/tablelib.php');
// Check permissions. // Check permissions.
...@@ -39,6 +40,7 @@ admin_externalpage_setup('manageqbehaviours'); ...@@ -39,6 +40,7 @@ admin_externalpage_setup('manageqbehaviours');
$thispageurl = new moodle_url('/admin/qbehaviours.php'); $thispageurl = new moodle_url('/admin/qbehaviours.php');
$behaviours = get_plugin_list('qbehaviour'); $behaviours = get_plugin_list('qbehaviour');
$pluginmanager = plugin_manager::instance();
// Get some data we will need - question counts and which types are needed. // Get some data we will need - question counts and which types are needed.
$counts = $DB->get_records_sql_menu(" $counts = $DB->get_records_sql_menu("
...@@ -50,15 +52,11 @@ foreach ($behaviours as $behaviour => $notused) { ...@@ -50,15 +52,11 @@ foreach ($behaviours as $behaviour => $notused) {
if (!array_key_exists($behaviour, $counts)) { if (!array_key_exists($behaviour, $counts)) {
$counts[$behaviour] = 0; $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); $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) { foreach ($counts as $behaviour => $count) {
if (!array_key_exists($behaviour, $behaviours)) { if (!array_key_exists($behaviour, $behaviours)) {
$counts['missingtype'] += $count; $counts['missingtype'] += $count;
...@@ -238,13 +236,14 @@ foreach ($sortedbehaviours as $behaviour => $behaviourname) { ...@@ -238,13 +236,14 @@ foreach ($sortedbehaviours as $behaviour => $behaviourname) {
} }
// Other question types required by this one. // Other question types required by this one.
$requiredbehaviours = question_engine::get_behaviour_required_behaviours($behaviour); $plugin = $pluginmanager->get_plugin_info('qbehaviour_' . $behaviour);
if (!empty($requiredbehaviours)) { $required = $plugin->get_other_required_plugins();
$strrequiredbehaviours = array(); if (!empty($required)) {
foreach ($requiredbehaviours as $required) { $strrequired = array();
$strrequiredbehaviours[] = $sortedbehaviours[$required]; foreach ($required as $component => $notused) {
$strrequired[] = $pluginmanager->plugin_name($component);
} }
$row[] = implode(', ', $strrequiredbehaviours); $row[] = implode(', ', $strrequired);
} else { } else {
$row[] = ''; $row[] = '';
} }
......
...@@ -1382,25 +1382,9 @@ class plugintype_mod extends plugintype_base implements plugin_information { ...@@ -1382,25 +1382,9 @@ class plugintype_mod extends plugintype_base implements plugin_information {
* Class for question behaviours. * Class for question behaviours.
*/ */
class plugintype_qbehaviour extends plugintype_base implements plugin_information { 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() { public function get_uninstall_url() {
return new moodle_url('/admin/qbehaviours.php', return new moodle_url('/admin/qbehaviours.php',
array('delete' => $this->name, 'sesskey' => sesskey())); array('delete' => $this->name, 'sesskey' => sesskey()));
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
...@@ -40,10 +40,6 @@ require_once(dirname(__FILE__) . '/../adaptive/behaviour.php'); ...@@ -40,10 +40,6 @@ require_once(dirname(__FILE__) . '/../adaptive/behaviour.php');
class qbehaviour_adaptivenopenalty extends qbehaviour_adaptive { class qbehaviour_adaptivenopenalty extends qbehaviour_adaptive {
const IS_ARCHETYPAL = true; const IS_ARCHETYPAL = true;
public static function get_required_behaviours() {
return array('adaptive');
}
protected function adjusted_fraction($fraction, $prevtries) { protected function adjusted_fraction($fraction, $prevtries) {
return $fraction; return $fraction;
} }
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
...@@ -77,10 +77,6 @@ abstract class question_behaviour { ...@@ -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 * Most behaviours can only work with {@link question_definition}s
* of a particular subtype, or that implement a particular interface. * of a particular subtype, or that implement a particular interface.
......
...@@ -45,10 +45,6 @@ require_once(dirname(__FILE__) . '/../deferredfeedback/behaviour.php'); ...@@ -45,10 +45,6 @@ require_once(dirname(__FILE__) . '/../deferredfeedback/behaviour.php');
class qbehaviour_deferredcbm extends qbehaviour_deferredfeedback { class qbehaviour_deferredcbm extends qbehaviour_deferredfeedback {
const IS_ARCHETYPAL = true; const IS_ARCHETYPAL = true;
public static function get_required_behaviours() {
return array('deferredfeedback');
}
public static function get_unused_display_options() { public static function get_unused_display_options() {
return array('correctness', 'marks', 'specificfeedback', 'generalfeedback', return array('correctness', 'marks', 'specificfeedback', 'generalfeedback',
'rightanswer'); 'rightanswer');
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
...@@ -45,10 +45,6 @@ require_once(dirname(__FILE__) . '/../immediatefeedback/behaviour.php'); ...@@ -45,10 +45,6 @@ require_once(dirname(__FILE__) . '/../immediatefeedback/behaviour.php');
class qbehaviour_immediatecbm extends qbehaviour_immediatefeedback { class qbehaviour_immediatecbm extends qbehaviour_immediatefeedback {
const IS_ARCHETYPAL = true; const IS_ARCHETYPAL = true;
public static function get_required_behaviours() {
return array('immediatefeedback', 'deferredcbm');
}
public function get_min_fraction() { public function get_min_fraction() {
return question_cbm::adjust_fraction(parent::get_min_fraction(), question_cbm::HIGH); return question_cbm::adjust_fraction(parent::get_min_fraction(), question_cbm::HIGH);
} }
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
...@@ -64,10 +64,6 @@ require_once(dirname(__FILE__) . '/../interactive/behaviour.php'); ...@@ -64,10 +64,6 @@ require_once(dirname(__FILE__) . '/../interactive/behaviour.php');
class qbehaviour_interactivecountback extends qbehaviour_interactive { class qbehaviour_interactivecountback extends qbehaviour_interactive {
const IS_ARCHETYPAL = false; const IS_ARCHETYPAL = false;
public static function get_required_behaviours() {
return array('interactive');
}
public function required_question_definition_type() { public function required_question_definition_type() {
return 'question_automatically_gradable_with_countback'; return 'question_automatically_gradable_with_countback';
} }
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
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
);
...@@ -328,17 +328,6 @@ abstract class question_engine { ...@@ -328,17 +328,6 @@ abstract class question_engine {
return get_string('pluginname', 'qbehaviour_' . $behaviour); 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. * @return array all the file area names that may contain response files.
*/ */
......