function readquestions($lines) { /// Parses an array of lines into an array of questions, /// where each item is a question object as defined by /// readquestion(). // set courseid and baseurl global $CFG, $COURSE, $course; switch (true) { case isset($this->course->id): // import to quiz module $courseid = $this->course->id; break; case isset($course->id): // import to lesson module $courseid = $course->id; break; case isset($COURSE->id): // last resort $courseid = $COURSE->id; break; default: // shouldn't happen !! $courseid = 0; } require_once $CFG->libdir . '/filelib.php'; $baseurl = get_file_url($courseid) . '/'; // get import file name global $params; if (!empty($this->realfilename)) { $filename = $this->realfilename; } else { if (isset($params) && !empty($params->choosefile)) { // course file (Moodle >=1.6+) $filename = $params->choosefile; } else { // uploaded file (all Moodles) $filename = basename($_FILES['newfile']['tmp_name']); } } // get hotpot file source $source = implode($lines, " "); $source = hotpot_convert_relative_urls($source, $baseurl, $filename); // create xml tree for this hotpot $xml = new hotpot_xml_tree($source); // determine the quiz type $xml->quiztype = ''; $keys = array_keys($xml->xml); foreach ($keys as $key) { if (preg_match('/^(hotpot|textoys)-(\\w+)-file$/i', $key, $matches)) { $xml->quiztype = strtolower($matches[2]); $xml->xml_root = "['{$key}']['#']"; break; } } // convert xml to questions array $questions = array(); switch ($xml->quiztype) { case 'jcloze': $this->process_jcloze($xml, $questions); break; case 'jcross': $this->process_jcross($xml, $questions); break; case 'jmatch': $this->process_jmatch($xml, $questions); break; case 'jmix': $this->process_jmix($xml, $questions); break; case 'jbc': case 'jquiz': $this->process_jquiz($xml, $questions); break; default: if (empty($xml->quiztype)) { notice("Input file not recognized as a Hot Potatoes XML file"); } else { notice("Unknown quiz type '{$xml->quiztype}'"); } } // end switch if (count($questions)) { return $questions; } else { if (method_exists($this, 'error')) { // Moodle >= 1.8 $this->error(get_string('giftnovalidquestion', 'quiz')); } return false; } }
function readquestions($lines) { /// Parses an array of lines into an array of questions, /// where each item is a question object as defined by /// readquestion(). // set baseurl global $CFG; if ($CFG->slasharguments) { $baseurl = "{$CFG->wwwroot}/file.php/{$this->course->id}/"; } else { $baseurl = "{$CFG->wwwroot}/file.php?file=/{$this->course->id}/"; } // get import file name global $params; if (isset($params) && !empty($params->choosefile)) { // course file (Moodle >=1.6+) $filename = $params->choosefile; } else { // uploaded file (all Moodles) $filename = basename($_FILES['newfile']['tmp_name']); } // get hotpot file source $source = implode($lines, " "); $source = hotpot_convert_relative_urls($source, $baseurl, $filename); // create xml tree for this hotpot $xml = new hotpot_xml_tree($source); // determine the quiz type $xml->quiztype = ''; $keys = array_keys($xml->xml); foreach ($keys as $key) { if (preg_match('/^(hotpot|textoys)-(\\w+)-file$/i', $key, $matches)) { $xml->quiztype = strtolower($matches[2]); $xml->xml_root = "['{$key}']['#']"; break; } } // convert xml to questions array $questions = array(); switch ($xml->quiztype) { case 'jcloze': $this->process_jcloze($xml, $questions); break; case 'jcross': $this->process_jcross($xml, $questions); break; case 'jmatch': $this->process_jmatch($xml, $questions); break; case 'jmix': $this->process_jmix($xml, $questions); break; case 'jbc': case 'jquiz': $this->process_jquiz($xml, $questions); break; default: if (empty($xml->quiztype)) { notice("Input file not recognized as a Hot Potatoes XML file"); } else { notice("Unknown quiz type '{$xml->quiztype}'"); } } // end switch return $questions; }