From 38cde336cab9168088fadaaba05b7d183aa049d0 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Sat, 6 Sep 2014 20:20:58 +0100 Subject: [PATCH 1/3] MDL-46195 Fix fractionsaddwrong string component in lesson & qformat_webct. I know. You should not refer to strings from other plugins, but * qformat_webct is importing multichoice questions in that bit of code. I suppose a pedant would say that qformat_webct should declare dependencies on all the qtypes it relies on, but that would be silly. * Lesson should be using the question engine, rather than doing its own thing. --- mod/lesson/format.php | 2 +- question/format/webct/format.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/lesson/format.php b/mod/lesson/format.php index 22201b1fdd3..e699122229f 100644 --- a/mod/lesson/format.php +++ b/mod/lesson/format.php @@ -221,7 +221,7 @@ function lesson_save_question_options($question, $lesson) { $totalfraction = round($totalfraction,2); if ($totalfraction != 1) { $totalfraction = $totalfraction * 100; - $result->notice = get_string("fractionsaddwrong", "quiz", $totalfraction); + $result->notice = get_string("fractionsaddwrong", "qtype_multichoice", $totalfraction); return $result; } } diff --git a/question/format/webct/format.php b/question/format/webct/format.php index 2c003d87ca1..498995cdec0 100644 --- a/question/format/webct/format.php +++ b/question/format/webct/format.php @@ -518,7 +518,7 @@ class qformat_webct extends qformat_default { if ($totalfraction != 1) { $totalfraction = $totalfraction * 100; $errors[] = "'{$question->name}': ".get_string('wronggrade', 'qformat_webct', $nlinecounter) - .' '.get_string('fractionsaddwrong', 'question', $totalfraction); + .' '.get_string('fractionsaddwrong', 'qtype_multichoice', $totalfraction); $questionok = false; } } From 57944b7a54c1d0ddb148bbd24a62c883ef01537d Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Sat, 6 Sep 2014 20:40:49 +0100 Subject: [PATCH 2/3] MDL-46195 fix error handling. --- question/format.php | 2 +- question/format/webct/format.php | 25 ++++++++----------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/question/format.php b/question/format.php index 3460b432860..827636f0e63 100644 --- a/question/format.php +++ b/question/format.php @@ -230,7 +230,7 @@ class qformat_default { echo "{$message}\n"; echo ""; - $this->importerrors++; + $this->importerrors++; } /** diff --git a/question/format/webct/format.php b/question/format/webct/format.php index 498995cdec0..6efa010c904 100644 --- a/question/format/webct/format.php +++ b/question/format/webct/format.php @@ -337,7 +337,6 @@ class qformat_webct extends qformat_default { '[+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)((e|E|\\*10\\*\\*)([+-]?[0-9]+|\\([+-]?[0-9]+\\)))?'; $questions = array(); - $errors = array(); $warnings = array(); $webctoptions = array(); @@ -453,7 +452,7 @@ class qformat_webct extends qformat_default { $questionok = false; } if (count($question->answer) < 1) { // A question must have at least 1 answer. - $errors[] = get_string('missinganswer', 'qformat_webct', $nquestionstartline); + $this->error(get_string('missinganswer', 'qformat_webct', $nquestionstartline), '', $question->name); $questionok = false; } else { // Create empty feedback array. @@ -497,8 +496,8 @@ class qformat_webct extends qformat_default { case 'shortanswer': if ($maxfraction != 1) { $maxfraction = $maxfraction * 100; - $errors[] = "'{$question->name}': ".get_string('wronggrade', 'qformat_webct', $nlinecounter) - .' '.get_string('fractionsnomax', 'question', $maxfraction); + $this->error(get_string('wronggrade', 'qformat_webct', $nlinecounter) + .' '.get_string('fractionsnomax', 'question', $maxfraction), '', $question->name);; $questionok = false; } break; @@ -509,16 +508,17 @@ class qformat_webct extends qformat_default { if ($question->single) { if ($maxfraction != 1) { $maxfraction = $maxfraction * 100; - $errors[] = "'{$question->name}': ".get_string('wronggrade', 'qformat_webct', $nlinecounter) - .' '.get_string('fractionsnomax', 'question', $maxfraction); + $this->error(get_string('wronggrade', 'qformat_webct', $nlinecounter) + .' '.get_string('fractionsnomax', 'question', $maxfraction), '', $question->name); $questionok = false; } } else { $totalfraction = round($totalfraction, 2); if ($totalfraction != 1) { $totalfraction = $totalfraction * 100; - $errors[] = "'{$question->name}': ".get_string('wronggrade', 'qformat_webct', $nlinecounter) - .' '.get_string('fractionsaddwrong', 'qtype_multichoice', $totalfraction); + $this->error(get_string('wronggrade', 'qformat_webct', $nlinecounter) + .' '.get_string('fractionsaddwrong', 'qtype_multichoice', $totalfraction), + '', $question->name); $questionok = false; } } @@ -852,15 +852,6 @@ class qformat_webct extends qformat_default { } } - if (count($errors) > 0) { - echo '

'.get_string('errorsdetected', 'qformat_webct', count($errors)).'

'; - unset($questions); // No questions imported. - } - if (count($warnings) > 0) { echo '

'.get_string('warningsdetected', 'qformat_webct', count($warnings)).'