From: dongsheng Date: Thu, 24 Jul 2008 04:20:44 +0000 (+0000) Subject: MDL-14129, remove error() in question module X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ac93d63d2a8708e9c16ae7a7fcc4d4022fa4e5db;p=moodle.git MDL-14129, remove error() in question module --- diff --git a/lang/en_utf8/question.php b/lang/en_utf8/question.php index bd140aac96..268663c0a7 100644 --- a/lang/en_utf8/question.php +++ b/lang/en_utf8/question.php @@ -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!'; diff --git a/question/editlib.php b/question/editlib.php index 51081c03d2..6fdf8d95ee 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -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()); } diff --git a/question/exportfile.php b/question/exportfile.php index a3947fe1ce..6d0bc59cc2 100644 --- a/question/exportfile.php +++ b/question/exportfile.php @@ -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; diff --git a/question/format/qti_two/format.php b/question/format/qti_two/format.php index fc1268ecc5..d516714fc7 100644 --- a/question/format/qti_two/format.php +++ b/question/format/qti_two/format.php @@ -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; diff --git a/question/preview.php b/question/preview.php index 9243c6c115..19779cb9e3 100644 --- a/question/preview.php +++ b/question/preview.php @@ -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)); } @@ -86,11 +86,11 @@ $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;