MDL-20636 Remove all references to global $QTYPES.
Except in the question types that have not yet been converted to the new question engine.
This commit is contained in:
+1
-1
@@ -622,7 +622,7 @@ class generator {
|
||||
require_once($CFG->libdir .'/questionlib.php');
|
||||
require_once($CFG->dirroot .'/mod/quiz/editlib.php');
|
||||
$questions = array();
|
||||
$questionsmenu = question_type_menu();
|
||||
$questionsmenu = question_bank::get_creatable_qtypes();
|
||||
$questiontypes = array();
|
||||
foreach ($questionsmenu as $qtype => $qname) {
|
||||
$questiontypes[] = $qtype;
|
||||
|
||||
+250
-231
@@ -1,277 +1,296 @@
|
||||
<?php
|
||||
// Allows the admin to manage question types.
|
||||
|
||||
require_once(dirname(__FILE__) . '/../config.php');
|
||||
require_once($CFG->libdir . '/questionlib.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/tablelib.php');
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/// Check permissions.
|
||||
require_login();
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
require_capability('moodle/question:config', $systemcontext);
|
||||
$canviewreports = has_capability('report/questioninstances:view', $systemcontext);
|
||||
/**
|
||||
* Allows the admin to manage question types.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage questionbank
|
||||
* @copyright 2008 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
admin_externalpage_setup('manageqtypes');
|
||||
|
||||
$qtypes = question_bank::get_all_qtypes();
|
||||
require_once(dirname(__FILE__) . '/../config.php');
|
||||
require_once($CFG->libdir . '/questionlib.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/tablelib.php');
|
||||
|
||||
/// Get some data we will need - question counts and which types are needed.
|
||||
$counts = $DB->get_records_sql("
|
||||
SELECT qtype, COUNT(1) as numquestions, SUM(hidden) as numhidden
|
||||
FROM {question} GROUP BY qtype", array());
|
||||
$needed = array();
|
||||
foreach ($qtypes as $qtypename => $qtype) {
|
||||
if (!isset($counts[$qtypename])) {
|
||||
$counts[$qtypename] = new stdClass;
|
||||
$counts[$qtypename]->numquestions = 0;
|
||||
$counts[$qtypename]->numhidden = 0;
|
||||
}
|
||||
$needed[$qtypename] = $counts[$qtypename]->numquestions > 0;
|
||||
$counts[$qtypename]->numquestions -= $counts[$qtypename]->numhidden;
|
||||
// Check permissions.
|
||||
require_login();
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
require_capability('moodle/question:config', $systemcontext);
|
||||
$canviewreports = has_capability('report/questioninstances:view', $systemcontext);
|
||||
|
||||
admin_externalpage_setup('manageqtypes');
|
||||
|
||||
$qtypes = question_bank::get_all_qtypes();
|
||||
|
||||
// Get some data we will need - question counts and which types are needed.
|
||||
$counts = $DB->get_records_sql("
|
||||
SELECT qtype, COUNT(1) as numquestions, SUM(hidden) as numhidden
|
||||
FROM {question} GROUP BY qtype", array());
|
||||
$needed = array();
|
||||
foreach ($qtypes as $qtypename => $qtype) {
|
||||
if (!isset($counts[$qtypename])) {
|
||||
$counts[$qtypename] = new stdClass;
|
||||
$counts[$qtypename]->numquestions = 0;
|
||||
$counts[$qtypename]->numhidden = 0;
|
||||
}
|
||||
$needed['missingtype'] = true; // The system needs the missing question type.
|
||||
foreach ($qtypes as $qtypename => $qtype) {
|
||||
foreach ($qtype->requires_qtypes() as $reqtype) {
|
||||
$needed[$reqtype] = true;
|
||||
}
|
||||
$needed[$qtypename] = $counts[$qtypename]->numquestions > 0;
|
||||
$counts[$qtypename]->numquestions -= $counts[$qtypename]->numhidden;
|
||||
}
|
||||
$needed['missingtype'] = true; // The system needs the missing question type.
|
||||
foreach ($qtypes as $qtypename => $qtype) {
|
||||
foreach ($qtype->requires_qtypes() as $reqtype) {
|
||||
$needed[$reqtype] = true;
|
||||
}
|
||||
foreach ($counts as $qtypename => $count) {
|
||||
if (!isset($qtypes[$qtypename])) {
|
||||
$counts['missingtype']->numquestions += $count->numquestions - $count->numhidden;
|
||||
$counts['missingtype']->numhidden += $count->numhidden;
|
||||
}
|
||||
}
|
||||
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_bank::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', new moodle_url('/admin/qtypes.php'), $disable);
|
||||
}
|
||||
|
||||
/// 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);
|
||||
set_config($disable . '_disabled', 1, 'question');
|
||||
redirect(admin_url('qtypes.php'));
|
||||
}
|
||||
|
||||
/// 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', new moodle_url('/admin/qtypes.php'), $enable);
|
||||
}
|
||||
|
||||
// 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'));
|
||||
if (!$qtypes[$enable]->menu_name()) {
|
||||
print_error('cannotenable', 'question', new moodle_url('/admin/qtypes.php'), $enable);
|
||||
}
|
||||
|
||||
// Move up in order.
|
||||
if (($up = optional_param('up', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
|
||||
if (!isset($qtypes[$up])) {
|
||||
print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $up);
|
||||
}
|
||||
unset_config($enable . '_disabled', 'question');
|
||||
redirect(new moodle_url('/admin/qtypes.php'));
|
||||
}
|
||||
|
||||
$neworder = question_reorder_qtypes($sortedqtypes, $up, -1);
|
||||
question_save_qtype_order($neworder, $config);
|
||||
redirect(admin_url('qtypes.php'));
|
||||
// Move up in order.
|
||||
if (($up = optional_param('up', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
|
||||
if (!isset($qtypes[$up])) {
|
||||
print_error('unknownquestiontype', 'question', new moodle_url('/admin/qtypes.php'), $up);
|
||||
}
|
||||
|
||||
// Move down in order.
|
||||
if (($down = optional_param('down', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
|
||||
if (!isset($qtypes[$down])) {
|
||||
print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $down);
|
||||
}
|
||||
$neworder = question_reorder_qtypes($sortedqtypes, $up, -1);
|
||||
question_save_qtype_order($neworder, $config);
|
||||
redirect(new moodle_url('/admin/qtypes.php'));
|
||||
}
|
||||
|
||||
$neworder = question_reorder_qtypes($sortedqtypes, $down, +1);
|
||||
question_save_qtype_order($neworder, $config);
|
||||
redirect(admin_url('qtypes.php'));
|
||||
// Move down in order.
|
||||
if (($down = optional_param('down', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
|
||||
if (!isset($qtypes[$down])) {
|
||||
print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $down);
|
||||
}
|
||||
|
||||
// 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'));
|
||||
}
|
||||
$neworder = question_reorder_qtypes($sortedqtypes, $down, +1);
|
||||
question_save_qtype_order($neworder, $config);
|
||||
redirect(new moodle_url('/admin/qtypes.php'));
|
||||
}
|
||||
|
||||
if (!isset($qtypes[$delete])) {
|
||||
print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $delete);
|
||||
}
|
||||
// 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', new moodle_url('/admin/qtypes.php'));
|
||||
}
|
||||
|
||||
if (!isset($qtypes[$delete])) {
|
||||
print_error('unknownquestiontype', 'question', new moodle_url('/admin/qtypes.php'), $delete);
|
||||
}
|
||||
|
||||
$qtypename = $qtypes[$delete]->local_name();
|
||||
if ($counts[$delete]->numquestions + $counts[$delete]->numhidden > 0) {
|
||||
print_error('cannotdeleteqtypeinuse', 'admin', new moodle_url('/admin/qtypes.php'), $qtypename);
|
||||
}
|
||||
|
||||
if ($needed[$delete] > 0) {
|
||||
print_error('cannotdeleteqtypeneeded', 'admin', new moodle_url('/admin/qtypes.php'), $qtypename);
|
||||
}
|
||||
|
||||
// If not yet confirmed, display a confirmation message.
|
||||
if (!optional_param('confirm', '', PARAM_BOOL)) {
|
||||
$qtypename = $qtypes[$delete]->local_name();
|
||||
if ($counts[$delete]->numquestions + $counts[$delete]->numhidden > 0) {
|
||||
print_error('cannotdeleteqtypeinuse', 'admin', admin_url('qtypes.php'), $qtypename);
|
||||
}
|
||||
|
||||
if ($needed[$delete] > 0) {
|
||||
print_error('cannotdeleteqtypeneeded', 'admin', admin_url('qtypes.php'), $qtypename);
|
||||
}
|
||||
|
||||
// If not yet confirmed, display a confirmation message.
|
||||
if (!optional_param('confirm', '', PARAM_BOOL)) {
|
||||
$qtypename = $qtypes[$delete]->local_name();
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('deleteqtypeareyousure', 'admin', $qtypename));
|
||||
echo $OUTPUT->confirm(get_string('deleteqtypeareyousuremessage', 'admin', $qtypename),
|
||||
admin_url('qtypes.php?delete=' . $delete . '&confirm=1'),
|
||||
admin_url('qtypes.php'));
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Do the deletion.
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('deletingqtype', 'admin', $qtypename));
|
||||
|
||||
// Delete any configuration records.
|
||||
if (!unset_all_config_for_plugin('qtype_' . $delete)) {
|
||||
echo $OUTPUT->notification(get_string('errordeletingconfig', 'admin', 'qtype_' . $delete));
|
||||
}
|
||||
unset_config($delete . '_disabled', 'question');
|
||||
unset_config($delete . '_sortorder', 'question');
|
||||
|
||||
// Then the tables themselves
|
||||
drop_plugin_tables($delete, $qtypes[$delete]->plugin_dir() . '/db/install.xml', false);
|
||||
|
||||
// Remove event handlers and dequeue pending events
|
||||
events_uninstall('qtype/' . $delete);
|
||||
|
||||
$a->qtype = $qtypename;
|
||||
$a->directory = $qtypes[$delete]->plugin_dir();
|
||||
echo $OUTPUT->box(get_string('qtypedeletefiles', 'admin', $a), 'generalbox', 'notice');
|
||||
echo $OUTPUT->continue_button(admin_url('qtypes.php'));
|
||||
echo $OUTPUT->heading(get_string('deleteqtypeareyousure', 'admin', $qtypename));
|
||||
echo $OUTPUT->confirm(get_string('deleteqtypeareyousuremessage', 'admin', $qtypename),
|
||||
new moodle_url('/admin/qtypes.php', array('delete' => $delete, 'confirm' => 1)),
|
||||
new moodle_url('/admin/qtypes.php'));
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// End of process actions ==================================================
|
||||
|
||||
/// Print the page heading.
|
||||
// Do the deletion.
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('manageqtypes', 'admin'));
|
||||
echo $OUTPUT->heading(get_string('deletingqtype', 'admin', $qtypename));
|
||||
|
||||
/// Set up the table.
|
||||
$table = new flexible_table('qtypeadmintable');
|
||||
$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('availableq', 'question'),
|
||||
get_string('delete'), get_string('settings')));
|
||||
$table->set_attribute('id', 'qtypes');
|
||||
$table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
|
||||
$table->setup();
|
||||
// Delete any configuration records.
|
||||
if (!unset_all_config_for_plugin('qtype_' . $delete)) {
|
||||
echo $OUTPUT->notification(get_string('errordeletingconfig', 'admin', 'qtype_' . $delete));
|
||||
}
|
||||
unset_config($delete . '_disabled', 'question');
|
||||
unset_config($delete . '_sortorder', 'question');
|
||||
|
||||
/// Add a row for each question type.
|
||||
$createabletypes = question_type_menu();
|
||||
foreach ($sortedqtypes as $qtypename => $localname) {
|
||||
$qtype = $qtypes[$qtypename];
|
||||
$row = array();
|
||||
// Then the tables themselves
|
||||
drop_plugin_tables($delete, $qtypes[$delete]->plugin_dir() . '/db/install.xml', false);
|
||||
|
||||
// Question icon and name.
|
||||
$fakequestion = new stdClass;
|
||||
$fakequestion->qtype = $qtypename;
|
||||
$icon = print_question_icon($fakequestion, true);
|
||||
$row[] = $icon . ' ' . $localname;
|
||||
// Remove event handlers and dequeue pending events
|
||||
events_uninstall('qtype/' . $delete);
|
||||
|
||||
// Number of questions of this type.
|
||||
if ($counts[$qtypename]->numquestions + $counts[$qtypename]->numhidden > 0) {
|
||||
if ($counts[$qtypename]->numhidden > 0) {
|
||||
$strcount = get_string('numquestionsandhidden', 'admin', $counts[$qtypename]);
|
||||
} else {
|
||||
$strcount = $counts[$qtypename]->numquestions;
|
||||
}
|
||||
if ($canviewreports) {
|
||||
$row[] = '<a href="' . admin_url('/report/questioninstances/index.php?qtype=' . $qtypename) .
|
||||
'" title="' . get_string('showdetails', 'admin') . '">' . $strcount . '</a>';
|
||||
} else {
|
||||
$strcount;
|
||||
}
|
||||
$a->qtype = $qtypename;
|
||||
$a->directory = $qtypes[$delete]->plugin_dir();
|
||||
echo $OUTPUT->box(get_string('qtypedeletefiles', 'admin', $a), 'generalbox', 'notice');
|
||||
echo $OUTPUT->continue_button(new moodle_url('/admin/qtypes.php'));
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// End of process actions ==================================================
|
||||
|
||||
// Print the page heading.
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('manageqtypes', 'admin'));
|
||||
|
||||
// Set up the table.
|
||||
$table = new flexible_table('qtypeadmintable');
|
||||
$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('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_bank::get_creatable_qtypes();
|
||||
foreach ($sortedqtypes as $qtypename => $localname) {
|
||||
$qtype = $qtypes[$qtypename];
|
||||
$row = array();
|
||||
|
||||
// Question icon and name.
|
||||
$fakequestion = new stdClass;
|
||||
$fakequestion->qtype = $qtypename;
|
||||
$icon = print_question_icon($fakequestion, true);
|
||||
$row[] = $icon . ' ' . $localname;
|
||||
|
||||
// Number of questions of this type.
|
||||
if ($counts[$qtypename]->numquestions + $counts[$qtypename]->numhidden > 0) {
|
||||
if ($counts[$qtypename]->numhidden > 0) {
|
||||
$strcount = get_string('numquestionsandhidden', 'admin', $counts[$qtypename]);
|
||||
} else {
|
||||
$row[] = 0;
|
||||
$strcount = $counts[$qtypename]->numquestions;
|
||||
}
|
||||
|
||||
// Question version number.
|
||||
$version = get_config('qtype_' . $qtypename, 'version');
|
||||
if ($version) {
|
||||
$row[] = $version;
|
||||
if ($canviewreports) {
|
||||
$row[] = '<a href="' . new moodle_url('/admin/report/questioninstances/index.php', array('qtype' => $qtypename)) .
|
||||
'" title="' . get_string('showdetails', 'admin') . '">' . $strcount . '</a>';
|
||||
} else {
|
||||
$row[] = '<span class="disabled">' . get_string('nodatabase', 'admin') . '</span>';
|
||||
$strcount;
|
||||
}
|
||||
|
||||
// Other question types required by this one.
|
||||
$requiredtypes = $qtype->requires_qtypes();
|
||||
$strtypes = array();
|
||||
if (!empty($requiredtypes)) {
|
||||
foreach ($requiredtypes as $required) {
|
||||
$strtypes[] = $qtypes[$required]->local_name();
|
||||
}
|
||||
$row[] = implode(', ', $strtypes);
|
||||
} else {
|
||||
$row[] = '';
|
||||
}
|
||||
|
||||
// Are people allowed to create new questions of this type?
|
||||
$rowclass = '';
|
||||
if ($qtype->menu_name()) {
|
||||
$createable = isset($createabletypes[$qtypename]);
|
||||
$icons = enable_disable_button($qtypename, $createable);
|
||||
if (!$createable) {
|
||||
$rowclass = 'dimmed_text';
|
||||
}
|
||||
} else {
|
||||
$icons = '<img src="' . $OUTPUT->pix_url('spacer') . '" alt="" class="spacer" />';
|
||||
}
|
||||
|
||||
// Move icons.
|
||||
$icons .= icon_html('up', $qtypename, 't/up', get_string('up'), '');
|
||||
$icons .= icon_html('down', $qtypename, 't/down', get_string('down'), '');
|
||||
$row[] = $icons;
|
||||
|
||||
// Delete link, if available.
|
||||
if ($needed[$qtypename]) {
|
||||
$row[] = '';
|
||||
} else {
|
||||
$row[] = '<a href="' . admin_url('qtypes.php?delete=' . $qtypename .
|
||||
'&sesskey=' . sesskey()) . '" title="' .
|
||||
get_string('uninstallqtype', 'admin') . '">' . get_string('delete') . '</a>';
|
||||
}
|
||||
|
||||
// Settings link, if available.
|
||||
$settings = admin_get_root()->locate('qtypesetting' . $qtypename);
|
||||
if ($settings instanceof admin_externalpage) {
|
||||
$row[] = '<a href="' . $settings->url .
|
||||
'">' . get_string('settings') . '</a>';
|
||||
} else if ($settings instanceof admin_settingpage) {
|
||||
$row[] = '<a href="' . admin_url('settings.php?section=qtypesetting' . $qtypename) .
|
||||
'">' . get_string('settings') . '</a>';
|
||||
} else {
|
||||
$row[] = '';
|
||||
}
|
||||
|
||||
$table->add_data($row, $rowclass);
|
||||
} else {
|
||||
$row[] = 0;
|
||||
}
|
||||
|
||||
$table->finish_output();
|
||||
// Question version number.
|
||||
$version = get_config('qtype_' . $qtypename, 'version');
|
||||
if ($version) {
|
||||
$row[] = $version;
|
||||
} else {
|
||||
$row[] = '<span class="disabled">' . get_string('nodatabase', 'admin') . '</span>';
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
// Other question types required by this one.
|
||||
$requiredtypes = $qtype->requires_qtypes();
|
||||
$strtypes = array();
|
||||
if (!empty($requiredtypes)) {
|
||||
foreach ($requiredtypes as $required) {
|
||||
$strtypes[] = $qtypes[$required]->local_name();
|
||||
}
|
||||
$row[] = implode(', ', $strtypes);
|
||||
} else {
|
||||
$row[] = '';
|
||||
}
|
||||
|
||||
function admin_url($endbit) {
|
||||
global $CFG;
|
||||
return $CFG->wwwroot . '/' . $CFG->admin . '/' . $endbit;
|
||||
// Are people allowed to create new questions of this type?
|
||||
$rowclass = '';
|
||||
if ($qtype->menu_name()) {
|
||||
$createable = isset($createabletypes[$qtypename]);
|
||||
$icons = enable_disable_button($qtypename, $createable);
|
||||
if (!$createable) {
|
||||
$rowclass = 'dimmed_text';
|
||||
}
|
||||
} else {
|
||||
$icons = '<img src="' . $OUTPUT->pix_url('spacer') . '" alt="" class="spacer" />';
|
||||
}
|
||||
|
||||
// Move icons.
|
||||
$icons .= icon_html('up', $qtypename, 't/up', get_string('up'), '');
|
||||
$icons .= icon_html('down', $qtypename, 't/down', get_string('down'), '');
|
||||
$row[] = $icons;
|
||||
|
||||
// Delete link, if available.
|
||||
if ($needed[$qtypename]) {
|
||||
$row[] = '';
|
||||
} else {
|
||||
$row[] = '<a href="' . new moodle_url('/admin/qtypes.php', array('delete' => $qtypename,
|
||||
'sesskey' => sesskey())) . '" title="' .
|
||||
get_string('uninstallqtype', 'admin') . '">' . get_string('delete') . '</a>';
|
||||
}
|
||||
|
||||
// Settings link, if available.
|
||||
$settings = admin_get_root()->locate('qtypesetting' . $qtypename);
|
||||
if ($settings instanceof admin_externalpage) {
|
||||
$row[] = '<a href="' . $settings->url .
|
||||
'">' . get_string('settings') . '</a>';
|
||||
} else if ($settings instanceof admin_settingpage) {
|
||||
$row[] = '<a href="' . new moodle_url('/admin/settings.php', array('section' => 'qtypesetting' . $qtypename)) .
|
||||
'">' . get_string('settings') . '</a>';
|
||||
} else {
|
||||
$row[] = '';
|
||||
}
|
||||
|
||||
$table->add_data($row, $rowclass);
|
||||
}
|
||||
|
||||
$table->finish_output();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
function enable_disable_button($qtypename, $createable) {
|
||||
if ($createable) {
|
||||
return icon_html('disable', $qtypename, 'i/hide', get_string('enabled', 'question'), get_string('disable'));
|
||||
@@ -285,7 +304,7 @@ function icon_html($action, $qtypename, $icon, $alt, $tip) {
|
||||
if ($tip) {
|
||||
$tip = 'title="' . $tip . '" ';
|
||||
}
|
||||
$html = ' <form action="' . admin_url('qtypes.php') . '" method="post"><div>';
|
||||
$html = ' <form action="' . new moodle_url('/admin/qtypes.php') . '" method="post"><div>';
|
||||
$html .= '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
|
||||
$html .= '<input type="image" name="' . $action . '" value="' . $qtypename .
|
||||
'" src="' . $OUTPUT->pix_url($icon) . '" alt="' . $alt . '" ' . $tip . '/>';
|
||||
|
||||
@@ -22,8 +22,9 @@ echo $OUTPUT->header();
|
||||
add_to_log(SITEID, "admin", "report questioninstances", "report/questioninstances/index.php?qtype=$requestedqtype", $requestedqtype);
|
||||
|
||||
// Prepare the list of capabilities to choose from
|
||||
$qtypes = question_bank::get_all_qtypes();
|
||||
$qtypechoices = array();
|
||||
foreach ($QTYPES as $qtype) {
|
||||
foreach ($qtypes as $qtype) {
|
||||
$qtypechoices[$qtype->name()] = $qtype->local_name();
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ if ($requestedqtype) {
|
||||
|
||||
// Work out the bits needed for the SQL WHERE clauses.
|
||||
if ($requestedqtype == 'missingtype') {
|
||||
$othertypes = array_keys($QTYPES);
|
||||
$othertypes = array_keys($qtypes);
|
||||
$key = array_search('missingtype', $othertypes);
|
||||
unset($othertypes[$key]);
|
||||
list($sqlqtypetest, $params) = $DB->get_in_or_equal($othertypes, SQL_PARAMS_QM, '', false);
|
||||
@@ -58,7 +59,8 @@ if ($requestedqtype) {
|
||||
} else {
|
||||
$sqlqtypetest = 'WHERE qtype = ?';
|
||||
$params = array($requestedqtype);
|
||||
$title = get_string('reportforqtype', 'report_questioninstances', $QTYPES[$requestedqtype]->local_name());
|
||||
$title = get_string('reportforqtype', 'report_questioninstances',
|
||||
question_bank::get_qtype($requestedqtype)->local_name());
|
||||
}
|
||||
|
||||
// Get the question counts, and all the context information, for each
|
||||
|
||||
+11
-88
@@ -82,81 +82,6 @@ define("QUESTION_NUMANS_ADD", 3);
|
||||
*/
|
||||
define('QUESTION_PREVIEW_POPUP_OPTIONS', 'scrollbars=yes,resizable=yes,width=800,height=600');
|
||||
|
||||
/**
|
||||
* @global array holding question type objects
|
||||
* @deprecated
|
||||
*/
|
||||
global $QTYPES;
|
||||
$QTYPES = question_bank::get_all_qtypes();
|
||||
function question_register_questiontype() {
|
||||
// TODO kill this.
|
||||
}
|
||||
// TODO kill this.
|
||||
class default_questiontype {
|
||||
function plugin_dir() {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
static $menuoptions = null;
|
||||
if (is_null($menuoptions)) {
|
||||
$config = get_config('question');
|
||||
$menuoptions = array();
|
||||
foreach (question_bank::get_all_qtypes() as $name => $qtype) {
|
||||
$menuname = $qtype->menu_name();
|
||||
$enabledvar = $name . '_disabled';
|
||||
if ($menuname && !isset($config->$enabledvar)) {
|
||||
$menuoptions[$name] = $menuname;
|
||||
}
|
||||
}
|
||||
|
||||
$menuoptions = question_sort_qtype_array($menuoptions, $config);
|
||||
}
|
||||
return $menuoptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort an array of question type names according to the question type sort order stored in
|
||||
* config_plugins. Entries for which there is no xxx_sortorder defined will go
|
||||
* at the end, sorted according to textlib_get_instance()->asort($inarray).
|
||||
* @param $inarray an array $qtypename => $qtype->local_name().
|
||||
* @param $config get_config('question'), if you happen to have it around, to save one DB query.
|
||||
* @return array the sorted version of $inarray.
|
||||
*/
|
||||
function question_sort_qtype_array($inarray, $config = null) {
|
||||
if (is_null($config)) {
|
||||
$config = get_config('question');
|
||||
}
|
||||
|
||||
$sortorder = array();
|
||||
foreach ($inarray as $name => $notused) {
|
||||
$sortvar = $name . '_sortorder';
|
||||
if (isset($config->$sortvar)) {
|
||||
$sortorder[$config->$sortvar] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
ksort($sortorder);
|
||||
$outarray = array();
|
||||
foreach ($sortorder as $name) {
|
||||
$outarray[$name] = $inarray[$name];
|
||||
unset($inarray[$name]);
|
||||
}
|
||||
textlib_get_instance()->asort($inarray);
|
||||
return array_merge($outarray, $inarray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move one question type in a list of question types. If you try to move one element
|
||||
* off of the end, nothing will change.
|
||||
@@ -692,7 +617,7 @@ function question_delete_activity($cm, $feedback=true) {
|
||||
* @param integer $newcategoryid the id of the category to move to.
|
||||
*/
|
||||
function question_move_questions_to_category($questionids, $newcategoryid) {
|
||||
global $DB, $QTYPES;
|
||||
global $DB;
|
||||
|
||||
$newcontextid = $DB->get_field('question_categories', 'contextid',
|
||||
array('id' => $newcategoryid));
|
||||
@@ -704,8 +629,8 @@ function question_move_questions_to_category($questionids, $newcategoryid) {
|
||||
WHERE q.id $questionidcondition", $params);
|
||||
foreach ($questions as $question) {
|
||||
if ($newcontextid != $question->contextid) {
|
||||
$QTYPES[$question->qtype]->move_files($question->id,
|
||||
$question->contextid, $newcontextid);
|
||||
question_bank::get_qtype($question->qtype)->move_files(
|
||||
$question->id, $question->contextid, $newcontextid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -729,12 +654,12 @@ function question_move_questions_to_category($questionids, $newcategoryid) {
|
||||
* @param integer $newcontextid the new context id.
|
||||
*/
|
||||
function question_move_category_to_context($categoryid, $oldcontextid, $newcontextid) {
|
||||
global $DB, $QTYPES;
|
||||
global $DB;
|
||||
|
||||
$questionids = $DB->get_records_menu('question',
|
||||
array('category' => $categoryid), '', 'id,qtype');
|
||||
foreach ($questionids as $questionid => $qtype) {
|
||||
$QTYPES[$qtype]->move_files($questionid, $oldcontextid, $newcontextid);
|
||||
question_bank::get_qtype($qtype)->move_files($questionid, $oldcontextid, $newcontextid);
|
||||
}
|
||||
|
||||
$subcatids = $DB->get_records_menu('question_categories',
|
||||
@@ -851,12 +776,12 @@ function question_load_questions($questionids, $extrafields = '', $join = '') {
|
||||
* @param boolean $loadtags load the question tags from the tags table. Optional, default false.
|
||||
*/
|
||||
function _tidy_question($question, $loadtags = false) {
|
||||
global $CFG, $QTYPES;
|
||||
if (!array_key_exists($question->qtype, $QTYPES)) {
|
||||
$question->qtype = 'missingtype';
|
||||
$question->questiontext = '<p>' . get_string('warningmissingtype', 'quiz') . '</p>' . $question->questiontext;
|
||||
global $CFG;
|
||||
if (question_bank::is_qtype_installed($question->qtype)) {
|
||||
$question->questiontext = html_writer::tag('p', get_string('warningmissingtype',
|
||||
'qtype_missingtype')) . $question->questiontext;
|
||||
}
|
||||
$QTYPES[$question->qtype]->get_question_options($question);
|
||||
question_bank::get_qtype($question->qtype)->get_question_options($question);
|
||||
if (isset($question->_partiallyloaded)) {
|
||||
unset($question->_partiallyloaded);
|
||||
}
|
||||
@@ -940,9 +865,7 @@ function question_get_editing_head_contributions($question) {
|
||||
* Simply calls the question type specific save_question_options() method.
|
||||
*/
|
||||
function save_question_options($question) {
|
||||
global $QTYPES;
|
||||
|
||||
$QTYPES[$question->qtype]->save_question_options($question);
|
||||
question_bank::get_qtype($question->qtype)->save_question_options($question);
|
||||
}
|
||||
|
||||
/// CATEGORY FUNCTIONS /////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -41,22 +41,6 @@ class questionlib_test extends UnitTestCase {
|
||||
|
||||
public static $includecoverage = array('lib/questionlib.php');
|
||||
|
||||
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',
|
||||
));
|
||||
}
|
||||
|
||||
function test_question_reorder_qtypes() {
|
||||
$this->assertEqual(question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 't1', +1),
|
||||
array(0 => 't2', 1 => 't1', 2 => 't3'));
|
||||
|
||||
+50
-18
@@ -55,6 +55,15 @@ abstract class question_bank {
|
||||
|
||||
private static $questionconfig = null;
|
||||
|
||||
/**
|
||||
* @param string $qtypename a question type name, e.g. 'multichoice'.
|
||||
* @return bool whether that question type is installed in this Moodle.
|
||||
*/
|
||||
public static function is_qtype_installed($qtypename) {
|
||||
$plugindir = get_plugin_directory('qtype', $qtypename);
|
||||
return $plugindir && is_readable($plugindir . '/questiontype.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the question type class for a particular question type.
|
||||
* @param string $qtypename the question type name. For example 'multichoice' or 'shortanswer'.
|
||||
@@ -131,12 +140,47 @@ abstract class question_bank {
|
||||
try {
|
||||
$qtypes[$plugin] = self::get_qtype($plugin);
|
||||
} catch (Exception $e) {
|
||||
// TODO ingore, but reivew this later.
|
||||
// TODO ingore, but review this later.
|
||||
}
|
||||
}
|
||||
return $qtypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort an array of question types according to the order the admin set up,
|
||||
* and then alphabetically for the rest.
|
||||
* @param array qtype->name() => qtype->local_name().
|
||||
* @return array sorted array.
|
||||
*/
|
||||
public static function sort_qtype_array($qtypes, $config = null) {
|
||||
if (is_null($config)) {
|
||||
$config = self::get_config();
|
||||
}
|
||||
|
||||
$sortorder = array();
|
||||
$otherqtypes = array();
|
||||
foreach ($qtypes as $name => $localname) {
|
||||
$sortvar = $name . '_sortorder';
|
||||
if (isset($config->$sortvar)) {
|
||||
$sortorder[$config->$sortvar] = $name;
|
||||
} else {
|
||||
$otherqtypes[$name] = $localname;
|
||||
}
|
||||
}
|
||||
|
||||
ksort($sortorder);
|
||||
textlib_get_instance()->asort($otherqtypes);
|
||||
|
||||
$sortedqtypes = array();
|
||||
foreach ($sortorder as $name) {
|
||||
$sortedqtypes[$name] = $qtypes[$name];
|
||||
}
|
||||
foreach ($otherqtypes as $name => $notused) {
|
||||
$sortedqtypes[$name] = $qtypes[$name];
|
||||
}
|
||||
return $sortedqtypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array all the question types that users are allowed to create,
|
||||
* sorted into the preferred order set on the admin screen.
|
||||
@@ -145,29 +189,17 @@ abstract class question_bank {
|
||||
$config = self::get_config();
|
||||
$allqtypes = self::get_all_qtypes();
|
||||
|
||||
$sortorder = array();
|
||||
$otherqtypes = array();
|
||||
$qtypenames = array();
|
||||
foreach ($allqtypes as $name => $qtype) {
|
||||
if (!self::qtype_enabled($name)) {
|
||||
unset($allqtypes[$name]);
|
||||
continue;
|
||||
}
|
||||
$sortvar = $name . '_sortorder';
|
||||
if (isset($config->$sortvar)) {
|
||||
$sortorder[$config->$sortvar] = $name;
|
||||
} else {
|
||||
$otherqtypes[$name] = $qtype->local_name();
|
||||
if (self::qtype_enabled($name)) {
|
||||
$qtypenames[$name] = $qtype->local_name();
|
||||
}
|
||||
}
|
||||
|
||||
ksort($sortorder);
|
||||
textlib_get_instance()->asort($otherqtypes);
|
||||
$qtypenames = self::sort_qtype_array($qtypenames);
|
||||
|
||||
$creatableqtypes = array();
|
||||
foreach ($sortorder as $name) {
|
||||
$creatableqtypes[$name] = $allqtypes[$name];
|
||||
}
|
||||
foreach ($otherqtypes as $name => $notused) {
|
||||
foreach ($qtypenames as $name => $notused) {
|
||||
$creatableqtypes[$name] = $allqtypes[$name];
|
||||
}
|
||||
return $creatableqtypes;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This file contains tests for the question_bank class.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage questionbank
|
||||
* @copyright 2011 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(dirname(__FILE__) . '/../lib.php');
|
||||
|
||||
|
||||
/**
|
||||
*Unit tests for the {@link question_bank} class.
|
||||
*
|
||||
* @copyright 2011 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class question_bank_test extends UnitTestCase {
|
||||
|
||||
public function setUp() {
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
}
|
||||
|
||||
function test_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_bank::sort_qtype_array($qtypes, $config), array(
|
||||
'multichoice' => 'eft',
|
||||
'calculated' => 'newt',
|
||||
'frog' => 'toad',
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -506,7 +506,7 @@ class question_engine_upgrade_question_loader {
|
||||
}
|
||||
|
||||
protected function load_question($questionid, $quizid) {
|
||||
global $CFG, $QTYPES;
|
||||
global $CFG;
|
||||
|
||||
if ($quizid) {
|
||||
$question = get_record_sql("
|
||||
@@ -531,14 +531,14 @@ class question_engine_upgrade_question_loader {
|
||||
unset($question->defaultgrade);
|
||||
}
|
||||
|
||||
if (!array_key_exists($question->qtype, $QTYPES)) {
|
||||
$qtype = question_bank::get_qtype($question->qtype, false);
|
||||
if ($qtype->name() === 'missingtype') {
|
||||
$this->logger->log_assumption("Dealing with question id {$question->id}
|
||||
that is of an unknown type {$question->qtype}.");
|
||||
$question->qtype = 'missingtype';
|
||||
$question->questiontext = '<p>' . get_string('warningmissingtype', 'quiz') . '</p>' . $question->questiontext;
|
||||
}
|
||||
|
||||
$QTYPES[$question->qtype]->get_question_options($question);
|
||||
$qtype->get_question_options($question);
|
||||
|
||||
return $question;
|
||||
}
|
||||
|
||||
+9
-13
@@ -273,7 +273,7 @@ class qformat_default {
|
||||
* @return bool success
|
||||
*/
|
||||
function importprocess($category) {
|
||||
global $USER, $CFG, $DB, $OUTPUT, $QTYPES;
|
||||
global $USER, $CFG, $DB, $OUTPUT;
|
||||
|
||||
$context = $category->context;
|
||||
$this->importcontext = $context;
|
||||
@@ -378,12 +378,14 @@ class qformat_default {
|
||||
$question->id = $DB->insert_record('question', $question);
|
||||
if (isset($question->questiontextfiles)) {
|
||||
foreach ($question->questiontextfiles as $file) {
|
||||
$QTYPES[$question->qtype]->import_file($context, 'question', 'questiontext', $question->id, $file);
|
||||
question_bank::get_qtype($question->qtype)->import_file(
|
||||
$context, 'question', 'questiontext', $question->id, $file);
|
||||
}
|
||||
}
|
||||
if (isset($question->generalfeedbackfiles)) {
|
||||
foreach ($question->generalfeedbackfiles as $file) {
|
||||
$QTYPES[$question->qtype]->import_file($context, 'question', 'generalfeedback', $question->id, $file);
|
||||
question_bank::get_qtype($question->qtype)->import_file(
|
||||
$context, 'question', 'generalfeedback', $question->id, $file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,7 +393,7 @@ class qformat_default {
|
||||
|
||||
// Now to save all the answers and type-specific options
|
||||
|
||||
$result = $QTYPES[$question->qtype]->save_question_options($question);
|
||||
$result = question_bank::get_qtype($question->qtype)->save_question_options($question);
|
||||
|
||||
if (!empty($CFG->usetags) && isset($question->tags)) {
|
||||
require_once($CFG->dirroot . '/tag/lib.php');
|
||||
@@ -626,19 +628,13 @@ class qformat_default {
|
||||
* @return string the data to append to export or false if error (or unhandled)
|
||||
*/
|
||||
function try_exporting_using_qtypes($name, $question, $extra=null) {
|
||||
global $QTYPES;
|
||||
|
||||
// work out the name of format in use
|
||||
$formatname = substr(get_class($this), strlen('qformat_'));
|
||||
$methodname = "export_to_$formatname";
|
||||
|
||||
if (array_key_exists($name, $QTYPES)) {
|
||||
$qtype = $QTYPES[ $name ];
|
||||
if (method_exists($qtype, $methodname)) {
|
||||
if ($data = $qtype->$methodname($question, $this, $extra)) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
$qtype = question_bank::get_qtype($name, false);
|
||||
if (method_exists($qtype, $methodname)) {
|
||||
return $qtype->$methodname($question, $this, $extra);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -833,11 +833,9 @@ function process_essay($quest, &$questions) {
|
||||
// Process Matching Questions
|
||||
//----------------------------------------
|
||||
function process_matching($quest, &$questions) {
|
||||
global $QTYPES;
|
||||
|
||||
// renderedmatch is an optional plugin, so we need to check if it is defined
|
||||
if (array_key_exists('renderedmatch', $QTYPES)) {
|
||||
$question = $this->process_common( $quest );
|
||||
if (question_bank::is_qtype_installed('renderedmatch')) {
|
||||
$question = $this->process_common($quest);
|
||||
$question->valid = true;
|
||||
$question->qtype = 'renderedmatch';
|
||||
|
||||
|
||||
@@ -619,7 +619,7 @@ class qformat_gift extends qformat_default {
|
||||
}
|
||||
|
||||
function writequestion($question) {
|
||||
global $QTYPES, $OUTPUT;
|
||||
global $OUTPUT;
|
||||
|
||||
// Start with a comment
|
||||
$expout = "// question: $question->id name: $question->name\n";
|
||||
@@ -747,7 +747,7 @@ class qformat_gift extends qformat_default {
|
||||
} else {
|
||||
$expout .= "Question type $question->qtype is not supported\n";
|
||||
echo $OUTPUT->notification(get_string('nohandler', 'qformat_gift',
|
||||
$QTYPES[$question->qtype]->local_name()));
|
||||
question_bank::get_qtype_name($question->qtype)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -174,8 +174,6 @@ class qformat_webct extends qformat_default {
|
||||
}
|
||||
|
||||
function readquestions ($lines) {
|
||||
global $QTYPES ;
|
||||
// $qtypecalculated = new qformat_webct_modified_calculated_qtype();
|
||||
$webctnumberregex =
|
||||
'[+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)((e|E|\\*10\\*\\*)([+-]?[0-9]+|\\([+-]?[0-9]+\\)))?';
|
||||
|
||||
@@ -344,7 +342,7 @@ class qformat_webct extends qformat_default {
|
||||
|
||||
case CALCULATED:
|
||||
foreach ($question->answers as $answer) {
|
||||
if ($formulaerror =qtype_calculated_find_formula_errors($answer)) { //$QTYPES['calculated']->
|
||||
if ($formulaerror = qtype_calculated_find_formula_errors($answer)) {
|
||||
$warnings[] = "'$question->name': ". $formulaerror;
|
||||
$QuestionOK = FALSE;
|
||||
}
|
||||
@@ -549,7 +547,8 @@ class qformat_webct extends qformat_default {
|
||||
$question->feedback[$currentchoice] = '';
|
||||
$question->correctanswerlength[$currentchoice] = 4;
|
||||
|
||||
$datasetnames = $QTYPES[CALCULATED]->find_dataset_names($webct_options[1]);
|
||||
$datasetnames = question_bank::get_qtype('calculated')->
|
||||
find_dataset_names($webct_options[1]);
|
||||
foreach ($datasetnames as $datasetname) {
|
||||
$question->dataset[$datasetname] = new stdClass();
|
||||
$question->dataset[$datasetname]->datasetitem = array();
|
||||
|
||||
@@ -1082,7 +1082,7 @@ class qformat_xml extends qformat_default {
|
||||
* @return string xml segment
|
||||
*/
|
||||
function writequestion($question) {
|
||||
global $CFG, $QTYPES, $OUTPUT;
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
$fs = get_file_storage();
|
||||
$contextid = $question->contextid;
|
||||
@@ -1168,7 +1168,7 @@ class qformat_xml extends qformat_default {
|
||||
// not a qtype really - dummy used for category switching
|
||||
break;
|
||||
|
||||
case TRUEFALSE:
|
||||
case 'truefalse':
|
||||
$trueanswer = $question->options->answers[$question->options->trueanswer];
|
||||
$trueanswer->answer = 'true';
|
||||
$expout .= $this->write_answer($trueanswer);
|
||||
@@ -1178,7 +1178,7 @@ class qformat_xml extends qformat_default {
|
||||
$expout .= $this->write_answer($falseanswer);
|
||||
break;
|
||||
|
||||
case MULTICHOICE:
|
||||
case 'multichoice':
|
||||
$expout .= " <single>" . $this->get_single($question->options->single) . "</single>\n";
|
||||
$expout .= " <shuffleanswers>" . $this->get_single($question->options->shuffleanswers) . "</shuffleanswers>\n";
|
||||
$expout .= " <answernumbering>{$question->options->answernumbering}</answernumbering>\n";
|
||||
@@ -1186,12 +1186,12 @@ class qformat_xml extends qformat_default {
|
||||
$expout .= $this->write_answers($question->options->answers);
|
||||
break;
|
||||
|
||||
case SHORTANSWER:
|
||||
case 'shortanswer':
|
||||
$expout .= " <usecase>{$question->options->usecase}</usecase>\n";
|
||||
$expout .= $this->write_answers($question->options->answers);
|
||||
break;
|
||||
|
||||
case NUMERICAL:
|
||||
case 'numerical':
|
||||
foreach ($question->options->answers as $answer) {
|
||||
$expout .= $this->write_answer($answer,
|
||||
" <tolerance>$answer->tolerance</tolerance>\n");
|
||||
@@ -1229,7 +1229,7 @@ class qformat_xml extends qformat_default {
|
||||
}
|
||||
break;
|
||||
|
||||
case MATCH:
|
||||
case 'match':
|
||||
$expout .= " <shuffleanswers>" . $this->get_single($question->options->shuffleanswers) . "</shuffleanswers>\n";
|
||||
$expout .= $this->write_combined_feedback($question->options);
|
||||
foreach ($question->options->subquestions as $subquestion) {
|
||||
@@ -1244,11 +1244,11 @@ class qformat_xml extends qformat_default {
|
||||
}
|
||||
break;
|
||||
|
||||
case DESCRIPTION:
|
||||
case 'description':
|
||||
// Nothing else to do.
|
||||
break;
|
||||
|
||||
case MULTIANSWER:
|
||||
case 'multianswer':
|
||||
$acount = 1;
|
||||
foreach ($question->options->questions as $question) {
|
||||
$thispattern = addslashes("{#".$acount."}");
|
||||
@@ -1258,13 +1258,13 @@ class qformat_xml extends qformat_default {
|
||||
}
|
||||
break;
|
||||
|
||||
case ESSAY:
|
||||
case 'essay':
|
||||
// Nothing else to do.
|
||||
break;
|
||||
|
||||
case CALCULATED:
|
||||
case CALCULATEDSIMPLE:
|
||||
case CALCULATEDMULTI:
|
||||
case 'calculated':
|
||||
case 'calculatedsimple':
|
||||
case 'calculatedmulti':
|
||||
$expout .= " <synchronize>{$question->options->synchronize}</synchronize>\n";
|
||||
$expout .= " <single>{$question->options->single}</single>\n";
|
||||
$expout .= " <answernumbering>{$question->options->answernumbering}</answernumbering>\n";
|
||||
@@ -1342,9 +1342,11 @@ class qformat_xml extends qformat_default {
|
||||
$expout .= "</units>\n";
|
||||
}
|
||||
}
|
||||
//The tag $question->export_process has been set so we get all the data items in the database
|
||||
// from the function $QTYPES['calculated']->get_question_options(&$question);
|
||||
// calculatedsimple defaults to calculated
|
||||
|
||||
// The tag $question->export_process has been set so we get all the
|
||||
// data items in the database from the function
|
||||
// qtype_calculated::get_question_options calculatedsimple defaults
|
||||
// to calculated
|
||||
if( isset($question->options->datasets)&&count($question->options->datasets)){// there should be
|
||||
$expout .= "<dataset_definitions>\n";
|
||||
foreach ($question->options->datasets as $def) {
|
||||
|
||||
@@ -34,7 +34,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class question_calculated_qtype extends default_questiontype {
|
||||
class question_calculated_qtype extends question_type {
|
||||
|
||||
public $fileoptionsa = array(
|
||||
'subdirs' => false,
|
||||
@@ -2163,11 +2163,6 @@ class question_calculated_qtype extends default_questiontype {
|
||||
}
|
||||
//// END OF CLASS ////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//// INITIATION - Without this line the question type is not in use... ///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
question_register_questiontype(new question_calculated_qtype());
|
||||
|
||||
if ( ! defined ("CALCULATEDQUESTIONMAXITEMNUMBER")) {
|
||||
define("CALCULATEDQUESTIONMAXITEMNUMBER", 100);
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ class question_calculatedmulti_qtype extends question_calculated_qtype {
|
||||
}
|
||||
|
||||
function create_runtime_question($question, $form) {
|
||||
$question = default_questiontype::create_runtime_question($question, $form);
|
||||
$question = parent::create_runtime_question($question, $form);
|
||||
$question->options->answers = array();
|
||||
foreach ($form->answers as $key => $answer) {
|
||||
$a->answer = trim($form->answer[$key]);
|
||||
@@ -621,11 +621,6 @@ class question_calculatedmulti_qtype extends question_calculated_qtype {
|
||||
|
||||
//// END OF CLASS ////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//// INITIATION - Without this line the question type is not in use... ///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
question_register_questiontype(new question_calculatedmulti_qtype());
|
||||
|
||||
if ( ! defined ("CALCULATEDMULTI")) {
|
||||
define("CALCULATEDMULTI", "calculatedmulti");
|
||||
}
|
||||
|
||||
@@ -405,11 +405,3 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
|
||||
}
|
||||
//// END OF CLASS ////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//// INITIATION - Without this line the question type is not in use... ///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
question_register_questiontype(new question_calculatedsimple_qtype());
|
||||
|
||||
if ( ! defined ("CALCULATEDSIMPLE")) {
|
||||
define("CALCULATEDSIMPLE", "calculatedsimple");
|
||||
}
|
||||
|
||||
@@ -80,7 +80,6 @@ class question_edit_multianswer_form extends question_edit_form {
|
||||
$mform->addElement('hidden', 'reload', 1);
|
||||
// $mform->addElement('hidden', 'generalfeedback','');
|
||||
$mform->setType('reload', PARAM_INT);
|
||||
$question_type_names = question_type_menu();
|
||||
|
||||
// Remove meaningless defaultgrade field.
|
||||
$mform->removeElement('defaultgrade');
|
||||
@@ -156,11 +155,11 @@ class question_edit_multianswer_form extends question_edit_form {
|
||||
if(isset($this->savedquestiondisplay->options->questions[$sub]->qtype) &&
|
||||
$this->savedquestiondisplay->options->questions[$sub]->qtype != $this->questiondisplay->options->questions[$sub]->qtype ){
|
||||
$this->qtype_change = true ;
|
||||
$storemess = "<font class=\"error\"> STORED QTYPE ".$question_type_names[$this->savedquestiondisplay->options->questions[$sub]->qtype]."</font >";
|
||||
$storemess = "<font class=\"error\"> STORED QTYPE ".question_bank::get_qtype_name($this->savedquestiondisplay->options->questions[$sub]->qtype)."</font >";
|
||||
}
|
||||
|
||||
$mform->addElement('header', 'subhdr'.$sub, get_string('questionno', 'question',
|
||||
'{#'.$sub.'}').' '.$question_type_names[$this->questiondisplay->options->questions[$sub]->qtype].$storemess);
|
||||
'{#'.$sub.'}').' '.question_bank::get_qtype_name($this->questiondisplay->options->questions[$sub]->qtype).$storemess);
|
||||
|
||||
$mform->addElement('static', 'sub_'.$sub."_".'questiontext', get_string('questiondefinition','qtype_multianswer'),array('cols'=>60, 'rows'=>3));
|
||||
|
||||
@@ -388,7 +387,7 @@ class question_edit_multianswer_form extends question_edit_form {
|
||||
$maxfraction = -1;
|
||||
if(isset($this->savedquestiondisplay->options->questions[$sub]->qtype) &&
|
||||
$this->savedquestiondisplay->options->questions[$sub]->qtype != $questiondisplay->options->questions[$sub]->qtype ){
|
||||
$storemess = " STORED QTYPE ".$question_type_names[$this->savedquestiondisplay->options->questions[$sub]->qtype];
|
||||
$storemess = " STORED QTYPE ".question_bank::get_qtype_name($this->savedquestiondisplay->options->questions[$sub]->qtype);
|
||||
}
|
||||
foreach ( $subquestion->answer as $key=>$answer) {
|
||||
$trimmedanswer = trim($answer);
|
||||
|
||||
@@ -34,7 +34,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class embedded_cloze_qtype extends default_questiontype {
|
||||
class embedded_cloze_qtype extends question_type {
|
||||
|
||||
function name() {
|
||||
return 'multianswer';
|
||||
@@ -710,12 +710,6 @@ Good luck!
|
||||
}
|
||||
//// END OF CLASS ////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//// INITIATION - Without this line the question type is not in use... ///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
question_register_questiontype(new embedded_cloze_qtype());
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// ADDITIONAL FUNCTIONS
|
||||
//// The functions below deal exclusivly with editing
|
||||
|
||||
@@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @param int $oldversion the version we are upgrading from.
|
||||
*/
|
||||
function xmldb_qtype_multichoice_upgrade($oldversion) {
|
||||
global $CFG, $DB, $QTYPES;
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
@@ -42,7 +42,9 @@ function xmldb_qtype_multichoice_upgrade($oldversion) {
|
||||
// is doing it.
|
||||
// Rename random questions to give them more helpful names.
|
||||
if ($oldversion < 2008021800) {
|
||||
require_once($CFG->libdir . '/questionlib.php');
|
||||
require_once($CFG->dirroot . '/question/type/random/questiontype.php');
|
||||
$randomqtype = new qtype_random();
|
||||
|
||||
// Get all categories containing random questions.
|
||||
$categories = $DB->get_recordset_sql("
|
||||
SELECT qc.id, qc.name
|
||||
@@ -55,10 +57,10 @@ function xmldb_qtype_multichoice_upgrade($oldversion) {
|
||||
$where = "qtype = 'random' AND category = ? AND " .
|
||||
$DB->sql_compare_text('questiontext') . " = " . $DB->sql_compare_text('?');
|
||||
foreach ($categories as $cat) {
|
||||
$randomqname = $QTYPES[RANDOM]->question_name($cat, false);
|
||||
$randomqname = $randomqtype->question_name($cat, false);
|
||||
$DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0'));
|
||||
|
||||
$randomqname = $QTYPES[RANDOM]->question_name($cat, true);
|
||||
$randomqname = $randomqtype->question_name($cat, true);
|
||||
$DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1'));
|
||||
}
|
||||
|
||||
|
||||
@@ -1310,7 +1310,7 @@ class question_numerical_qtype extends qtype_shortanswer {
|
||||
*/
|
||||
function generate_test($name, $courseid = null) {
|
||||
global $DB;
|
||||
list($form, $question) = default_questiontype::generate_test($name, $courseid);
|
||||
list($form, $question) = parent::generate_test($name, $courseid);
|
||||
$question->category = $form->category;
|
||||
|
||||
$form->questiontext = "What is 674 * 36?";
|
||||
@@ -1379,8 +1379,6 @@ class question_numerical_qtype extends qtype_shortanswer {
|
||||
}
|
||||
}
|
||||
|
||||
// INITIATION - Without this line the question type is not in use.
|
||||
question_register_questiontype(new question_numerical_qtype());
|
||||
if ( ! defined ("NUMERICALQUESTIONUNITTEXTINPUTDISPLAY")) {
|
||||
define("NUMERICALQUESTIONUNITTEXTINPUTDISPLAY", 0);
|
||||
}
|
||||
|
||||
@@ -360,11 +360,3 @@ class question_randomsamatch_qtype extends qtype_match {
|
||||
return 1/$question->options->choose;
|
||||
}
|
||||
}
|
||||
|
||||
//// END OF CLASS ////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//// INITIATION - Without this line the question type is not in use... ///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
question_register_questiontype(new question_randomsamatch_qtype());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user