function test_question_sort_qtype_array() { $config = new stdClass(); $config->multichoice_sortorder = '1'; $config->calculated_sortorder = '2'; $qtypes = array('frog' => 'toad', 'calculated' => 'newt', 'multichoice' => 'eft'); $this->assertEqual(question_sort_qtype_array($qtypes), array('multichoice' => 'eft', 'calculated' => 'newt', 'frog' => 'toad')); }
/** * An array of question type names translated to the user's language, suitable for use when * creating a drop-down menu of options. * * Long-time Moodle programmers will realise that this replaces the old $QTYPE_MENU array. * The array returned will only hold the names of all the question types that the user should * be able to create directly. Some internal question types like random questions are excluded. * * @return array an array of question type names translated to the user's language. */ function question_type_menu() { global $QTYPES; static $menuoptions = null; if (is_null($menuoptions)) { $config = get_config('question'); $menuoptions = array(); foreach ($QTYPES as $name => $qtype) { // Get the name if this qtype is enabled. $menuname = $qtype->menu_name(); $enabledvar = $name . '_disabled'; if ($menuname && !isset($config->{$enabledvar})) { $menuoptions[$name] = $menuname; } } $menuoptions = question_sort_qtype_array($menuoptions, $config); } return $menuoptions; }
$needed[$reqtype] = true; } } foreach ($counts as $qtypename => $count) { if (!isset($QTYPES[$qtypename])) { $counts['missingtype']->numquestions += $count->numquestions - $count->numhidden; $counts['missingtype']->numhidden += $count->numhidden; } } /// Work of the correct sort order. $config = get_config('question'); $sortedqtypes = array(); foreach ($QTYPES as $qtypename => $qtype) { $sortedqtypes[$qtypename] = $qtype->local_name(); } $sortedqtypes = question_sort_qtype_array($sortedqtypes, $config); /// 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()) {