|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00024 defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.'); 00025 00026 require_once($CFG->dirroot . '/backup/cc/cc2moodle.php'); 00027 require_once($CFG->dirroot . '/backup/cc/entities11.class.php'); 00028 require_once($CFG->dirroot . '/backup/cc/entity11.resource.class.php'); 00029 require_once($CFG->dirroot . '/backup/cc/entity11.forum.class.php'); 00030 require_once($CFG->dirroot . '/backup/cc/entity11.quiz.class.php'); 00031 require_once($CFG->dirroot . '/backup/cc/entity11.lti.class.php'); 00032 00033 class cc112moodle extends cc2moodle { 00034 const CC_TYPE_FORUM = 'imsdt_xmlv1p1'; 00035 const CC_TYPE_QUIZ = 'imsqti_xmlv1p2/imscc_xmlv1p1/assessment'; 00036 const CC_TYPE_QUESTION_BANK = 'imsqti_xmlv1p2/imscc_xmlv1p1/question-bank'; 00037 const CC_TYPE_WEBLINK = 'imswl_xmlv1p1'; 00038 const CC_TYPE_ASSOCIATED_CONTENT = 'associatedcontent/imscc_xmlv1p1/learning-application-resource'; 00039 const CC_TYPE_BASICLTI = 'imsbasiclti_xmlv1p0'; 00040 00041 public static $namespaces = array('imscc' => 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', 00042 'lomimscc' => 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', 00043 'lom' => 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', 00044 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 00045 'cc' => 'http://www.imsglobal.org/xsd/imsccv1p1/imsccauth_v1p1'); 00046 00047 public static $restypes = array('associatedcontent/imscc_xmlv1p1/learning-application-resource', 'webcontent'); 00048 public static $forumns = array('dt' => 'http://www.imsglobal.org/xsd/imsccv1p1/imsdt_v1p1'); 00049 public static $quizns = array('xmlns' => 'http://www.imsglobal.org/xsd/ims_qtiasiv1p2'); 00050 public static $resourcens = array('wl' => 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1'); 00051 public static $basicltins = array( 00052 'xmlns' => 'http://www.imsglobal.org/xsd/imslticc_v1p0', 00053 'blti' => 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0', 00054 'lticm' => 'http://www.imsglobal.org/xsd/imslticm_v1p0', 00055 'lticp' => 'http://www.imsglobal.org/xsd/imslticp_v1p0' 00056 ); 00057 00058 00059 public function __construct($path_to_manifest) { 00060 parent::__construct($path_to_manifest); 00061 } 00062 00063 public function generate_moodle_xml () { 00064 00065 global $CFG; 00066 $cdir = static::$path_to_manifest_folder . DIRECTORY_SEPARATOR . 'course_files'; 00067 00068 if (!file_exists($cdir)) { 00069 mkdir($cdir); 00070 } 00071 00072 $sheet_base = static::loadsheet(SHEET_BASE); 00073 00074 // MOODLE_BACKUP / INFO / DETAILS / MOD 00075 $node_info_details_mod = $this->create_code_info_details_mod(); 00076 00077 // MOODLE_BACKUP / BLOCKS / BLOCK 00078 $node_course_blocks_block = $this->create_node_course_blocks_block(); 00079 00080 // MOODLE_BACKUP / COURSES / SECTIONS / SECTION 00081 $node_course_sections_section = $this->create_node_course_sections_section(); 00082 00083 // MOODLE_BACKUP / COURSES / QUESTION_CATEGORIES 00084 $node_course_question_categories = $this->create_node_question_categories(); 00085 00086 // MOODLE_BACKUP / COURSES / MODULES / MOD 00087 $node_course_modules_mod = $this->create_node_course_modules_mod(); 00088 00089 // MOODLE_BACKUP / COURSE / HEADER 00090 $node_course_header = $this->create_node_course_header(); 00091 00092 // GENERAL INFO 00093 $filename = optional_param('file', 'not_available.zip', PARAM_RAW); 00094 $filename = basename($filename); 00095 00096 $www_root = $CFG->wwwroot; 00097 00098 $find_tags = array('[#zip_filename#]', 00099 '[#www_root#]', 00100 '[#node_course_header#]', 00101 '[#node_info_details_mod#]', 00102 '[#node_course_blocks_block#]', 00103 '[#node_course_sections_section#]', 00104 '[#node_course_question_categories#]', 00105 '[#node_course_modules#]'); 00106 00107 $replace_values = array($filename, 00108 $www_root, 00109 $node_course_header, 00110 $node_info_details_mod, 00111 $node_course_blocks_block, 00112 $node_course_sections_section, 00113 $node_course_question_categories, 00114 $node_course_modules_mod); 00115 00116 $result_xml = str_replace($find_tags, $replace_values, $sheet_base); 00117 00118 // COPY RESOURSE FILES 00119 $entities = new entities11(); 00120 00121 $entities->move_all_files(); 00122 00123 if (array_key_exists("index", self::$instances)) { 00124 00125 if (!file_put_contents(static::$path_to_manifest_folder . DIRECTORY_SEPARATOR . 'moodle.xml', $result_xml)) { 00126 static::log_action('Cannot save the moodle manifest file: ' . static::$path_to_tmp_folder . DIRECTORY_SEPARATOR . 'moodle.xml', true); 00127 } else { 00128 $status = true; 00129 } 00130 00131 } else { 00132 $status = false; 00133 static::log_action('The course is empty', false); 00134 } 00135 00136 return $status; 00137 00138 } 00139 00140 public function convert_to_moodle_type ($cc_type) { 00141 $type = parent::convert_to_moodle_type($cc_type); 00142 00143 if ($type == TYPE_UNKNOWN) { 00144 if ($cc_type == static::CC_TYPE_BASICLTI) { 00145 $type = MOODLE_TYPE_LTI; 00146 } 00147 } 00148 00149 return $type; 00150 } 00151 00152 protected function create_node_question_categories () { 00153 00154 $quiz = new cc11_quiz(); 00155 00156 static::log_action('Creating node: QUESTION_CATEGORIES'); 00157 00158 $node_course_question_categories = $quiz->generate_node_question_categories(); 00159 00160 return $node_course_question_categories; 00161 } 00162 00163 protected function create_code_info_details_mod () { 00164 $result = parent::create_code_info_details_mod(); 00165 00166 $count_blti = $this->count_instances(MOODLE_TYPE_LTI); 00167 00168 $sheet_info_details_mod_instances_instance = static::loadsheet(SHEET_INFO_DETAILS_MOD_INSTANCE); 00169 00170 $blti_mod = ''; 00171 00172 if ($count_blti > 0) { 00173 $blti_instance = $this->create_mod_info_details_mod_instances_instance($sheet_info_details_mod_instances_instance, $count_blti, static::$instances['instances'][MOODLE_TYPE_LTI]); 00174 $blti_mod = $blti_instance ? $this->create_mod_info_details_mod(MOODLE_TYPE_LTI, $blti_instance) : ''; 00175 } 00176 00177 return $result . $blti_mod; 00178 } 00179 00184 protected function get_module_visible($identifier) { 00185 //Should item be hidden or not 00186 $mod_visible = 1; 00187 if (!empty($identifier)) { 00188 $xpath = static::newx_path(static::$manifest, static::$namespaces); 00189 $query = '/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $identifier . '"]'; 00190 $query .= '//lom:intendedEndUserRole/lom:value'; 00191 $intendeduserrole = $xpath->query($query); 00192 if (!empty($intendeduserrole) && ($intendeduserrole->length > 0)) { 00193 $role = trim($intendeduserrole->item(0)->nodeValue); 00194 if ((strcasecmp('Instructor', $role) === 0) || (strcasecmp('Mentor', $role) === 0)) { 00195 $mod_visible = 0; 00196 } 00197 } 00198 } 00199 return $mod_visible; 00200 } 00201 00202 protected function create_node_course_modules_mod () { 00203 $labels = new cc_label(); 00204 $resources = new cc11_resource(); 00205 $forums = new cc11_forum(); 00206 $quiz = new cc11_quiz(); 00207 $basiclti = new cc11_lti(); 00208 00209 static::log_action('Creating node: COURSE/MODULES/MOD'); 00210 00211 // LABELS 00212 $node_course_modules_mod_label = $labels->generate_node(); 00213 00214 // RESOURCES (WEB CONTENT AND WEB LINK) 00215 $node_course_modules_mod_resource = $resources->generate_node(); 00216 00217 // FORUMS 00218 $node_course_modules_mod_forum = $forums->generate_node(); 00219 00220 // QUIZ 00221 $node_course_modules_mod_quiz = $quiz->generate_node_course_modules_mod(); 00222 00223 //BasicLTI 00224 $node_course_modules_mod_basiclti = $basiclti->generate_node(); 00225 00226 $node_course_modules = $node_course_modules_mod_label. 00227 $node_course_modules_mod_resource . 00228 $node_course_modules_mod_forum . 00229 $node_course_modules_mod_quiz . 00230 $node_course_modules_mod_basiclti; 00231 00232 return $node_course_modules; 00233 } 00234 00235 }