Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/cc/cc_lib/cc_resources.php
Go to the documentation of this file.
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/>.
00016 
00024 require_once 'cc_interfaces.php';
00025 require_once 'xmlbase.php';
00026 require_once 'gral_lib/pathutils.php';
00027 require_once 'gral_lib/ccdependencyparser.php';
00028 require_once 'cc_version_base.php';
00029 require_once 'cc_version1.php';
00030 require_once 'cc_manifest.php';
00031 
00036 class cc_version{
00037   const v1  = 1;
00038   const v11 = 11;
00039 }
00040 
00041 
00042 class cc1_resource_type {
00043     const   webcontent          = 'webcontent';
00044     const   questionbank        = 'imsqti_xmlv1p2/imscc_xmlv1p0/question-bank';
00045     const   assessment          = 'imsqti_xmlv1p2/imscc_xmlv1p0/assessment';
00046     const   associatedcontent   = 'associatedcontent/imscc_xmlv1p0/learning-application-resource';
00047     const   discussiontopic     = 'imsdt_xmlv1p0';
00048     const   weblink             = 'imswl_xmlv1p0';
00049 
00050     public static $checker = array(self::webcontent,
00051                                     self::assessment,
00052                                     self::associatedcontent,
00053                                     self::discussiontopic,
00054                                     self::questionbank,
00055                                     self::weblink);
00056 
00057 }
00058 
00059 class cc11_resource_type {
00060     const webcontent         = 'webcontent';
00061     const questionbank       = 'imsqti_xmlv1p2/imscc_xmlv1p1/question-bank';
00062     const assessment         = 'imsqti_xmlv1p2/imscc_xmlv1p1/assessment';
00063     const associatedcontent  = 'associatedcontent/imscc_xmlv1p1/learning-application-resource';
00064     const discussiontopic    = 'imsdt_xmlv1p1';
00065     const weblink            = 'imswl_xmlv1p1';
00066     const basiclti           = 'imsbasiclti_xmlv1p0';
00067 
00068     public static $checker = array(self::webcontent,
00069                                     self::assessment,
00070                                     self::associatedcontent,
00071                                     self::discussiontopic,
00072                                     self::questionbank,
00073                                     self::weblink,
00074                                     self::basiclti);
00075 
00076 }
00077 
00078 
00083 class cc_resource implements cc_i_resource {
00084 
00085     public  $identifier     = null;
00086     public  $type           = null;
00087     public  $dependency     = array();
00088     public  $identifierref  = null;
00089     public  $href           = null;
00090     public  $base           = null;
00091     public  $persiststate   = null;
00092     public  $filename       = null;
00093     public  $files          = array();
00094     public  $isempty        = null;
00095     public  $manifestroot   = null;
00096     public  $folder         = null;
00097 
00098     private $throwonerror   = true;
00099 
00100     public function __construct($manifest, $file, $folder='', $throwonerror = true) {
00101         $this->throwonerror = $throwonerror;
00102         if (is_string($manifest)) {
00103             $this->folder = $folder;
00104             $this->process_resource($manifest, $file,$folder);
00105             $this->manifestroot = $manifest;
00106         } else if (is_object($manifest)) {
00107             $this->import_resource($file,$manifest.$folder);
00108         }
00109     }
00110 
00117     public function add_resource ($fname, $location =''){
00118         $this->process_resource($fname,$location);
00119 
00120     }
00121 
00122 
00129     public function import_resource(DOMElement &$node, cc_i_manifest &$doc) {
00130 
00131         $searchstr = "//imscc:manifest[@identifier='".$doc->manifestID().
00132                      "']/imscc:resources/imscc:resource";
00133         $this->identifier   = $this->get_attr_value($node,"identifier");
00134         $this->type         = $this->get_attr_value($node,"type");
00135         $this->href         = $this->get_attr_value($node,"href");
00136         $this->base         = $this->get_attr_value($node,"base");
00137         $this->persiststate = null;
00138         $nodo               = $doc->nodeList($searchstr."[@identifier='".
00139                               $this->identifier."']/metadata/@href");
00140         $this->metadata     = $nodo->nodeValue;
00141         $this->filename     = $this->href;
00142         $nlist              = $doc->nodeList($searchstr."[@identifier='".
00143                               $this->identifier."']/imscc:file/@href");
00144         $this->files        = array();
00145         foreach ($nlist as $file) {
00146             $this->files[]  = $file->nodeValue;
00147         }
00148         $nlist              = $doc->nodeList($searchstr."[@identifier='".
00149                               $this->identifier."']/imscc:dependency/@identifierref");
00150         $this->dependency   = array();
00151         foreach ($nlist as $dependency) {
00152             $this->dependency[]  = $dependency->nodeValue;
00153         }
00154         $this->isempty      = false;
00155     }
00156 
00157 
00166     public function get_attr_value(&$nod, $name, $ns=null) {
00167       return is_null($ns) ?
00168              ($nod->hasAttribute($name) ? $nod->getAttribute($name) : null) :
00169              ($nod->hasAttributeNS($ns, $name) ? $nod->getAttributeNS($ns, $name) : null);
00170     }
00171 
00172 
00180     public function process_resource($manifestroot, &$fname, $folder) {
00181         $file = empty($folder) ? $manifestroot.'/'.$fname : $manifestroot.'/'.$folder.'/'.$fname;
00182         if (!file_exists($file) && $this->throwonerror){
00183             throw new Exception('The file doesnt exist!');
00184         }
00185 
00186         GetDepFiles($manifestroot, $fname, $this->folder, $this->files);
00187         array_unshift($this->files,$folder.$fname);
00188         $this->init_empty_new();
00189         $this->href             = $folder.$fname;
00190         $this->identifierref    = $folder.$fname;
00191         $this->filename         = $fname;
00192         $this->isempty          = false;
00193         $this->folder           = $folder;
00194     }
00195 
00196     public function adjust_path($mroot, $fname) {
00197         $result = null;
00198         if (file_exists($fname->filename)) {
00199             $result = pathDiff($fname->filename,$mroot);
00200 
00201         } else if (file_exists($mroot.$fname->filename) || file_exists($mroot.DIRECTORY_SEPARATOR.$fname->filename)) {
00202             $result = trim(toUrlPath($fname->filename),"/");
00203         }
00204         return $result;
00205     }
00206 
00207 
00208 
00209     public function init_clean() {
00210         $this->identifier       =   null;
00211         $this->type             =   null;
00212         $this->href             =   null;
00213         $this->base             =   null;
00214         $this->metadata         =   array();
00215         $this->dependency       =   array();
00216         $this->identifierref    =   null;
00217         $this->persiststate     =   null;
00218         $this->filename         =   '';
00219         $this->files            =   array();
00220         $this->isempty          =   true;
00221     }
00222 
00223 
00224     public function init_empty_new() {
00225         $this->identifier       =   cc_helpers::uuidgen('I_', '_R');
00226         $this->type             =   null;
00227         $this->href             =   null;
00228         $this->persiststate     =   null;
00229         $this->filename         =   null;
00230         $this->isempty          =   false;
00231         $this->identifierref    =   null;
00232     }
00233 
00234     public function get_manifestroot(){
00235         return $this->manifestroot;
00236     }
00237 
00238 }
 All Data Structures Namespaces Files Functions Variables Enumerations