mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 14:02:32 +02:00
question bank: MDL-16412 Allow admins to enable/disable of each question type
This commit is contained in:
parent
c65562d30f
commit
a781921fd0
107
admin/qtypes.php
107
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[] = '<a href="' . admin_url('roles/manage.php?action=view&roleid=' . $role->id) .
|
||||
'" title="' . get_string('editrole', 'role') . '">' . $role->name . '</a>';
|
||||
// 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[] = '';
|
||||
}
|
||||
$rolelinks = implode(', ', $rolelinks);
|
||||
if (!$rolelinks) {
|
||||
$rolelinks = get_string('noroles', 'admin');
|
||||
}
|
||||
if ($hasoverrides) {
|
||||
$a = new stdClass;
|
||||
$a->roles = $rolelinks;
|
||||
$a->exceptions = '<a href="' . admin_url('report/capability/index.php?capability=' .
|
||||
$addcapability) . '#report" title = "' . get_string('showdetails', 'admin') . '">' .
|
||||
get_string('exceptions', 'admin') . '</a>';
|
||||
$rolelinks = get_string('roleswithexceptions', 'admin', $a) ;
|
||||
}
|
||||
if (empty($adderroles) && !$hasoverrides) {
|
||||
$rolelinks = '<span class="disabled">' . $rolelinks . '</span>';
|
||||
}
|
||||
$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 = '<form action="' . admin_url('qtypes.php') . '" method="post"><div>';
|
||||
$html .= '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
|
||||
$html .= '<input type="image" name="' . $action . '" value="' . $qtypename .
|
||||
'" src="' . $CFG->pixpath . '/i/' . $icon . '.gif" alt="' . $alt . '" title="' . $tip . '" />';
|
||||
$html .= '</div></form>';
|
||||
return $html;
|
||||
}
|
||||
?>
|
||||
|
@ -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 <em>$a->user</em> on <em>$a->time</em>';
|
||||
@ -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!';
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user