|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00023 require_once 'cc_interfaces.php'; 00024 00025 abstract class cc_converter { 00031 protected $item = null; 00037 protected $manifest = null; 00043 protected $rootpath = null; 00049 protected $path = null; 00055 protected $defaultfile = null; 00061 protected $defaultname = null; 00067 protected $cc_type = null; 00073 protected $doc = null; 00074 00084 public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path){ 00085 $rpath = realpath($rootpath); 00086 if (empty($rpath)) { 00087 throw new InvalidArgumentException('Invalid path!'); 00088 } 00089 $rpath2 = realpath($path); 00090 if (empty($rpath)) { 00091 throw new InvalidArgumentException('Invalid path!'); 00092 } 00093 $doc = new XMLGenericDocument(); 00094 if (!$doc->load($path . DIRECTORY_SEPARATOR . $this->defaultfile)) { 00095 throw new RuntimeException('File does not exist!'); 00096 } 00097 00098 $this->doc = $doc; 00099 $this->item = $item; 00100 $this->manifest = $manifest; 00101 $this->rootpath = $rpath; 00102 $this->path = $rpath2; 00103 } 00104 00111 abstract public function convert($outdir); 00112 00117 protected function store(general_cc_file $doc, $outdir, $title, $deps = null) { 00118 $rdir = new cc_resource_location($outdir); 00119 $rtp = $rdir->fullpath(true).$this->defaultname; 00120 if ( $doc->saveTo($rtp) ) { 00121 $resource = new cc_resource($rdir->rootdir(), $this->defaultname, $rdir->dirname(true)); 00122 $resource->dependency = empty($deps) ? array() : $deps; 00123 $res = $this->manifest->add_resource($resource, null, $this->cc_type); 00124 $resitem = new cc_item(); 00125 $resitem->attach_resource($res[0]); 00126 $resitem->title = $title; 00127 $this->item->add_child_item($resitem); 00128 } else { 00129 throw new RuntimeException("Unable to save file {$rtp}!"); 00130 } 00131 } 00132 }