See Release Notes
Long Term Support Release
Differences Between: [Versions 401 and 402] [Versions 401 and 403]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 /** 18 * @package moodlecore 19 * @subpackage backup-imscc 20 * @copyright 2011 Darko Miletic (dmiletic@moodlerooms.com) 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.'); 25 26 require_once($CFG->dirroot . '/backup/cc/cc2moodle.php'); 27 require_once($CFG->dirroot . '/backup/cc/entities11.class.php'); 28 require_once($CFG->dirroot . '/backup/cc/entity11.resource.class.php'); 29 require_once($CFG->dirroot . '/backup/cc/entity11.forum.class.php'); 30 require_once($CFG->dirroot . '/backup/cc/entity11.quiz.class.php'); 31 require_once($CFG->dirroot . '/backup/cc/entity11.lti.class.php'); 32 33 class cc112moodle extends cc2moodle { 34 const CC_TYPE_FORUM = 'imsdt_xmlv1p1'; 35 const CC_TYPE_QUIZ = 'imsqti_xmlv1p2/imscc_xmlv1p1/assessment'; 36 const CC_TYPE_QUESTION_BANK = 'imsqti_xmlv1p2/imscc_xmlv1p1/question-bank'; 37 const CC_TYPE_WEBLINK = 'imswl_xmlv1p1'; 38 const CC_TYPE_ASSOCIATED_CONTENT = 'associatedcontent/imscc_xmlv1p1/learning-application-resource'; 39 const CC_TYPE_BASICLTI = 'imsbasiclti_xmlv1p0'; 40 41 public static $namespaces = array('imscc' => 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', 42 'lomimscc' => 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', 43 'lom' => 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', 44 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 45 'cc' => 'http://www.imsglobal.org/xsd/imsccv1p1/imsccauth_v1p1'); 46 47 public static $restypes = array('associatedcontent/imscc_xmlv1p1/learning-application-resource', 'webcontent'); 48 public static $forumns = array('dt' => 'http://www.imsglobal.org/xsd/imsccv1p1/imsdt_v1p1'); 49 public static $quizns = array('xmlns' => 'http://www.imsglobal.org/xsd/ims_qtiasiv1p2'); 50 public static $resourcens = array('wl' => 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1'); 51 public static $basicltins = array( 52 'xmlns' => 'http://www.imsglobal.org/xsd/imslticc_v1p0', 53 'blti' => 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0', 54 'lticm' => 'http://www.imsglobal.org/xsd/imslticm_v1p0', 55 'lticp' => 'http://www.imsglobal.org/xsd/imslticp_v1p0' 56 ); 57 58 59 public function __construct($path_to_manifest) { 60 parent::__construct($path_to_manifest); 61 } 62 63 public function generate_moodle_xml () { 64 65 global $CFG; 66 $cdir = static::$path_to_manifest_folder . DIRECTORY_SEPARATOR . 'course_files'; 67 68 if (!file_exists($cdir)) { 69 mkdir($cdir, $CFG->directorypermissions, true); 70 } 71 72 $sheet_base = static::loadsheet(SHEET_BASE); 73 74 // MOODLE_BACKUP / INFO / DETAILS / MOD 75 $node_info_details_mod = $this->create_code_info_details_mod(); 76 77 // MOODLE_BACKUP / BLOCKS / BLOCK 78 $node_course_blocks_block = $this->create_node_course_blocks_block(); 79 80 // MOODLE_BACKUP / COURSES / SECTIONS / SECTION 81 $node_course_sections_section = $this->create_node_course_sections_section(); 82 83 // MOODLE_BACKUP / COURSES / QUESTION_CATEGORIES 84 $node_course_question_categories = $this->create_node_question_categories(); 85 86 // MOODLE_BACKUP / COURSES / MODULES / MOD 87 $node_course_modules_mod = $this->create_node_course_modules_mod(); 88 89 // MOODLE_BACKUP / COURSE / HEADER 90 $node_course_header = $this->create_node_course_header(); 91 92 // GENERAL INFO 93 $filename = optional_param('file', 'not_available.zip', PARAM_RAW); 94 $filename = basename($filename); 95 96 $www_root = $CFG->wwwroot; 97 98 $find_tags = array('[#zip_filename#]', 99 '[#www_root#]', 100 '[#node_course_header#]', 101 '[#node_info_details_mod#]', 102 '[#node_course_blocks_block#]', 103 '[#node_course_sections_section#]', 104 '[#node_course_question_categories#]', 105 '[#node_course_modules#]'); 106 107 $replace_values = array($filename, 108 $www_root, 109 $node_course_header, 110 $node_info_details_mod, 111 $node_course_blocks_block, 112 $node_course_sections_section, 113 $node_course_question_categories, 114 $node_course_modules_mod); 115 116 $result_xml = str_replace($find_tags, $replace_values, $sheet_base); 117 118 // COPY RESOURSE FILES 119 $entities = new entities11(); 120 121 $entities->move_all_files(); 122 123 if (array_key_exists("index", self::$instances)) { 124 125 if (!file_put_contents(static::$path_to_manifest_folder . DIRECTORY_SEPARATOR . 'moodle.xml', $result_xml)) { 126 static::log_action('Cannot save the moodle manifest file: ' . static::$path_to_tmp_folder . DIRECTORY_SEPARATOR . 'moodle.xml', true); 127 } else { 128 $status = true; 129 } 130 131 } else { 132 $status = false; 133 static::log_action('The course is empty', false); 134 } 135 136 return $status; 137 138 } 139 140 public function convert_to_moodle_type ($cc_type) { 141 $type = parent::convert_to_moodle_type($cc_type); 142 143 if ($type == TYPE_UNKNOWN) { 144 if ($cc_type == static::CC_TYPE_BASICLTI) { 145 $type = MOODLE_TYPE_LTI; 146 } 147 } 148 149 return $type; 150 } 151 152 protected function create_node_question_categories () { 153 154 $quiz = new cc11_quiz(); 155 156 static::log_action('Creating node: QUESTION_CATEGORIES'); 157 158 $node_course_question_categories = $quiz->generate_node_question_categories(); 159 160 return $node_course_question_categories; 161 } 162 163 protected function create_code_info_details_mod () { 164 $result = parent::create_code_info_details_mod(); 165 166 $count_blti = $this->count_instances(MOODLE_TYPE_LTI); 167 168 $sheet_info_details_mod_instances_instance = static::loadsheet(SHEET_INFO_DETAILS_MOD_INSTANCE); 169 170 $blti_mod = ''; 171 172 if ($count_blti > 0) { 173 $blti_instance = $this->create_mod_info_details_mod_instances_instance($sheet_info_details_mod_instances_instance, $count_blti, static::$instances['instances'][MOODLE_TYPE_LTI]); 174 $blti_mod = $blti_instance ? $this->create_mod_info_details_mod(MOODLE_TYPE_LTI, $blti_instance) : ''; 175 } 176 177 return $result . $blti_mod; 178 } 179 180 /** 181 * (non-PHPdoc) 182 * @see cc2moodle::get_module_visible() 183 */ 184 protected function get_module_visible($identifier) { 185 //Should item be hidden or not 186 $mod_visible = 1; 187 if (!empty($identifier)) { 188 $xpath = static::newx_path(static::$manifest, static::$namespaces); 189 $query = '/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $identifier . '"]'; 190 $query .= '//lom:intendedEndUserRole/lom:value'; 191 $intendeduserrole = $xpath->query($query); 192 if (!empty($intendeduserrole) && ($intendeduserrole->length > 0)) { 193 $role = trim($intendeduserrole->item(0)->nodeValue); 194 if ((strcasecmp('Instructor', $role) === 0) || (strcasecmp('Mentor', $role) === 0)) { 195 $mod_visible = 0; 196 } 197 } 198 } 199 return $mod_visible; 200 } 201 202 protected function create_node_course_modules_mod () { 203 $labels = new cc_label(); 204 $resources = new cc11_resource(); 205 $forums = new cc11_forum(); 206 $quiz = new cc11_quiz(); 207 $basiclti = new cc11_lti(); 208 209 static::log_action('Creating node: COURSE/MODULES/MOD'); 210 211 // LABELS 212 $node_course_modules_mod_label = $labels->generate_node(); 213 214 // RESOURCES (WEB CONTENT AND WEB LINK) 215 $node_course_modules_mod_resource = $resources->generate_node(); 216 217 // FORUMS 218 $node_course_modules_mod_forum = $forums->generate_node(); 219 220 // QUIZ 221 $node_course_modules_mod_quiz = $quiz->generate_node_course_modules_mod(); 222 223 //BasicLTI 224 $node_course_modules_mod_basiclti = $basiclti->generate_node(); 225 226 $node_course_modules = $node_course_modules_mod_label. 227 $node_course_modules_mod_resource . 228 $node_course_modules_mod_forum . 229 $node_course_modules_mod_quiz . 230 $node_course_modules_mod_basiclti; 231 232 return $node_course_modules; 233 } 234 235 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body