2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * @package backup-convert
19 * @subpackage cc-library
20 * @copyright 2011 Darko Miletic <dmiletic@moodlerooms.com>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 require_once('cc_version1.php');
27 * Version 1.1 class of Common Cartridge
30 class cc_version11
extends cc_version1
{
31 const webcontent
= 'webcontent';
32 const questionbank
= 'imsqti_xmlv1p2/imscc_xmlv1p1/question-bank';
33 const assessment
= 'imsqti_xmlv1p2/imscc_xmlv1p1/assessment';
34 const associatedcontent
= 'associatedcontent/imscc_xmlv1p1/learning-application-resource';
35 const discussiontopic
= 'imsdt_xmlv1p1';
36 const weblink
= 'imswl_xmlv1p1';
37 const basiclti
= 'imsbasiclti_xmlv1p0';
39 public static $checker = array(self
::webcontent
,
41 self
::associatedcontent
,
42 self
::discussiontopic
,
48 * Validate if the type are valid or not
53 public function valid($type) {
54 return in_array($type, self
::$checker);
57 public function __construct() {
58 $this->ccnamespaces
= array('imscc' => 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1',
59 'lomimscc' => 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest' ,
60 'lom' => 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource' ,
61 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance'
64 $this->ccnsnames
= array('imscc' => 'http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd' ,
65 'lomimscc' => 'http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd',
66 'lom' => 'http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd'
69 $this->ccversion
= '1.1.0';
70 $this->camversion
= '1.1.0';
71 $this->_generator
= 'Moodle 2 Common Cartridge generator';
74 protected function update_items($items, DOMDocument
&$doc, DOMElement
&$xmlnode) {
75 foreach ($items as $key => $item) {
76 $itemnode = $doc->createElementNS($this->ccnamespaces
['imscc'], 'item');
77 $this->update_attribute($doc, 'identifier' , $key , $itemnode);
78 $this->update_attribute($doc, 'identifierref', $item->identifierref
, $itemnode);
79 if (!is_null($item->title
)) {
80 $titlenode = $doc->createElementNS($this->ccnamespaces
['imscc'], 'title');
81 $titlenode->appendChild(new DOMText($item->title
));
82 $itemnode->appendChild($titlenode);
84 if ($item->has_child_items()) {
85 $this->update_items($item->childitems
, $doc, $itemnode);
87 $xmlnode->appendChild($itemnode);
92 * Create Education Metadata (How To)
95 * @param DOMDocument $doc
96 * @param object $xmlnode
99 public function create_metadata_educational($met, DOMDocument
&$doc, $xmlnode) {
100 $metadata = $doc->createElementNS($this->ccnamespaces
['imscc'], 'metadata');
101 $xmlnode->insertBefore($metadata, $xmlnode->firstChild
);
102 $lom = $doc->createElementNS($this->ccnamespaces
['lom'], 'lom');
103 $metadata->appendChild($lom);
104 $educational = $doc->createElementNS($this->ccnamespaces
['lom'], 'educational');
105 $lom->appendChild($educational);
107 foreach ($met->arrayeducational
as $value) {
108 !is_array($value) ?
$value = array($value) : null;
109 foreach ($value as $v) {
110 $userrole = $doc->createElementNS($this->ccnamespaces
['lom'], 'intendedEndUserRole');
111 $educational->appendChild($userrole);
112 $nd4 = $doc->createElementNS($this->ccnamespaces
['lom'], 'source', 'IMSGLC_CC_Rolesv1p1');
113 $nd5 = $doc->createElementNS($this->ccnamespaces
['lom'], 'value', $v[0]);
114 $userrole->appendChild($nd4);
115 $userrole->appendChild($nd5);