Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-32246 question export: should cope with unrecognised qtypes.

If a question is of an unrecognised type, then we just omit it from the export.
  • Loading branch information...
commit 1fdd74081ce3489ad67d9a82edda06ba13bd28d4 1 parent c54172b
Tim Hunt timhunt authored

Showing 2 changed files with 16 additions and 14 deletions. Show diff stats Hide diff stats

  1. +14 13 question/editlib.php
  2. +2 1  question/export.php
27 question/editlib.php
@@ -54,15 +54,11 @@ function get_module_from_cmid($cmid) {
54 54 * @param bool $noparent if true only questions with NO parent will be selected
55 55 * @param bool $recurse include subdirectories
56 56 * @param bool $export set true if this is called by questionbank export
57   -* @author added by Howard Miller June 2004
58 57 */
59 58 function get_questions_category( $category, $noparent=false, $recurse=true, $export=true ) {
60 59 global $DB;
61 60
62   - // questions will be added to an array
63   - $qresults = array();
64   -
65   - // build sql bit for $noparent
  61 + // Build sql bit for $noparent
66 62 $npsql = '';
67 63 if ($noparent) {
68 64 $npsql = " and parent='0' ";
@@ -75,16 +71,21 @@ function get_questions_category( $category, $noparent=false, $recurse=true, $exp
75 71 $categorylist = array($category->id);
76 72 }
77 73
78   - // get the list of questions for the category
  74 + // Get the list of questions for the category
79 75 list($usql, $params) = $DB->get_in_or_equal($categorylist);
80   - if ($questions = $DB->get_records_select('question', "category $usql $npsql", $params, 'qtype, name')) {
  76 + $questions = $DB->get_records_select('question', "category $usql $npsql", $params, 'qtype, name');
81 77
82   - // iterate through questions, getting stuff we need
83   - foreach($questions as $question) {
84   - $question->export_process = $export;
85   - question_bank::get_qtype($question->qtype)->get_question_options($question);
86   - $qresults[] = $question;
87   - }
  78 + // Iterate through questions, getting stuff we need
  79 + $qresults = array();
  80 + foreach($questions as $key => $question) {
  81 + $question->export_process = $export;
  82 + $qtype = question_bank::get_qtype($question->qtype, false);
  83 + if ($export && $qtype->name() == 'missingtype') {
  84 + // Unrecognised question type. Skip this question when exporting.
  85 + continue;
  86 + }
  87 + $qtype->get_question_options($question);
  88 + $qresults[] = $question;
88 89 }
89 90
90 91 return $qresults;
3  question/export.php
@@ -43,7 +43,8 @@
43 43 $PAGE->set_heading($COURSE->fullname);
44 44 echo $OUTPUT->header();
45 45
46   -$export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat']));
  46 +$export_form = new question_export_form($thispageurl,
  47 + array('contexts' => $contexts->having_one_edit_tab_cap('export'), 'defaultcategory' => $pagevars['cat']));
47 48
48 49
49 50 if ($from_form = $export_form->get_data()) {

0 comments on commit 1fdd740

Please sign in to comment.
Something went wrong with that request. Please try again.