]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14129, remove error() in question module
authordongsheng <dongsheng>
Thu, 24 Jul 2008 04:20:44 +0000 (04:20 +0000)
committerdongsheng <dongsheng>
Thu, 24 Jul 2008 04:20:44 +0000 (04:20 +0000)
lang/en_utf8/question.php
question/editlib.php
question/exportfile.php
question/format/qti_two/format.php
question/preview.php

index bd140aac963712e406ce704920609c4e63f1ac61..268663c0a72f70672d2bbd391fb69fe6519d08ef 100644 (file)
@@ -10,20 +10,27 @@ $string['cannotcreate'] = 'Could not create new entry in question_attempts table
 $string['cannotcreatedataset'] = 'Unable to create dataset $a';
 $string['cannotcreaterelation'] = 'Unable to create relation to dataset $a[0] $a[1]';
 $string['cannotcopybackup'] = 'Could not copy backup file';
+$string['cannotdeletecate'] = 'You can\'t delete that category it is the default category for this context.';
+$string['cannotfindcate'] = 'Could not find category record';
 $string['cannotinsertitem'] = 'Unable to insert dataset item $a[0] with $a[1] for $a[2]';
 $string['cannotinsert'] = 'Error: Unable to insert dataset item';
 $string['cannotinsertquestion'] = 'Could not insert new question!';
 $string['cannotinsertquestioncatecontext'] = 'Could not insert the new question category $a[0] illegal contextid $a[1]';
 $string['cannotinsertquestioncate'] = 'Could not insert the new question category: $a';
+$string['cannotimportformat'] = 'Sorry, importing this format is not yet implemented!';
 $string['cannotfindquestionfile'] = 'Could not find question data file in zip';
 $string['cannotgetdsforquestion'] = 'Cannot get the specified dataset for a calculated question! (question: {$a})';
 $string['cannotgetdsfordependent'] = 'Cannot get the specified dataset for a dataset dependent question! (question: {$a[0]}, datasetitem: {a[1]})';
+$string['cannothidequestion'] = 'Was not able to hide question';
+$string['cannotloadquestion'] = 'Could not load question';
+$string['cannotpreview'] = 'You can\'t preview these questions!';
 $string['cannotretrieveqcat'] = 'Could retrieve question category';
 $string['cannotupdatecount'] = 'Error: Unable to update itemcount';
 $string['cannotupdatecate'] = 'Could not update the category $a';
 $string['cannotmovecate'] = 'Cannot move the category $a. It is the last in this context.';
 $string['cannotmovefromto'] = 'Could not move the category $a[0] to $a[1]';
 $string['cannotmovequestion'] = 'You can\'t use this script to move questions that have files associated with them from different areas.';
+$string['cannotunhidequestion'] = 'Failed to unhide the question.';
 $string['cannotunzip'] = 'Could not unzip file.';
 $string['cannotupdatesubcate'] = 'Could not update a child category!';
 $string['cannotupdaterandomqname'] = 'Could not update random question name';
@@ -85,7 +92,9 @@ $string['getcategoryfromfile'] = 'Get category from file';
 $string['getcontextfromfile'] = 'Get context from file';
 $string['ignorebroken'] = 'Ignore broken links';
 $string['impossiblechar'] = 'Impossible character $a detected as parenthesis character';
+$string['invalidarg'] = 'No valid arguments supplied or incorrect server configuration';
 $string['invalidcontextinhasanyquestions'] = 'Invalid context passed to question_context_has_any_questions.';
+$string['invalidconfirm'] = 'Confirmation string was incorrect';
 $string['invalidcategoryidforparent'] = 'Invalid category id for parent!';
 $string['invalidcategoryidtomove'] = 'Invalid category id to move!';
 $string['invalidwizardpage'] = 'Incorrect or no wizard page specified!';
