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; }
public function on_generate_feedbacks() { $general_question_feedback = $this->questions->nodeValue('generalfeedback', $this->question_node); if (empty($general_question_feedback)) { return; } $name = 'general_fb'; //Add question general feedback - the one that should be always displayed $result = cc_helpers::process_linked_files($general_question_feedback, $this->manifest, $this->rootpath, $this->contextid, $this->outdir); cc_assesment_helper::add_feedback($this->qitem, $result[0], cc_qti_values::htmltype, $name); pkg_resource_dependencies::instance()->add($result[1]); $this->general_feedback = $name; }
/** * * 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}"); } } } } } } }
/** * * Is the element visible in the course? * @throws RuntimeException * @return bool */ protected function is_visible() { $tdoc = new XMLGenericDocument(); if (!$tdoc->load($this->path . DIRECTORY_SEPARATOR . 'module.xml')) { throw new RuntimeException('File does not exist!'); } $visible = (int) $tdoc->nodeValue('/module/visible'); return $visible > 0; }