Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/converter/imscc11/lib.php
Go to the documentation of this file.
00001 <?php
00002 
00012 require_once($CFG->dirroot . '/backup/converter/convertlib.php');
00013 require_once($CFG->dirroot . '/backup/cc/includes/constants.php');
00014 require_once($CFG->dirroot . '/backup/cc/cc112moodle.php');
00015 require_once($CFG->dirroot . '/backup/cc/validator.php');
00016 
00017 
00018 class imscc11_converter extends base_converter {
00019 
00030     public function log($message, $level, $a = null, $depth = null, $display = false) {
00031         parent::log('(imscc1) '.$message, $level, $a, $depth, $display);
00032     }
00033 
00040     public static function detect_format($tempdir) {
00041         global $CFG;
00042 
00043         $filepath = $CFG->dataroot . '/temp/backup/' . $tempdir;
00044         $manifest = cc112moodle::get_manifest($filepath);
00045         if (file_exists($manifest)) {
00046             // looks promising, lets load some information
00047             $handle = fopen($manifest, 'r');
00048             $xml_snippet = fread($handle, 500);
00049             fclose($handle);
00050 
00051             // check if it has the required strings
00052 
00053             $xml_snippet = strtolower($xml_snippet);
00054             $xml_snippet = preg_replace('/\s*/m', '', $xml_snippet);
00055             $xml_snippet = str_replace("'", '', $xml_snippet);
00056             $xml_snippet = str_replace('"', '', $xml_snippet);
00057 
00058             $search_string = "xmlns=http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1";
00059             if (strpos($xml_snippet, $search_string) !== false) {
00060                 return backup::FORMAT_IMSCC11;
00061             }
00062         }
00063 
00064         return null;
00065     }
00066 
00067 
00076     public static function description() {
00077 
00078         return array(
00079                 'from'  => backup::FORMAT_IMSCC11,
00080                 'to'    => backup::FORMAT_MOODLE1,
00081                 'cost'  => 10
00082         );
00083     }
00084 
00085     protected function execute() {
00086         global $CFG;
00087 
00088         $manifest = cc112moodle::get_manifest($this->get_tempdir_path());
00089         if (empty($manifest)) {
00090             throw new imscc11_convert_exception('No Manifest detected!');
00091         }
00092 
00093         $this->log('validating manifest', backup::LOG_DEBUG, null, 1);
00094         $validator = new manifest_validator($CFG->dirroot . '/backup/cc/schemas11');
00095         if (!$validator->validate($manifest)) {
00096             $this->log('validation error(s): '.PHP_EOL.error_messages::instance(), backup::LOG_DEBUG, null, 2);
00097             throw new imscc11_convert_exception(error_messages::instance()->to_string(true));
00098         }
00099         $manifestdir = dirname($manifest);
00100         $cc112moodle = new cc112moodle($manifest);
00101         if ($cc112moodle->is_auth()) {
00102             throw new imscc11_convert_exception('protected_cc_not_supported');
00103         }
00104         $status = $cc112moodle->generate_moodle_xml();
00105         //Final cleanup
00106         $xml_error = new libxml_errors_mgr(true);
00107         $mdoc = new DOMDocument();
00108         $mdoc->preserveWhiteSpace = false;
00109         $mdoc->formatOutput = true;
00110         $mdoc->validateOnParse = false;
00111         $mdoc->strictErrorChecking = false;
00112         if ($mdoc->load($manifestdir.'/moodle.xml', LIBXML_NONET)) {
00113             $mdoc->save($this->get_workdir_path().'/moodle.xml', LIBXML_NOEMPTYTAG);
00114         } else {
00115             $xml_error->collect();
00116             $this->log('validation error(s): '.PHP_EOL.error_messages::instance(), backup::LOG_DEBUG, null, 2);
00117             throw new imscc11_convert_exception(error_messages::instance()->to_string(true));
00118         }
00119         //Move the files to the workdir
00120         rename($manifestdir.'/course_files', $this->get_workdir_path().'/course_files');
00121     }
00122 
00123 
00124 }
00125 
00129 class imscc11_convert_exception extends convert_exception {
00130 }
 All Data Structures Namespaces Files Functions Variables Enumerations