From 103928da0bbd46f5c7b43ca2d7dacd9d0bb30149 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 29 Apr 2013 19:04:51 +0100 Subject: [PATCH] MDL-39412 question behaviours: hide manual graded option The ability to set all your quiz questions to require manual grading is an interesting possibility, but practically almost useless. If you set that accidentally, then you are badly stuck. There is no way to fix it after the students have answered the quiz. Therefore, we should set the config option to hide that option from the UI. We do this for all Moodle sites as part of the upgrade, not just for new installs. If any admin wants to re-enable this, they can later. --- .../behaviour/manualgraded/db/install.php | 49 ++++++++++++++ .../behaviour/manualgraded/db/upgrade.php | 64 +++++++++++++++++++ question/behaviour/manualgraded/version.php | 2 +- 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 question/behaviour/manualgraded/db/install.php create mode 100644 question/behaviour/manualgraded/db/upgrade.php diff --git a/question/behaviour/manualgraded/db/install.php b/question/behaviour/manualgraded/db/install.php new file mode 100644 index 00000000000..78187699d4b --- /dev/null +++ b/question/behaviour/manualgraded/db/install.php @@ -0,0 +1,49 @@ +. + +/** + * Post-install script for manual graded question behaviour. + * @package qbehaviour_manualgraded + * @copyright 2013 The Open Universtiy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +defined('MOODLE_INTERNAL') || die(); + + +/** + * Post-install script + */ +function xmldb_qbehaviour_manualgraded_install() { + + // Hide the manualgraded behaviour from the list of behaviours that users + // can select in the user-interface. If a user accidentally chooses manual + // graded behaviour for a quiz, there is no way to get the questions automatically + // graded after the student has answered them. If teachers really want to do + // this they can ask their admin to enable it on the manage behaviours + // screen in the UI. + $disabledbehaviours = get_config('question', 'disabledbehaviours'); + if (!empty($disabledbehaviours)) { + $disabledbehaviours = explode(',', $disabledbehaviours); + } else { + $disabledbehaviours = array(); + } + if (array_search('manualgraded', $disabledbehaviours) === false) { + $disabledbehaviours[] = 'manualgraded'; + set_config('disabledbehaviours', implode(',', $disabledbehaviours), 'question'); + } +} diff --git a/question/behaviour/manualgraded/db/upgrade.php b/question/behaviour/manualgraded/db/upgrade.php new file mode 100644 index 00000000000..9c22cfb4c8d --- /dev/null +++ b/question/behaviour/manualgraded/db/upgrade.php @@ -0,0 +1,64 @@ +. + +/** + * Post-install script for the manual graded question behaviour. + * + * @package qbehaviour_manualgraded + * @copyright 2013 The Open Universtiy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +defined('MOODLE_INTERNAL') || die(); + + +/** + * Manual graded question behaviour upgrade code. + */ +function xmldb_qbehaviour_manualgraded_upgrade($oldversion) { + global $DB; + + $dbman = $DB->get_manager(); + + // Moodle v2.4.0 release upgrade line + // Put any upgrade step following this + + if ($oldversion < 2013050200) { + // Hide the manualgraded behaviour from the list of behaviours that users + // can select in the user-interface. If a user accidentally chooses manual + // graded behaviour for a quiz, there is no way to get the questions automatically + // graded after the student has answered them. If teachers really want to do + // this they can ask their admin to enable it on the manage behaviours + // screen in the UI. + $disabledbehaviours = get_config('question', 'disabledbehaviours'); + if (!empty($disabledbehaviours)) { + $disabledbehaviours = explode(',', $disabledbehaviours); + } else { + $disabledbehaviours = array(); + } + if (array_search('manualgraded', $disabledbehaviours) === false) { + $disabledbehaviours[] = 'manualgraded'; + set_config('disabledbehaviours', implode(',', $disabledbehaviours), 'question'); + } + + // Manual graded question behaviour savepoint reached. + upgrade_plugin_savepoint(true, 2013050200, 'qbehaviour', 'manualgraded'); + } + + return true; +} + diff --git a/question/behaviour/manualgraded/version.php b/question/behaviour/manualgraded/version.php index c53f90f8ee4..c90df4be51d 100644 --- a/question/behaviour/manualgraded/version.php +++ b/question/behaviour/manualgraded/version.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'qbehaviour_manualgraded'; -$plugin->version = 2013050100; +$plugin->version = 2013050200; $plugin->requires = 2013050100;