Skip to content

Commit

Permalink
MDL-20636 converstion of questionlib.php and base questiontype.php, p…
Browse files Browse the repository at this point in the history
…lus other cheanges required to get the question editing page to display.
  • Loading branch information
timhunt committed Jan 13, 2011
1 parent 06f8ed5 commit f29aeb5
Show file tree
Hide file tree
Showing 13 changed files with 3,209 additions and 2,683 deletions.
34 changes: 18 additions & 16 deletions admin/qtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

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) {
foreach ($qtypes as $qtypename => $qtype) {
if (!isset($counts[$qtypename])) {
$counts[$qtypename] = new stdClass;
$counts[$qtypename]->numquestions = 0;
Expand All @@ -29,13 +31,13 @@
$counts[$qtypename]->numquestions -= $counts[$qtypename]->numhidden;
}
$needed['missingtype'] = true; // The system needs the missing question type.
foreach ($QTYPES as $qtypename => $qtype) {
foreach ($qtypes as $qtypename => $qtype) {
foreach ($qtype->requires_qtypes() as $reqtype) {
$needed[$reqtype] = true;
}
}
foreach ($counts as $qtypename => $count) {
if (!isset($QTYPES[$qtypename])) {
if (!isset($qtypes[$qtypename])) {
$counts['missingtype']->numquestions += $count->numquestions - $count->numhidden;
$counts['missingtype']->numhidden += $count->numhidden;
}
Expand All @@ -44,7 +46,7 @@
/// Work of the correct sort order.
$config = get_config('question');
$sortedqtypes = array();
foreach ($QTYPES as $qtypename => $qtype) {
foreach ($qtypes as $qtypename => $qtype) {
$sortedqtypes[$qtypename] = $qtype->local_name();
}
$sortedqtypes = question_sort_qtype_array($sortedqtypes, $config);
Expand All @@ -53,7 +55,7 @@

// Disable.
if (($disable = optional_param('disable', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
if (!isset($QTYPES[$disable])) {
if (!isset($qtypes[$disable])) {
print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $disable);
}

Expand All @@ -63,11 +65,11 @@

// Enable.
if (($enable = optional_param('enable', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
if (!isset($QTYPES[$enable])) {
if (!isset($qtypes[$enable])) {
print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $enable);
}

if (!$QTYPES[$enable]->menu_name()) {
if (!$qtypes[$enable]->menu_name()) {
print_error('cannotenable', 'question', admin_url('qtypes.php'), $enable);
}

Expand All @@ -77,7 +79,7 @@

// Move up in order.
if (($up = optional_param('up', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
if (!isset($QTYPES[$up])) {
if (!isset($qtypes[$up])) {
print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $up);
}

Expand All @@ -88,7 +90,7 @@

// Move down in order.
if (($down = optional_param('down', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
if (!isset($QTYPES[$down])) {
if (!isset($qtypes[$down])) {
print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $down);
}

Expand All @@ -104,11 +106,11 @@
print_error('cannotdeletemissingqtype', 'admin', admin_url('qtypes.php'));
}

if (!isset($QTYPES[$delete])) {
if (!isset($qtypes[$delete])) {
print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $delete);
}

$qtypename = $QTYPES[$delete]->local_name();
$qtypename = $qtypes[$delete]->local_name();
if ($counts[$delete]->numquestions + $counts[$delete]->numhidden > 0) {
print_error('cannotdeleteqtypeinuse', 'admin', admin_url('qtypes.php'), $qtypename);
}
Expand All @@ -119,7 +121,7 @@

// If not yet confirmed, display a confirmation message.
if (!optional_param('confirm', '', PARAM_BOOL)) {
$qtypename = $QTYPES[$delete]->local_name();
$qtypename = $qtypes[$delete]->local_name();
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('deleteqtypeareyousure', 'admin', $qtypename));
echo $OUTPUT->confirm(get_string('deleteqtypeareyousuremessage', 'admin', $qtypename),
Expand All @@ -141,13 +143,13 @@
unset_config($delete . '_sortorder', 'question');

// Then the tables themselves
drop_plugin_tables($delete, $QTYPES[$delete]->plugin_dir() . '/db/install.xml', false);
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();
$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->footer();
Expand All @@ -174,7 +176,7 @@
/// Add a row for each question type.
$createabletypes = question_type_menu();
foreach ($sortedqtypes as $qtypename => $localname) {
$qtype = $QTYPES[$qtypename];
$qtype = $qtypes[$qtypename];
$row = array();

// Question icon and name.
Expand Down Expand Up @@ -213,7 +215,7 @@
$strtypes = array();
if (!empty($requiredtypes)) {
foreach ($requiredtypes as $required) {
$strtypes[] = $QTYPES[$required]->local_name();
$strtypes[] = $qtypes[$required]->local_name();
}
$row[] = implode(', ', $strtypes);
} else {
Expand Down
Loading

0 comments on commit f29aeb5

Please sign in to comment.