return true;
}
- function importprocess($filename) {
+ /**
+ *
+ * @PARAM $matchgrades string 'error' or 'nearest', mismatched grades handling
+ */
+ function importprocess($filename, $matchgrades='error') {
/// Processes a given file. There's probably little need to change this
if (! $lines = $this->readdata($filename)) {
notify( get_string('importingquestions','quiz',count($questions)) );
+ // get list of valid answer grades
+ $grades = get_grade_options();
+ $gradeoptionsfull = $grades->gradeoptionsfull;
+
$count = 0;
foreach ($questions as $question) { // Process and store each question
echo "<hr /><p><b>$count</b>. ".stripslashes($question->questiontext)."</p>";
+ // check for answer grades validity (must match fixed list of grades)
+ $fractions = $question->fraction;
+ $answersvalid = true; // in case they are!
+ foreach ($fractions as $key => $fraction) {
+ $newfraction = match_grade_options($gradeoptionsfull, $fraction, $matchgrades);
+ if ($newfraction===false) {
+ $answersvalid = false;
+ }
+ else {
+ $fractions[$key] = $newfraction;
+ }
+ }
+ if (!$answersvalid) {
+ notify( get_string('matcherror','quiz') );
+ continue;
+ }
+ else {
+ $question->fraction = $fractions;
+ }
+
$question->category = $this->category->id;
$question->stamp = make_unique_id_code(); // Set the unique code (not to be changed)
$question->version = 1; // Original version of this question
$categoryid = optional_param('category', 0, PARAM_INT);
$courseid = optional_param('course', 0, PARAM_INT);
$format = optional_param('format','',PARAM_FILE);
+ $params->matchgrades = optional_param('matchgrades','',PARAM_ALPHA);
// get display strings
$txt = new stdClass();
$txt->importfilearea = get_string('importfilearea','quiz');
$txt->importfileupload = get_string('importfileupload','quiz');
$txt->importquestions = get_string("importquestions", "quiz");
+ $txt->matchgrades = get_string('matchgrades','quiz');
+ $txt->matchgradeserror = get_string('matchgradeserror','quiz');
+ $txt->matchgradesnearest = get_string('matchgradesnearest','quiz');
$txt->modulename = get_string('modulename','quiz');
$txt->modulenameplural = get_string('modulenameplural','quiz');
$txt->nocategory = get_string('nocategory','quiz');
$txt->uploadproblem = get_string('uploadproblem');
$txt->uploadthisfile = get_string('uploadthisfile');
+ // matching options
+ $matchgrades = array();
+ $matchgrades['error'] = $txt->matchgradeserror;
+ $matchgrades['nearest'] = $txt->matchgradesnearest;
+
if (!$categoryid) { // try to get category from modform
$showcatmenu = true; // will ensure that user can choose category
if (isset($SESSION->modform)) {
"$CFG->wwwroot/question/import.php?courseid={$course->id}&category=$category->id");
}
- if (! $qformat->importprocess($importfile) ) { // Process the uploaded file
+ if (! $qformat->importprocess($importfile, $params->matchgrades) ) { // Process the uploaded file
error( $txt->importerror ,
"$CFG->wwwroot/question/import.php?courseid={$course->id}&category=$category->id");
}
<td><?php choose_from_menu($fileformatnames, "format", "gift", "");
helpbutton("import", $txt->importquestions, "quiz"); ?></td>
</tr>
+ <tr>
+ <td align="right"><?php echo $txt->matchgrades; ?></td>
+ <td><?php choose_from_menu($matchgrades,'matchgrades',$txt->matchgradeserror,'' );
+ helpbutton('matchgrades', $txt->matchgrades, 'quiz'); ?></td>
+ </td>
</table>
<?php
print_simple_box_end();