From a781921fd0b871c0b7857bd63992943d37ec043e Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 25 Feb 2009 09:31:49 +0000 Subject: [PATCH] question bank: MDL-16412 Allow admins to enable/disable of each question type --- admin/qtypes.php | 107 +++++++++++++++++++------------ lang/en_utf8/question.php | 4 ++ lib/questionlib.php | 4 +- theme/standard/styles_layout.css | 8 ++- 4 files changed, 81 insertions(+), 42 deletions(-) diff --git a/admin/qtypes.php b/admin/qtypes.php index f9f789596e..de4a3a7e9f 100644 --- a/admin/qtypes.php +++ b/admin/qtypes.php @@ -41,10 +41,34 @@ } } - // Process any actions. - $delete = optional_param('delete', '', PARAM_SAFEDIR); - $confirm = optional_param('confirm', '', PARAM_BOOL); - if (!empty($delete) and confirm_sesskey()) { + // Process actions ========================================================= + + // Disable. + if (($disable = optional_param('disable', '', PARAM_SAFEDIR)) && confirm_sesskey()) { + if (!isset($QTYPES[$disable])) { + print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $disable); + } + + set_config($disable . '_disabled', 1, 'question'); + redirect(admin_url('qtypes.php')); + } + + // Enable. + if (($enable = optional_param('enable', '', PARAM_SAFEDIR)) && confirm_sesskey()) { + if (!isset($QTYPES[$enable])) { + print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $enable); + } + + if (!$QTYPES[$enable]->menu_name()) { + print_error('cannotenable', 'question', admin_url('qtypes.php'), $enable); + } + + unset_config($enable . '_disabled', 'question'); + redirect(admin_url('qtypes.php')); + } + + // Delete. + if ($delete = optional_param('delete', '', PARAM_SAFEDIR) && confirm_sesskey()) { // Check it is OK to delete this question type. if ($delete == 'missingtype') { print_error('cannotdeletemissingqtype', 'admin', admin_url('qtypes.php')); @@ -64,7 +88,7 @@ } // If not yet confirmed, display a confirmation message. - if (!$confirm) { + if (!optional_param('confirm', '', PARAM_BOOL)) { $qytpename = $QTYPES[$delete]->local_name(); admin_externalpage_print_header(); print_heading(get_string('deleteqtypeareyousure', 'admin', $qytpename)); @@ -85,12 +109,7 @@ } // Then the tables themselves - if (!drop_plugin_tables($delete, $QTYPES[$delete]->plugin_dir() . '/db/install.xml', false)) { - - } - - // Delete the capabilities that were defined by this module - capabilities_cleanup('qtype/' . $delete); + drop_plugin_tables($delete, $QTYPES[$delete]->plugin_dir() . '/db/install.xml', false); // Remove event handlers and dequeue pending events events_uninstall('qtype/' . $delete); @@ -103,6 +122,8 @@ exit; } + // End of process actions ================================================== + /// Print the page heading. admin_externalpage_print_header(); print_heading(get_string('manageqtypes', 'admin')); @@ -112,13 +133,14 @@ $table->define_columns(array('questiontype', 'numquestions', 'version', 'requires', 'availableto', 'delete', 'settings')); $table->define_headers(array(get_string('questiontype', 'admin'), get_string('numquestions', 'admin'), - get_string('version'), get_string('requires', 'admin'), get_string('availableto', 'admin'), + get_string('version'), get_string('requires', 'admin'), get_string('availableq', 'question'), get_string('delete'), get_string('settings'))); $table->set_attribute('id', 'qtypes'); $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); $table->setup(); /// Add a row for each question type. + $createabletypes = question_type_menu(); foreach ($QTYPES as $qtypename => $qtype) { $row = array(); @@ -165,33 +187,17 @@ $row[] = ''; } - // Who is allowed to create this question type. -// TODO $addcapability = 'qtype/' . $qtypename . ':add'; - $addcapability = 'moodle/question:add'; - $adderroles = get_roles_with_capability($addcapability, CAP_ALLOW, $systemcontext); - $hasoverrides = $DB->record_exists_select('role_capabilities', - 'capability = ? AND contextid <> ?', array($addcapability, $systemcontext->id)); - $rolelinks = array(); - foreach ($adderroles as $role) { - $rolelinks[] = '' . $role->name . ''; - } - $rolelinks = implode(', ', $rolelinks); - if (!$rolelinks) { - $rolelinks = get_string('noroles', 'admin'); - } - if ($hasoverrides) { - $a = new stdClass; - $a->roles = $rolelinks; - $a->exceptions = '' . - get_string('exceptions', 'admin') . ''; - $rolelinks = get_string('roleswithexceptions', 'admin', $a) ; - } - if (empty($adderroles) && !$hasoverrides) { - $rolelinks = '' . $rolelinks . ''; + // Are people allowed to create new questions of this type? + $rowclass = ''; + if ($qtype->menu_name()) { + $createable = isset($createabletypes[$qtypename]); + $row[] = enable_disable_button($qtypename, $createable); + if (!$createable) { + $rowclass = 'dimmed_text'; + } + } else { + $row[] = ''; } - $row[] = $rolelinks; // Delete link, if available. if ($needed[$qtypename]) { @@ -210,10 +216,10 @@ $row[] = ''; } - $table->add_data($row); + $table->add_data($row, $rowclass); } - $table->print_html(); + $table->finish_output(); admin_externalpage_print_footer(); @@ -221,4 +227,25 @@ function admin_url($endbit) { global $CFG; return $CFG->wwwroot . '/' . $CFG->admin . '/' . $endbit; } + +function enable_disable_button($qtypename, $createable) { + global $CFG; + if ($createable) { + $action = 'disable'; + $tip = get_string('disable'); + $alt = get_string('enabled', 'question'); + $icon = 'hide'; + } else { + $action = 'enable'; + $tip = get_string('enable'); + $alt = get_string('disabled', 'question'); + $icon = 'show'; + } + $html = '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + return $html; +} ?> diff --git a/lang/en_utf8/question.php b/lang/en_utf8/question.php index 463a30513a..fb936e2e5d 100644 --- a/lang/en_utf8/question.php +++ b/lang/en_utf8/question.php @@ -2,6 +2,7 @@ // question.php - created with Moodle 1.8 dev $string['adminreport'] = 'Report on possible problems in your question database.'; +$string['availableq'] = 'Available?'; $string['badbase'] = 'Bad base before **: $a**'; $string['broken'] = 'This is a \"broken link\", it points to a nonexistent file.'; $string['byandon'] = 'by $a->user on $a->time'; @@ -12,6 +13,7 @@ $string['cannotcreaterelation'] = 'Unable to create relation to dataset $a[0] $a $string['cannotcreatepath'] = 'Cannot create path: $a'; $string['cannotcopybackup'] = 'Could not copy backup file'; $string['cannotdeletecate'] = 'You can\'t delete that category it is the default category for this context.'; +$string['cannotenable'] = 'Question type $a cannot be created directly.'; $string['cannotfindcate'] = 'Could not find category record'; $string['cannotinsertitem'] = 'Unable to insert dataset item $a[0] with $a[1] for $a[2]'; $string['cannotinsert'] = 'Error: Unable to insert dataset item'; @@ -70,10 +72,12 @@ $string['createdmodifiedheader'] = 'Created / Last Saved'; $string['defaultfor'] = 'Default for $a'; $string['defaultinfofor'] = 'The default category for questions shared in context \'$a\'.'; $string['deletecoursecategorywithquestions'] = 'There are questions in the question bank associated with this course category. If you proceed, they will be deleted. You may wish to move them first, using the question bank interface.'; +$string['disabled'] = 'Disabled'; $string['disterror'] = 'The distribution $a caused problems'; $string['donothing']= 'Don\'t copy or move files or change links.'; $string['editingcategory'] = 'Editing a category'; $string['editingquestion'] = 'Editing a question'; +$string['enabled'] = 'Enabled'; $string['erroraccessingcontext'] = 'Cannot access context'; $string['errordeletingquestionsfromcategory'] = 'Error deleting questions from category $a.'; $string['errorduringpre'] = 'Error occurred during pre-processing!'; diff --git a/lib/questionlib.php b/lib/questionlib.php index 565ccfef1a..16302f2a0b 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -169,10 +169,12 @@ function question_type_menu() { global $QTYPES; static $menu_options = null; if (is_null($menu_options)) { + $disbled = get_config('question'); $menu_options = array(); foreach ($QTYPES as $name => $qtype) { $menuname = $qtype->menu_name(); - if ($menuname) { + $configname = $name . '_disabled'; + if ($menuname && !isset($disbled->$configname)) { $menu_options[$name] = $menuname; } } diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index e6863fb843..a5b0efa3d5 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -1073,9 +1073,15 @@ body#admin-modules table.generaltable td.c0 #admin-report-questioninstances-index #settingsform p { margin-bottom: 0; } -#admin-qtypes .cell.c4 { +#admin-qtypes .cell.c3 { font-size: 0.7em; } +#admin-qtypes .cell { + text-align: center; +} +#admin-qtypes .cell.c0 { + text-align: left; +} #admin-roles-allowassign .buttons, #admin-roles-allowoverride .buttons, #admin-roles-manage .buttons, -- 2.39.5