index 51081c03d282873e220b7da6e3b2e02b4fc54bb9..6fdf8d95ee81a385b5ac8157a5e28e0cab67a55e 100644 (file)
@@ -86,7 +86,7 @@ function question_can_delete_cat($todelete){
     $contextid = $record->contextid;
     $count = $record->count;
     if ($count < 2) {
-        error('You can\'t delete that category it is the default category for this context.');
+        print_error('cannotdeletecate', 'question');
     } else {
         require_capability('moodle/question:managecategory', get_context_instance_by_id($contextid));
     }
@@ -420,7 +420,7 @@ function question_showbank_actions($pageurl, $cm){
         $category = required_param('category', PARAM_SEQUENCE);
         list($tocategoryid, $contextid) = explode(',', $category);
         if (! $tocategory = $DB->get_record('question_categories', array('id' => $tocategoryid, 'contextid' => $contextid))) {
-            error('Could not find category record');
+            print_error('cannotfindcate', 'question');
         }
         $tocontext = get_context_instance_by_id($contextid);
         require_capability('moodle/question:add', $tocontext);
@@ -479,7 +479,7 @@ function question_showbank_actions($pageurl, $cm){
                         if ($DB->record_exists('quiz_question_instances', array('question' => $questionid))) {
                             if (!$DB->set_field('question', 'hidden', 1, array('id', $questionid))) {
                                 question_require_capability_on($questionid, 'edit');
-                                error('Was not able to hide question');
+                                print_error('cannothidequestion', 'question');
                             }
                         } else {
                             delete_question($questionid);
@@ -488,7 +488,7 @@ function question_showbank_actions($pageurl, $cm){
                 }
                 redirect($pageurl->out());
             } else {
-                error("Confirmation string was incorrect");
+                print_error('invalidconfirm', 'question');
             }
         }
     }
@@ -497,7 +497,7 @@ function question_showbank_actions($pageurl, $cm){
     if(($unhide = optional_param('unhide', '', PARAM_INT)) and confirm_sesskey()) {
         question_require_capability_on($unhide, 'edit');
         if(!$DB->set_field('question', 'hidden', 0, array('id', $unhide))) {
-            error("Failed to unhide the question.");
+            print_error('cannotunhidequestion', 'question');
         }
         redirect($pageurl->out());
     }
index a3947fe1ce3e952afc6ea241a42bf293a184f780..6d0bc59cc20eb07286d7d94ee8530ebac589d57a 100644 (file)
@@ -8,7 +8,7 @@
 
     $relativepath = get_file_argument('question/exportfile.php');
     if (!$relativepath) {
-        error('No valid arguments supplied or incorrect server configuration');
+        print_error('invalidarg', 'question');
     }
 
     $pathname = $CFG->dataroot . '/temp/questionexport/' . $USER->id . '/' .  $relativepath;
index fc1268ecc51a23688af23dad5b6acc6021cf98df..d516714fc78b20db9f1faa39c8a31579f4cb431c 100644 (file)
@@ -109,9 +109,7 @@ class qformat_qti_two extends qformat_default {
     
     function importpreprocess() {
         global $CFG;
-
-        error("Sorry, importing this format is not yet implemented!", 
-            "$CFG->wwwroot/mod/quiz/import.php?category=$category->id");
+        print_error('cannotimportformat', 'question', "$CFG->wwwroot/mod/quiz/import.php?category=$category->id");
     }
 
     function exportpreprocess() {
@@ -241,7 +239,7 @@ function handle_questions_media(&$questions, $path, $courseid) {
 
         // create a directory for the exports (if not already existing)
         if (!$export_dir = make_upload_directory($this->question_get_export_dir().'/'.$this->filename)) {
-              error( get_string('cannotcreatepath','quiz',$export_dir) );
+            print_error('cannotcreatepath', 'quiz', '', $export_dir);
         }
         $path = $CFG->dataroot.'/'.$this->question_get_export_dir().'/'.$this->filename;
 
@@ -274,13 +272,13 @@ function handle_questions_media(&$questions, $path, $courseid) {
         $expout = $smarty->fetch('imsmanifest.tpl');
         $filepath = $path.'/imsmanifest.xml';
         if (empty($expout)) {
-            error("Unkown error - empty imsmanifest.xml");
+            print_error('emptyxml', 'question');
         }
         if (!$fh=fopen($filepath,"w")) {
-            error("Cannot open for writing: $filepath");
+            print_error('cannotwriteto', 'question', '', $filepath);
         }
         if (!fwrite($fh, $expout)) {
-            error("Cannot write exported questions to $filepath");
+            print_error('cannotwriteto', 'question', '', $filepath);
         }
         fclose($fh);
 
@@ -295,10 +293,10 @@ function handle_questions_media(&$questions, $path, $courseid) {
             
             $filepath = $path.'/'.$this->get_assesment_item_id($question) . ".xml";
             if (!$fh=fopen($filepath,"w")) {
-                error("Cannot open for writing: $filepath");
+                print_error('cannotwriteto', 'question', '', $filepath);
             }
             if (!fwrite($fh, $expout)) {
-                error("Cannot write exported questions to $filepath");
+                print_error('cannotwriteto', 'question', '', $filepath);
             }
             fclose($fh);
             
@@ -332,13 +330,13 @@ function handle_questions_media(&$questions, $path, $courseid) {
         $this->xml_entitize($result);
         $this->xml_entitize($submiturl);
         if (! $this->exportpreprocess(0, $course)) {   // Do anything before that we need to
-            error("Error occurred during pre-processing!", $redirect);
+            print_error('errorduringpre', 'question', $redirect);
         }
         if (! $this->exportprocess_quiz($quiz, $questions, $result, $submiturl, $course)) {         // Process the export data
-            error("Error occurred during processing!", $redirect);
+            print_error('errorduringproc', 'question', $redirect);
         }
         if (! $this->exportpostprocess()) {                    // In case anything needs to be done after
-            error("Error occurred during post-processing!", $redirect);
+            print_error('errorduringpost', 'question', $redirect);
         }
 
     }
@@ -675,7 +673,7 @@ function xml_entitize(&$collection) {
         $path = $CFG->dataroot."/smarty_c";
         if (!is_dir($path)) {
             if (!mkdir($path, $CFG->directorypermissions)) {
-              error("Cannot create path: $path");
+                print_error('cannotcreatepath', 'quiz', '', $path);
             }
         }
         $smarty = new Smarty;
index 9243c6c1153314dd5f321e3b078e29eaab606a09..19779cb9e3b1b0c86be74593753ef89208e1b203 100644 (file)
@@ -60,7 +60,7 @@
     }
     // Load the question information
     if (!$questions = $DB->get_records('question', array('id' =>  $id))) {
-        error('Could not load question');
+        print_error('cannotloadquestion', 'question');
     }
     if (empty($quizid)) {
         $quiz = new cmoptions;
@@ -69,7 +69,7 @@
         require_login($courseid, false);
         $quiz->course = $courseid;
     } else if (!$quiz = $DB->get_record('quiz', array('id' => $quizid))) {
-        error("Quiz id $quizid does not exist");
+        print_error('invalidquizid', 'quiz', '', $quizid);
     } else {
         require_login($quiz->course, false, get_coursemodule_from_instance('quiz', $quizid, $quiz->course));
     }
     $quiz->questions = $id;
 
     if (!$category = $DB->get_record("question_categories", array("id" => $questions[$id]->category))) {
-        error("This question doesn't belong to a valid category!");
+        print_error('invalidquestionid', 'quiz');
     }
 
     if (!question_has_capability_on($questions[$id], 'use', $questions[$id]->category)){
-        error("You can't preview these questions!");
+        print_error('cannotpreview', 'question');
     }
     if (isset($COURSE)){
         $quiz->course = $COURSE->id;