]> git.mjollnir.org Git - moodle.git/commitdiff
question bank: MDL-16412 Allow admins to enable/disable of each question type
authortjhunt <tjhunt>
Wed, 25 Feb 2009 09:31:49 +0000 (09:31 +0000)
committertjhunt <tjhunt>
Wed, 25 Feb 2009 09:31:49 +0000 (09:31 +0000)
admin/qtypes.php
lang/en_utf8/question.php
lib/questionlib.php
theme/standard/styles_layout.css

index f9f789596e225f65ab2f7465066e2a5188685f10..de4a3a7e9f50eb127685f2e9fd6b4040894a4bad 100644 (file)
         }
     }
 
-    // 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));
         }
 
         // 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);
         exit;
     }
 
+    // End of process actions ==================================================
+
 /// Print the page heading.
     admin_externalpage_print_header();
     print_heading(get_string('manageqtypes', 'admin'));
     $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();
 
             $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&amp;roleid=' . $role->id) .
-                    '" title="' . get_string('editrole', 'role') . '">' . $role->name . '</a>';
-        }
-        $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>';
+        // 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]) {
             $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;
+}
 ?>
index 463a30513a34e0b940f853f058aa2cc97e900f66..fb936e2e5d17d367ab41c9511b056d445ef835d1 100644 (file)
@@ -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!';
index 565ccfef1a652d5caabfb08f865f7283d000809d..16302f2a0b5addd707ebcb157d25254d1db467bf 100644 (file)
@@ -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;
             }
         }
index e6863fb843b23253ffb596f01c77c01d13333881..a5b0efa3d5112d1ec1cace6719bec5db6af18a0d 100644 (file)
@@ -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,