Fixed up a bunch of hardcoded text.
Added test for exporting category with no questions.
}
if (! $categorycourse = get_record("course", "id", $category->course)) {
- error("This category doesn't belong to a valid course!");
+ error( get_string('nocategory','quiz') );
}
require_login($course->id, false);
if (!isteacher($course->id)) {
- error("Only the teacher can export quiz questions!");
+ error( get_string('onlyteachersexport','quiz') );
}
// ensure the files area exists for this course
$qformat = new $classname();
if (! $qformat->exportpreprocess($category, $course)) { // Do anything before that we need to
- error("Error occurred during pre-processing!",
- "$CFG->wwwroot/question/export.php?category=$category->id");
+ error( get_string('exporterror','quiz'),
+ "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
}
if (! $qformat->exportprocess($exportfilename)) { // Process the export data
- error("Error occurred during processing!",
- "$CFG->wwwroot/question/export.php?category=$category->id");
+ error( get_string('exporterror','quiz'),
+ "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
}
if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
- error("Error occurred during post-processing!",
- "$CFG->wwwroot/question/export.php?category=$category->id");
+ error( get_string('exporterror','quiz'),
+ "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
}
echo "<hr />";
/// Processes a given file. There's probably little need to change this
if (! $lines = $this->readdata($filename)) {
- notify("File could not be read, or was empty");
+ notify( get_string('cannotread','quiz') );
return false;
}
if (! $questions = $this->readquestions($lines)) { // Extract all the questions
- notify("There are no questions in this file!");
+ notify( get_string('noquestionsinfile','quiz') );
return false;
}
- notify("Importing ".count($questions)." questions");
+ notify( get_string('importingquestions','quiz',count($questions)) );
$count = 0;
$question->version = 1; // Original version of this question
if (!$question->id = insert_record("question", $question)) {
- error("Could not insert new question!");
+ error( get_string('cannotinsert','quiz') );
}
$this->questionids[] = $question->id;
/// this format, this function converts it into a question
/// object suitable for processing and insertion into Moodle.
- echo "<p>This quiz format has not yet been completed!</p>";
+ $formatnotimplemented = get_string( 'formatnotimplemented','quiz' );
+ echo "<p>$formatnotimplemented</p>";
return NULL;
}
$path = $CFG->dataroot.'/'.$courseid.'/'.$dirname;
if (!is_dir($path)) {
if (!mkdir($path, $CFG->directorypermissions)) {
- error("Cannot create path: $path");
+ error( get_string('cannotcreatepath','quiz',$path) );
}
}
// only get q's with no parents (no cloze subquestions specifically)
$questions = get_questions_category( $this->category, true );
- notify("Exporting questions.");
+ notify( get_string('exportingquestions','quiz') );
if (!count($questions)) {
- return true;
+ notify( get_string('noquestions','quiz') );
+ return false;
}
$count = 0;
// write file
$filepath = $path."/".$filename . $this->export_file_extension();
if (!$fh=fopen($filepath,"w")) {
- error("Cannot open for writing: $filepath");
+ error( get_string('cannotopen','quiz',$filepath) );
}
if (!fwrite($fh, $expout)) {
- error("Cannot write exported questions to $filepath");
+ error( get_string('cannotwrite','quiz',$filepath) );
}
fclose($fh);
/// Turns a question object into textual output in the given format
/// must be overidden
- echo "<p>This quiz format has not yet been completed!</p>";
+ // if not overidden, then this is an error.
+ $formatnotimplemented = get_string( 'formatnotimplemented','quiz' );
+ echo "<p>$formatnotimplemented</p>";
return NULL;
}
if ($courseid) {
$category = get_default_question_category($courseid);
} else {
- error("No category specified");
+ error( get_string('nocategory','quiz') );
}
}
require_login($course->id, false);
if (!isteacheredit($course->id)) {
- error("Only editing teachers can import quiz questions!");
+ error( get_string('onlyteachersimport','quiz') );
}
// ensure the files area exists for this course
} else { // Valid file is found
if (! is_readable("format/$format/format.php")) {
- error("Format not known ($format)");
+ error( get_string('formatnotfound','quiz', $format) );
}
require("format.php"); // Parent class
$qformat = new $classname();
if (! $qformat->importpreprocess($category,$course)) { // Do anything before that we need to
- error("Error occurred during pre-processing!",
- "$CFG->wwwroot/question/import.php?category=$category->id");
+ error( get_string('importerror','quiz'),
+ "$CFG->wwwroot/question/import.php?courseid={$course->id}&category=$category->id");
}
if (! $qformat->importprocess($_FILES['newfile']['tmp_name'])) { // Process the uploaded file
- error("Error occurred during processing!",
- "$CFG->wwwroot/question/import.php?category=$category->id");
+ error( get_string('importerror','quiz'),
+ "$CFG->wwwroot/question/import.php?courseid={$course->id}&category=$category->id");
}
if (! $qformat->importpostprocess()) { // In case anything needs to be done after
- error("Error occurred during post-processing!",
- "$CFG->wwwroot/question/import.php?category=$category->id");
+ error( get_string('importerror','quiz'),
+ "$CFG->wwwroot/question/import.php?courseid={$course->id}&category=$category->id");
}
echo "<hr />";