/** * * Stores any files that need to be stored */ protected function store(general_cc_file $doc, $outdir, $title, $deps = null) { $rdir = new cc_resource_location($outdir); $rtp = $rdir->fullpath(true) . $this->defaultname; if ($doc->saveTo($rtp)) { $resource = new cc_resource($rdir->rootdir(), $this->defaultname, $rdir->dirname(true)); $resource->dependency = empty($deps) ? array() : $deps; $res = $this->manifest->add_resource($resource, null, $this->cc_type); $resitem = new cc_item(); $resitem->attach_resource($res[0]); $resitem->title = $title; $this->item->add_child_item($resitem); } else { throw new RuntimeException("Unable to save file {$rtp}!"); } }
/** * * Enter description here ... * @param unknown_type $packagedir * @param unknown_type $outdir * @throws DOMException * @throws InvalidArgumentException */ public static function convert($packagedir, $outdir) { $dir = realpath($packagedir); if (empty($dir)) { throw new InvalidArgumentException('Directory does not exist!'); } $odir = realpath($outdir); if (empty($odir)) { throw new InvalidArgumentException('Directory does not exist!'); } $coursefile = $dir . DIRECTORY_SEPARATOR . 'course' . DIRECTORY_SEPARATOR . 'course.xml'; $doc = new XMLGenericDocument(); if ($doc->load($coursefile)) { $course_name = $doc->nodeValue('/course/fullname'); $course_desc = $doc->nodeValue('/course/summary'); $course_language = $doc->nodeValue('/course/lang'); $course_language = empty($course_language) ? 'en' : $course_language; $course_category = $doc->nodeValue('/course/category/name'); //Initialize the manifest metadata class $meta = new cc_metadata_manifest(); //Package metadata $metageneral = new cc_metadata_general(); $metageneral->set_language($course_language); $metageneral->set_title($course_name, $course_language); $metageneral->set_description($course_desc, $course_language); $metageneral->set_catalog('category'); $metageneral->set_entry($course_category); $meta->add_metadata_general($metageneral); // Create the manifest $manifest = new cc_manifest(cc_version::v11); $manifest->add_metadata_manifest($meta); $organization = null; //Package structure - default organization and resources //Get the course structure - this will be transformed into organization //Step 1 - Get the list and order of sections/topics $moodle_backup = $dir . DIRECTORY_SEPARATOR . 'moodle_backup.xml'; $secp = new XMLGenericDocument(); $docp = new XMLGenericDocument(); if ($docp->load($moodle_backup)) { //sections $sections = array(); $coursef = new XMLGenericDocument(); $course_file = $dir . DIRECTORY_SEPARATOR . 'course' . DIRECTORY_SEPARATOR . 'course.xml'; $coursef->load($course_file); //$numsections = (int)$coursef->nodeValue('/course/numsections'); // TODO MDL-35781, this is commented because numsections is now optional attribute $section_list = $docp->nodeList('/moodle_backup/information/contents/sections/section'); if (!empty($section_list)) { $count = 0; foreach ($section_list as $node) { //if ($count > $numsections) { // break; //} $sectionid = $docp->nodeValue('sectionid', $node); $sectiontitle = $docp->nodeValue('title', $node); $sectionpath = $docp->nodeValue('directory', $node); $sequence = array(); //Get section stuff $section_file = $dir . DIRECTORY_SEPARATOR . $sectionpath . DIRECTORY_SEPARATOR . 'section.xml'; if ($secp->load($section_file)) { $rawvalue = $secp->nodeValue('/section/sequence'); if ($rawvalue != '$@NULL@$') { $sequence = explode(',', $rawvalue); } } $sections[$sectionid] = array($sectiontitle, $sequence); $count++; } } //organization title $organization = new cc_organization(); //Add section/topic items foreach ($sections as $sectionid => $values) { $item = new cc_item(); $item->title = $values[0]; self::process_sequence($item, $manifest, $values[1], $dir, $odir); $organization->add_item($item); } $manifest->put_nodes(); } if (!empty($organization)) { $manifest->add_new_organization($organization); } $manifestpath = $outdir . DIRECTORY_SEPARATOR . 'imsmanifest.xml'; $manifest->saveTo($manifestpath); } }