/** * * Process the activites and create item structure * @param cc_i_item $item * @param array $sequence * @param string $packageroot - directory path * @throws DOMException */ protected static function process_sequence(cc_i_item &$item, cc_i_manifest &$manifest, array $sequence, $packageroot, $outdir) { $moodle_backup = $packageroot . DIRECTORY_SEPARATOR . 'moodle_backup.xml'; $doc = new XMLGenericDocument(); if (!$doc->load($moodle_backup)) { return; } $activities = $doc->nodeList('/moodle_backup/information/contents/activities/activity'); if (!empty($activities)) { $dpp = new XMLGenericDocument(); foreach ($activities as $activity) { $moduleid = $doc->nodeValue('moduleid', $activity); if (in_array($moduleid, $sequence)) { //detect activity type $directory = $doc->nodeValue('directory', $activity); $path = $packageroot . DIRECTORY_SEPARATOR . $directory; $module_file = $path . DIRECTORY_SEPARATOR . 'module.xml'; if ($dpp->load($module_file)) { $activity_type = $dpp->nodeValue('/module/modulename'); $activity_indentation = $dpp->nodeValue('/module/indent'); $aitem = self::item_indenter($item, $activity_indentation); $caller = "cc_converter_{$activity_type}"; if (class_exists($caller)) { $obj = new $caller($aitem, $manifest, $packageroot, $path); if (!$obj->convert($outdir)) { throw new RuntimeException("failed to convert {$activity_type}"); } } } } } } }
public static function embedded_mapping($packageroot, $contextid = null) { $main_file = $packageroot . DIRECTORY_SEPARATOR . 'files.xml'; $mfile = new XMLGenericDocument(); if (!$mfile->load($main_file)) { return false; } $query = "/files/file[filename!='.']"; if (!empty($contextid)) { $query .= "[contextid='{$contextid}']"; } $files = $mfile->nodeList($query); $depfiles = array(); foreach ($files as $node) { $mainfile = intval($mfile->nodeValue('sortorder', $node)); $filename = $mfile->nodeValue('filename', $node); $filepath = $mfile->nodeValue('filepath', $node); $source = $mfile->nodeValue('source', $node); $author = $mfile->nodeValue('author', $node); $license = $mfile->nodeValue('license', $node); $hashedname = $mfile->nodeValue('contenthash', $node); $hashpart = substr($hashedname, 0, 2); $location = 'files' . DIRECTORY_SEPARATOR . $hashpart . DIRECTORY_SEPARATOR . $hashedname; $type = $mfile->nodeValue('mimetype', $node); $depfiles[$filepath . $filename] = array($location, $mainfile == 1, strtolower(str_replace(' ', '_', $filename)), $type, $source, $author, $license, strtolower(str_replace(' ', '_', $filepath))); } return $depfiles; }
/** * * Checks if question has matching element * @param XMLGenericDocument $questions * @param object $question_node * @return bool */ public static function has_matching_element(XMLGenericDocument $questions, $question_node) { $answers = $questions->nodeList('plugin_qtype_shortanswer_question//answertext', $question_node); $result = false; foreach ($answers as $answer) { $prepare = str_replace('\\*', '\\#', $answer->nodeValue); $result = strpos($prepare, '*') !== false; if ($result) { break; } } return $result; }