1 | <?php |
||||||
2 | /* Source: https://github.com/moodle/moodle/blob/MOODLE_310_STABLE/backup/cc/cc_lib/cc_version1.php under GNU/GPL license */ |
||||||
3 | |||||||
4 | /** |
||||||
5 | * Version 1 class of Common Cartridge. |
||||||
6 | */ |
||||||
7 | class CcVersion1 extends CcVersionBase |
||||||
8 | { |
||||||
9 | public const WEBCONTENT = 'webcontent'; |
||||||
10 | public const QUESTIONBANK = 'imsqti_xmlv1p2/imscc_xmlv1p0/question-bank'; |
||||||
11 | public const ASSESSMENT = 'imsqti_xmlv1p2/imscc_xmlv1p0/assessment'; |
||||||
12 | public const ASSOCIATEDCONTENT = 'associatedcontent/imscc_xmlv1p0/learning-application-resource'; |
||||||
13 | public const DISCUSSIONTOPIC = 'imsdt_xmlv1p0'; |
||||||
14 | public const WEBLINK = 'imswl_xmlv1p0'; |
||||||
15 | |||||||
16 | public static $checker = [self::WEBCONTENT, |
||||||
17 | self::ASSESSMENT, |
||||||
18 | self::ASSOCIATEDCONTENT, |
||||||
19 | self::DISCUSSIONTOPIC, |
||||||
20 | self::QUESTIONBANK, |
||||||
21 | self::WEBLINK, ]; |
||||||
22 | |||||||
23 | public function __construct() |
||||||
24 | { |
||||||
25 | $this->ccnamespaces = ['imscc' => 'http://www.imsglobal.org/xsd/imscc/imscp_v1p1', |
||||||
26 | 'lomimscc' => 'http://ltsc.ieee.org/xsd/imscc/LOM', |
||||||
27 | 'lom' => 'http://ltsc.ieee.org/xsd/LOM', |
||||||
28 | 'voc' => 'http://ltsc.ieee.org/xsd/LOM/vocab', |
||||||
29 | 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance', |
||||||
30 | ]; |
||||||
31 | |||||||
32 | $this->ccnsnames = [ |
||||||
33 | 'imscc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/imscp_v1p2_localised.xsd', |
||||||
34 | 'lom' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_2/lomLoose_localised.xsd', |
||||||
35 | 'lomimscc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_1/lomLoose_localised.xsd', |
||||||
36 | 'voc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_2/vocab/loose.xsd', |
||||||
37 | ]; |
||||||
38 | |||||||
39 | $this->ccversion = '1.0.0'; |
||||||
40 | $this->camversion = '1.0.0'; |
||||||
41 | $this->_generator = 'Common Cartridge generator'; |
||||||
42 | } |
||||||
43 | |||||||
44 | /** |
||||||
45 | * Validate if the type are valid or not. |
||||||
46 | * |
||||||
47 | * @param string $type |
||||||
48 | * |
||||||
49 | * @return bool |
||||||
50 | */ |
||||||
51 | public function valid($type) |
||||||
52 | { |
||||||
53 | return in_array($type, self::$checker); |
||||||
54 | } |
||||||
55 | |||||||
56 | /** |
||||||
57 | * Create Education Metadata (How To). |
||||||
58 | * |
||||||
59 | * @param object $met |
||||||
60 | * @param object $xmlnode |
||||||
61 | * |
||||||
62 | * @return DOMNode |
||||||
63 | */ |
||||||
64 | public function createMetadataEducational($met, DOMDocument &$doc, $xmlnode) |
||||||
65 | { |
||||||
66 | $nd = $doc->createElementNS($this->ccnamespaces['lom'], 'educational'); |
||||||
67 | $nd2 = $doc->createElementNS($this->ccnamespaces['lom'], 'intendedEndUserRole'); |
||||||
68 | $nd3 = $doc->createElementNS($this->ccnamespaces['voc'], 'vocabulary'); |
||||||
69 | |||||||
70 | $xmlnode->appendChild($nd); |
||||||
71 | $nd->appendChild($nd2); |
||||||
72 | $nd2->appendChild($nd3); |
||||||
73 | |||||||
74 | foreach ($met->arrayeducational as $name => $value) { |
||||||
75 | !is_array($value) ? $value = [$value] : null; |
||||||
76 | foreach ($value as $v) { |
||||||
77 | $nd4 = $doc->createElementNS($this->ccnamespaces['voc'], $name, $v[0]); |
||||||
78 | $nd3->appendChild($nd4); |
||||||
79 | } |
||||||
80 | } |
||||||
81 | |||||||
82 | return $nd; |
||||||
83 | } |
||||||
84 | |||||||
85 | protected function onCreate(DOMDocument &$doc, $rootmanifestnode = null, $nmanifestID = null) |
||||||
86 | { |
||||||
87 | $doc->formatOutput = true; |
||||||
88 | $doc->preserveWhiteSpace = true; |
||||||
89 | |||||||
90 | $this->manifestID = is_null($nmanifestID) ? CcHelpers::uuidgen('M_') : $nmanifestID; |
||||||
91 | $mUUID = $doc->createAttribute('identifier'); |
||||||
92 | $mUUID->nodeValue = $this->manifestID; |
||||||
93 | |||||||
94 | if (is_null($rootmanifestnode)) { |
||||||
95 | if (!empty($this->_generator)) { |
||||||
96 | $comment = $doc->createComment($this->_generator); |
||||||
97 | $doc->appendChild($comment); |
||||||
98 | } |
||||||
99 | |||||||
100 | $rootel = $doc->createElementNS($this->ccnamespaces['imscc'], 'manifest'); |
||||||
101 | $rootel->appendChild($mUUID); |
||||||
102 | $doc->appendChild($rootel); |
||||||
103 | |||||||
104 | // Add all namespaces. |
||||||
105 | foreach ($this->ccnamespaces as $key => $value) { |
||||||
106 | $dummy_attr = $key.":dummy"; |
||||||
107 | $doc->createAttributeNS($value, $dummy_attr); |
||||||
108 | } |
||||||
109 | |||||||
110 | // Add location of schemas. |
||||||
111 | $schemaLocation = ''; |
||||||
112 | foreach ($this->ccnsnames as $key => $value) { |
||||||
113 | $vt = empty($schemaLocation) ? '' : ' '; |
||||||
114 | $schemaLocation .= $vt.$this->ccnamespaces[$key].' '.$value; |
||||||
115 | } |
||||||
116 | $aSchemaLoc = $doc->createAttributeNS($this->ccnamespaces['xsi'], 'xsi:schemaLocation'); |
||||||
117 | $aSchemaLoc->nodeValue = $schemaLocation; |
||||||
118 | $rootel->appendChild($aSchemaLoc); |
||||||
119 | } else { |
||||||
120 | $rootel = $doc->createElementNS($this->ccnamespaces['imscc'], 'imscc:manifest'); |
||||||
121 | $rootel->appendChild($mUUID); |
||||||
122 | } |
||||||
123 | |||||||
124 | $metadata = $doc->createElementNS($this->ccnamespaces['imscc'], 'metadata'); |
||||||
125 | $schema = $doc->createElementNS($this->ccnamespaces['imscc'], 'schema', 'IMS Common Cartridge'); |
||||||
126 | $schemaversion = $doc->createElementNS($this->ccnamespaces['imscc'], 'schemaversion', $this->ccversion); |
||||||
127 | |||||||
128 | $metadata->appendChild($schema); |
||||||
129 | $metadata->appendChild($schemaversion); |
||||||
130 | $rootel->appendChild($metadata); |
||||||
131 | |||||||
132 | if (!is_null($rootmanifestnode)) { |
||||||
133 | $rootmanifestnode->appendChild($rootel); |
||||||
134 | } |
||||||
135 | |||||||
136 | $organizations = $doc->createElementNS($this->ccnamespaces['imscc'], 'organizations'); |
||||||
137 | $rootel->appendChild($organizations); |
||||||
138 | $resources = $doc->createElementNS($this->ccnamespaces['imscc'], 'resources'); |
||||||
139 | $rootel->appendChild($resources); |
||||||
140 | |||||||
141 | return true; |
||||||
142 | } |
||||||
143 | |||||||
144 | protected function updateAttribute(DOMDocument &$doc, $attrname, $attrvalue, DOMElement &$node) |
||||||
145 | { |
||||||
146 | $busenew = (is_object($node) && $node->hasAttribute($attrname)); |
||||||
147 | $nResult = null; |
||||||
148 | if (!$busenew && is_null($attrvalue)) { |
||||||
149 | $node->removeAttribute($attrname); |
||||||
150 | } else { |
||||||
151 | $nResult = $busenew ? $node->getAttributeNode($attrname) : $doc->createAttribute($attrname); |
||||||
152 | $nResult->nodeValue = $attrvalue; |
||||||
153 | if (!$busenew) { |
||||||
154 | $node->appendChild($nResult); |
||||||
155 | } |
||||||
156 | } |
||||||
157 | |||||||
158 | return $nResult; |
||||||
159 | } |
||||||
160 | |||||||
161 | protected function updateAttributeNs(DOMDocument &$doc, $attrname, $attrnamespace, $attrvalue, DOMElement &$node) |
||||||
162 | { |
||||||
163 | $busenew = (is_object($node) && $node->hasAttributeNS($attrnamespace, $attrname)); |
||||||
164 | $nResult = null; |
||||||
165 | if (!$busenew && is_null($attrvalue)) { |
||||||
166 | $node->removeAttributeNS($attrnamespace, $attrname); |
||||||
167 | } else { |
||||||
168 | $nResult = $busenew ? $node->getAttributeNodeNS($attrnamespace, $attrname) : |
||||||
169 | $doc->createAttributeNS($attrnamespace, $attrname); |
||||||
170 | $nResult->nodeValue = $attrvalue; |
||||||
171 | if (!$busenew) { |
||||||
172 | $node->appendChild($nResult); |
||||||
173 | } |
||||||
174 | } |
||||||
175 | |||||||
176 | return $nResult; |
||||||
177 | } |
||||||
178 | |||||||
179 | protected function getChildNode(DOMDocument &$doc, $itemname, DOMElement &$node) |
||||||
180 | { |
||||||
181 | $nlist = $node->getElementsByTagName($itemname); |
||||||
182 | $item = is_object($nlist) && ($nlist->length > 0) ? $nlist->item(0) : null; |
||||||
183 | |||||||
184 | return $item; |
||||||
185 | } |
||||||
186 | |||||||
187 | protected function updateChildItem(DOMDocument &$doc, $itemname, $itemvalue, DOMElement &$node, $attrtostore = null) |
||||||
188 | { |
||||||
189 | $tnode = $this->getChildNode($doc, 'title', $node); |
||||||
190 | $usenew = is_null($tnode); |
||||||
191 | $tnode = $usenew ? $doc->createElementNS($this->ccnamespaces['imscc'], $itemname) : $tnode; |
||||||
192 | if (!is_null($attrtostore)) { |
||||||
193 | foreach ($attrtostore as $key => $value) { |
||||||
194 | $this->updateAttribute($doc, $key, $value, $tnode); |
||||||
195 | } |
||||||
196 | } |
||||||
197 | $tnode->nodeValue = $itemvalue; |
||||||
198 | if ($usenew) { |
||||||
199 | $node->appendChild($tnode); |
||||||
200 | } |
||||||
201 | } |
||||||
202 | |||||||
203 | protected function updateItems($items, DOMDocument &$doc, DOMElement &$xmlnode) |
||||||
204 | { |
||||||
205 | foreach ($items as $key => $item) { |
||||||
206 | $itemnode = $doc->createElementNS($this->ccnamespaces['imscc'], 'item'); |
||||||
207 | $this->updateAttribute($doc, 'identifier', $key, $itemnode); |
||||||
208 | $this->updateAttribute($doc, 'identifierref', $item->identifierref, $itemnode); |
||||||
209 | $this->updateAttribute($doc, 'parameters', $item->parameters, $itemnode); |
||||||
210 | if (!empty($item->title)) { |
||||||
211 | $titlenode = $doc->createElementNS($this->ccnamespaces['imscc'], |
||||||
212 | 'title', |
||||||
213 | $item->title); |
||||||
214 | $itemnode->appendChild($titlenode); |
||||||
215 | } |
||||||
216 | if ($item->hasChildItems()) { |
||||||
217 | $this->updateItems($item->childitems, $doc, $itemnode); |
||||||
218 | } |
||||||
219 | $xmlnode->appendChild($itemnode); |
||||||
220 | } |
||||||
221 | } |
||||||
222 | |||||||
223 | /** |
||||||
224 | * Create a Resource (How to). |
||||||
225 | * |
||||||
226 | * @param object $xmlnode |
||||||
227 | * |
||||||
228 | * @return DOMNode |
||||||
229 | */ |
||||||
230 | protected function createResource(CcIResource &$res, DOMDocument &$doc, $xmlnode = null) |
||||||
231 | { |
||||||
232 | $usenew = is_object($xmlnode); |
||||||
233 | $dnode = $usenew ? $xmlnode : $doc->createElementNS($this->ccnamespaces['imscc'], "resource"); |
||||||
234 | $this->updateAttribute($doc, 'identifier', $res->identifier, $dnode); |
||||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
235 | $this->updateAttribute($doc, 'type', $res->type, $dnode); |
||||||
0 ignored issues
–
show
|
|||||||
236 | !is_null($res->href) ? $this->updateAttribute($doc, 'href', $res->href, $dnode) : null; |
||||||
0 ignored issues
–
show
|
|||||||
237 | $this->updateAttribute($doc, 'base', $res->base, $dnode); |
||||||
0 ignored issues
–
show
|
|||||||
238 | |||||||
239 | foreach ($res->files as $file) { |
||||||
0 ignored issues
–
show
|
|||||||
240 | $nd = $doc->createElementNS($this->ccnamespaces['imscc'], 'file'); |
||||||
241 | $ndatt = $doc->createAttribute('href'); |
||||||
242 | $ndatt->nodeValue = $file; |
||||||
243 | $nd->appendChild($ndatt); |
||||||
244 | $dnode->appendChild($nd); |
||||||
245 | } |
||||||
246 | $this->resources[$res->identifier] = $res; |
||||||
247 | $this->resourcesInd[$res->files[0]] = $res->identifier; |
||||||
248 | |||||||
249 | foreach ($res->dependency as $dependency) { |
||||||
0 ignored issues
–
show
|
|||||||
250 | $nd = $doc->createElementNS($this->ccnamespaces['imscc'], 'dependency'); |
||||||
251 | $ndatt = $doc->createAttribute('identifierref'); |
||||||
252 | $ndatt->nodeValue = $dependency; |
||||||
253 | $nd->appendChild($ndatt); |
||||||
254 | $dnode->appendChild($nd); |
||||||
255 | } |
||||||
256 | |||||||
257 | return $dnode; |
||||||
258 | } |
||||||
259 | |||||||
260 | /** |
||||||
261 | * Create an Item Folder (How To). |
||||||
262 | * |
||||||
263 | * @param DOMElement $xmlnode |
||||||
264 | */ |
||||||
265 | protected function createItemFolder(CcIOrganization &$org, DOMDocument &$doc, DOMElement &$xmlnode = null) |
||||||
266 | { |
||||||
267 | $itemfoldernode = $doc->createElementNS($this->ccnamespaces['imscc'], 'item'); |
||||||
268 | $this->updateAttribute($doc, 'identifier', "root", $itemfoldernode); |
||||||
269 | |||||||
270 | if ($org->hasItems()) { |
||||||
271 | $this->updateItems($org->itemlist, $doc, $itemfoldernode); |
||||||
0 ignored issues
–
show
|
|||||||
272 | } |
||||||
273 | if (is_null($this->organizations)) { |
||||||
274 | $this->organizations = []; |
||||||
275 | } |
||||||
276 | $this->organizations[$org->identifier] = $org; |
||||||
0 ignored issues
–
show
|
|||||||
277 | |||||||
278 | $xmlnode->appendChild($itemfoldernode); |
||||||
0 ignored issues
–
show
The method
appendChild() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
279 | } |
||||||
280 | |||||||
281 | /** |
||||||
282 | * Create an Organization (How To). |
||||||
283 | * |
||||||
284 | * @param object $xmlnode |
||||||
285 | * |
||||||
286 | * @return DOMNode |
||||||
287 | */ |
||||||
288 | protected function createOrganization(CcIOrganization &$org, DOMDocument &$doc, $xmlnode = null) |
||||||
289 | { |
||||||
290 | $usenew = is_object($xmlnode); |
||||||
291 | $dnode = $usenew ? $xmlnode : $doc->createElementNS($this->ccnamespaces['imscc'], "organization"); |
||||||
292 | $this->updateAttribute($doc, 'identifier', $org->identifier, $dnode); |
||||||
0 ignored issues
–
show
|
|||||||
293 | $this->updateAttribute($doc, 'structure', $org->structure, $dnode); |
||||||
0 ignored issues
–
show
|
|||||||
294 | |||||||
295 | $this->createItemFolder($org, $doc, $dnode); |
||||||
296 | |||||||
297 | return $dnode; |
||||||
298 | } |
||||||
299 | |||||||
300 | /** |
||||||
301 | * Create Metadata For Manifest (How To). |
||||||
302 | * |
||||||
303 | * @param object $xmlnode |
||||||
304 | * |
||||||
305 | * @return DOMNode |
||||||
306 | */ |
||||||
307 | protected function createMetadataManifest(CcIMetadataManifest $met, DOMDocument &$doc, $xmlnode = null) |
||||||
308 | { |
||||||
309 | $dnode = $doc->createElementNS($this->ccnamespaces['lomimscc'], "lom"); |
||||||
310 | if (!empty($xmlnode)) { |
||||||
311 | $xmlnode->appendChild($dnode); |
||||||
312 | } |
||||||
313 | $dnodegeneral = empty($met->arraygeneral) ? null : $this->createMetadataGeneral($met, $doc, $xmlnode); |
||||||
0 ignored issues
–
show
|
|||||||
314 | $dnodetechnical = empty($met->arraytech) ? null : $this->createMetadataTechnical($met, $doc, $xmlnode); |
||||||
0 ignored issues
–
show
|
|||||||
315 | $dnoderights = empty($met->arrayrights) ? null : $this->createMetadataRights($met, $doc, $xmlnode); |
||||||
0 ignored issues
–
show
|
|||||||
316 | $dnodelifecycle = empty($met->arraylifecycle) ? null : $this->createMetadataLifecycle($met, $doc, $xmlnode); |
||||||
0 ignored issues
–
show
|
|||||||
317 | |||||||
318 | !is_null($dnodegeneral) ? $dnode->appendChild($dnodegeneral) : null; |
||||||
319 | !is_null($dnodetechnical) ? $dnode->appendChild($dnodetechnical) : null; |
||||||
320 | !is_null($dnoderights) ? $dnode->appendChild($dnoderights) : null; |
||||||
321 | !is_null($dnodelifecycle) ? $dnode->appendChild($dnodelifecycle) : null; |
||||||
322 | |||||||
323 | return $dnode; |
||||||
324 | } |
||||||
325 | |||||||
326 | /** |
||||||
327 | * Create Metadata For Resource (How To). |
||||||
328 | * |
||||||
329 | * @param object $xmlnode |
||||||
330 | * |
||||||
331 | * @return DOMNode |
||||||
332 | */ |
||||||
333 | protected function createMetadataResource(CcIMetadataResource $met, DOMDocument &$doc, $xmlnode = null) |
||||||
334 | { |
||||||
335 | $dnode = $doc->createElementNS($this->ccnamespaces['lom'], "lom"); |
||||||
336 | |||||||
337 | !empty($xmlnode) ? $xmlnode->appendChild($dnode) : null; |
||||||
338 | !empty($met->arrayeducational) ? $this->createMetadataEducational($met, $doc, $dnode) : null; |
||||||
0 ignored issues
–
show
|
|||||||
339 | |||||||
340 | return $dnode; |
||||||
341 | } |
||||||
342 | |||||||
343 | /** |
||||||
344 | * Create Metadata For File (How To). |
||||||
345 | * |
||||||
346 | * @param object $xmlnode |
||||||
347 | * |
||||||
348 | * @return DOMNode |
||||||
349 | */ |
||||||
350 | protected function createMetadataFile(CcIMetadataFile $met, DOMDocument &$doc, $xmlnode = null) |
||||||
351 | { |
||||||
352 | $dnode = $doc->createElementNS($this->ccnamespaces['lom'], "lom"); |
||||||
353 | |||||||
354 | !empty($xmlnode) ? $xmlnode->appendChild($dnode) : null; |
||||||
355 | !empty($met->arrayeducational) ? $this->createMetadataEducational($met, $doc, $dnode) : null; |
||||||
0 ignored issues
–
show
|
|||||||
356 | |||||||
357 | return $dnode; |
||||||
358 | } |
||||||
359 | |||||||
360 | /** |
||||||
361 | * Create General Metadata (How To). |
||||||
362 | * |
||||||
363 | * @param object $met |
||||||
364 | * @param object $xmlnode |
||||||
365 | * |
||||||
366 | * @return DOMNode |
||||||
367 | */ |
||||||
368 | protected function createMetadataGeneral($met, DOMDocument &$doc, $xmlnode) |
||||||
369 | { |
||||||
370 | $nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'general'); |
||||||
371 | |||||||
372 | foreach ($met->arraygeneral as $name => $value) { |
||||||
373 | !is_array($value) ? $value = [$value] : null; |
||||||
374 | foreach ($value as $v) { |
||||||
375 | if ($name != 'language' && $name != 'catalog' && $name != 'entry') { |
||||||
376 | $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name); |
||||||
377 | $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'string', $v[1]); |
||||||
378 | $ndatt = $doc->createAttribute('language'); |
||||||
379 | $ndatt->nodeValue = $v[0]; |
||||||
380 | $nd3->appendChild($ndatt); |
||||||
381 | $nd2->appendChild($nd3); |
||||||
382 | $nd->appendChild($nd2); |
||||||
383 | } else { |
||||||
384 | if ($name == 'language') { |
||||||
385 | $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name, $v[0]); |
||||||
386 | $nd->appendChild($nd2); |
||||||
387 | } |
||||||
388 | } |
||||||
389 | } |
||||||
390 | } |
||||||
391 | if (!empty($met->arraygeneral['catalog']) || !empty($met->arraygeneral['entry'])) { |
||||||
392 | $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'identifier'); |
||||||
393 | $nd->appendChild($nd2); |
||||||
394 | if (!empty($met->arraygeneral['catalog'])) { |
||||||
395 | $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'catalog', $met->arraygeneral['catalog'][0][0]); |
||||||
396 | $nd2->appendChild($nd3); |
||||||
397 | } |
||||||
398 | if (!empty($met->arraygeneral['entry'])) { |
||||||
399 | $nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'entry', $met->arraygeneral['entry'][0][0]); |
||||||
400 | $nd2->appendChild($nd4); |
||||||
401 | } |
||||||
402 | } |
||||||
403 | |||||||
404 | return $nd; |
||||||
405 | } |
||||||
406 | |||||||
407 | /** |
||||||
408 | * Create Technical Metadata (How To). |
||||||
409 | * |
||||||
410 | * @param object $met |
||||||
411 | * @param object $xmlnode |
||||||
412 | * |
||||||
413 | * @return DOMNode |
||||||
414 | */ |
||||||
415 | protected function createMetadataTechnical($met, DOMDocument &$doc, $xmlnode) |
||||||
416 | { |
||||||
417 | $nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'technical'); |
||||||
418 | $xmlnode->appendChild($nd); |
||||||
419 | |||||||
420 | foreach ($met->arraytech as $name => $value) { |
||||||
421 | !is_array($value) ? $value = [$value] : null; |
||||||
422 | foreach ($value as $v) { |
||||||
423 | $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name, $v[0]); |
||||||
424 | $nd->appendChild($nd2); |
||||||
425 | } |
||||||
426 | } |
||||||
427 | |||||||
428 | return $nd; |
||||||
429 | } |
||||||
430 | |||||||
431 | /** |
||||||
432 | * Create Rights Metadata (How To). |
||||||
433 | * |
||||||
434 | * @param object $met |
||||||
435 | * @param object $xmlnode |
||||||
436 | * |
||||||
437 | * @return DOMNode |
||||||
438 | */ |
||||||
439 | protected function createMetadataRights($met, DOMDocument &$doc, $xmlnode) |
||||||
440 | { |
||||||
441 | $nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'rights'); |
||||||
442 | |||||||
443 | foreach ($met->arrayrights as $name => $value) { |
||||||
444 | !is_array($value) ? $value = [$value] : null; |
||||||
445 | foreach ($value as $v) { |
||||||
446 | if ($name == 'description') { |
||||||
447 | $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name); |
||||||
448 | $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'string', $v[1]); |
||||||
449 | $ndatt = $doc->createAttribute('language'); |
||||||
450 | $ndatt->nodeValue = $v[0]; |
||||||
451 | $nd3->appendChild($ndatt); |
||||||
452 | $nd2->appendChild($nd3); |
||||||
453 | $nd->appendChild($nd2); |
||||||
454 | } elseif ($name == 'copyrightAndOtherRestrictions' || $name == 'cost') { |
||||||
455 | $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name); |
||||||
456 | $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'value', $v[0]); |
||||||
457 | $nd2->appendChild($nd3); |
||||||
458 | $nd->appendChild($nd2); |
||||||
459 | } |
||||||
460 | } |
||||||
461 | } |
||||||
462 | |||||||
463 | return $nd; |
||||||
464 | } |
||||||
465 | |||||||
466 | /** |
||||||
467 | * Create Lifecycle Metadata (How To). |
||||||
468 | * |
||||||
469 | * @param object $met |
||||||
470 | * @param object $met |
||||||
471 | * @param object $xmlnode |
||||||
472 | * |
||||||
473 | * @return DOMNode |
||||||
474 | */ |
||||||
475 | protected function createMetadataLifecycle($met, DOMDocument &$doc, $xmlnode) |
||||||
476 | { |
||||||
477 | $nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'lifeCycle'); |
||||||
478 | $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'contribute'); |
||||||
479 | |||||||
480 | $nd->appendChild($nd2); |
||||||
481 | $xmlnode->appendChild($nd); |
||||||
482 | |||||||
483 | foreach ($met->arraylifecycle as $name => $value) { |
||||||
484 | !is_array($value) ? $value = [$value] : null; |
||||||
485 | foreach ($value as $v) { |
||||||
486 | if ($name == 'role') { |
||||||
487 | $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name); |
||||||
488 | $nd2->appendChild($nd3); |
||||||
489 | $nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'value', $v[0]); |
||||||
490 | $nd3->appendChild($nd4); |
||||||
491 | } else { |
||||||
492 | if ($name == 'date') { |
||||||
493 | $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name); |
||||||
494 | $nd2->appendChild($nd3); |
||||||
495 | $nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'dateTime', $v[0]); |
||||||
496 | $nd3->appendChild($nd4); |
||||||
497 | } else { |
||||||
498 | $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name, $v[0]); |
||||||
499 | $nd2->appendChild($nd3); |
||||||
500 | } |
||||||
501 | } |
||||||
502 | } |
||||||
503 | } |
||||||
504 | |||||||
505 | return $nd; |
||||||
506 | } |
||||||
507 | } |
||||||
508 |