Passed
Pull Request — master (#6921)
by
unknown
09:03
created

CcVersion1::createMetadataLifecycle()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 22
c 1
b 0
f 0
nc 9
nop 3
dl 0
loc 31
rs 8.9457
1
<?php
2
3
/* Source: https://github.com/moodle/moodle/blob/MOODLE_310_STABLE/backup/cc/cc_lib/cc_version1.php under GNU/GPL license */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CourseBundle\Component\CourseCopy\CommonCartridge\Export\Base;
8
9
use Chamilo\CourseBundle\Component\CourseCopy\CommonCartridge\Export\Interfaces\CcIMetadataFile;
10
use Chamilo\CourseBundle\Component\CourseCopy\CommonCartridge\Export\Interfaces\CcIMetadataManifest;
11
use Chamilo\CourseBundle\Component\CourseCopy\CommonCartridge\Export\Interfaces\CcIMetadataResource;
12
use Chamilo\CourseBundle\Component\CourseCopy\CommonCartridge\Export\Interfaces\CcIOrganization;
13
use Chamilo\CourseBundle\Component\CourseCopy\CommonCartridge\Export\Interfaces\CcIResource;
14
use Chamilo\CourseBundle\Component\CourseCopy\CommonCartridge\Export\Utils\CcHelpers;
15
use DOMDocument;
16
use DOMElement;
17
18
/**
19
 * Version 1 class of Common Cartridge.
20
 */
21
class CcVersion1 extends CcVersionBase
22
{
23
    public const WEBCONTENT = 'webcontent';
24
    public const QUESTIONBANK = 'imsqti_xmlv1p2/imscc_xmlv1p0/question-bank';
25
    public const ASSESSMENT = 'imsqti_xmlv1p2/imscc_xmlv1p0/assessment';
26
    public const ASSOCIATEDCONTENT = 'associatedcontent/imscc_xmlv1p0/learning-application-resource';
27
    public const DISCUSSIONTOPIC = 'imsdt_xmlv1p0';
28
    public const WEBLINK = 'imswl_xmlv1p0';
29
30
    public static $checker = [self::WEBCONTENT,
31
        self::ASSESSMENT,
32
        self::ASSOCIATEDCONTENT,
33
        self::DISCUSSIONTOPIC,
34
        self::QUESTIONBANK,
35
        self::WEBLINK, ];
36
37
    public function __construct()
38
    {
39
        $this->ccnamespaces = ['imscc' => 'http://www.imsglobal.org/xsd/imscc/imscp_v1p1',
40
            'lomimscc' => 'http://ltsc.ieee.org/xsd/imscc/LOM',
41
            'lom' => 'http://ltsc.ieee.org/xsd/LOM',
42
            'voc' => 'http://ltsc.ieee.org/xsd/LOM/vocab',
43
            'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
44
        ];
45
46
        $this->ccnsnames = [
47
            'imscc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/imscp_v1p2_localised.xsd',
48
            'lom' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_2/lomLoose_localised.xsd',
49
            'lomimscc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_1/lomLoose_localised.xsd',
50
            'voc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_2/vocab/loose.xsd',
51
        ];
52
53
        $this->ccversion = '1.0.0';
54
        $this->camversion = '1.0.0';
55
        $this->_generator = 'Common Cartridge generator';
56
    }
57
58
    /**
59
     * Validate if the type are valid or not.
60
     *
61
     * @param string $type
62
     *
63
     * @return bool
64
     */
65
    public function valid($type)
66
    {
67
        return \in_array($type, self::$checker);
68
    }
69
70
    /**
71
     * Create Education Metadata (How To).
72
     *
73
     * @param object $met
74
     * @param object $xmlnode
75
     *
76
     * @return DOMNode
0 ignored issues
show
Bug introduced by
The type Chamilo\CourseBundle\Com...dge\Export\Base\DOMNode was not found. Did you mean DOMNode? If so, make sure to prefix the type with \.
Loading history...
77
     */
78
    public function createMetadataEducational($met, DOMDocument &$doc, $xmlnode)
79
    {
80
        $nd = $doc->createElementNS($this->ccnamespaces['lom'], 'educational');
81
        $nd2 = $doc->createElementNS($this->ccnamespaces['lom'], 'intendedEndUserRole');
82
        $nd3 = $doc->createElementNS($this->ccnamespaces['voc'], 'vocabulary');
83
84
        $xmlnode->appendChild($nd);
85
        $nd->appendChild($nd2);
86
        $nd2->appendChild($nd3);
87
88
        foreach ($met->arrayeducational as $name => $value) {
89
            !\is_array($value) ? $value = [$value] : null;
90
            foreach ($value as $v) {
91
                $nd4 = $doc->createElementNS($this->ccnamespaces['voc'], $name, $v[0]);
92
                $nd3->appendChild($nd4);
93
            }
94
        }
95
96
        return $nd;
97
    }
98
99
    protected function onCreate(DOMDocument &$doc, $rootmanifestnode = null, $nmanifestID = null)
100
    {
101
        $doc->formatOutput = true;
102
        $doc->preserveWhiteSpace = true;
103
104
        $this->manifestID = null === $nmanifestID ? CcHelpers::uuidgen('M_') : $nmanifestID;
105
        $mUUID = $doc->createAttribute('identifier');
106
        $mUUID->nodeValue = $this->manifestID;
107
108
        if (null === $rootmanifestnode) {
109
            if (!empty($this->_generator)) {
110
                $comment = $doc->createComment($this->_generator);
111
                $doc->appendChild($comment);
112
            }
113
114
            $rootel = $doc->createElementNS($this->ccnamespaces['imscc'], 'manifest');
115
            $rootel->appendChild($mUUID);
116
            $doc->appendChild($rootel);
117
118
            // Add all namespaces.
119
            foreach ($this->ccnamespaces as $key => $value) {
120
                $dummy_attr = $key.':dummy';
121
                $doc->createAttributeNS($value, $dummy_attr);
122
            }
123
124
            // Add location of schemas.
125
            $schemaLocation = '';
126
            foreach ($this->ccnsnames as $key => $value) {
127
                $vt = empty($schemaLocation) ? '' : ' ';
128
                $schemaLocation .= $vt.$this->ccnamespaces[$key].' '.$value;
129
            }
130
            $aSchemaLoc = $doc->createAttributeNS($this->ccnamespaces['xsi'], 'xsi:schemaLocation');
131
            $aSchemaLoc->nodeValue = $schemaLocation;
132
            $rootel->appendChild($aSchemaLoc);
133
        } else {
134
            $rootel = $doc->createElementNS($this->ccnamespaces['imscc'], 'imscc:manifest');
135
            $rootel->appendChild($mUUID);
136
        }
137
138
        $metadata = $doc->createElementNS($this->ccnamespaces['imscc'], 'metadata');
139
        $schema = $doc->createElementNS($this->ccnamespaces['imscc'], 'schema', 'IMS Common Cartridge');
140
        $schemaversion = $doc->createElementNS($this->ccnamespaces['imscc'], 'schemaversion', $this->ccversion);
141
142
        $metadata->appendChild($schema);
143
        $metadata->appendChild($schemaversion);
144
        $rootel->appendChild($metadata);
145
146
        if (null !== $rootmanifestnode) {
147
            $rootmanifestnode->appendChild($rootel);
148
        }
149
150
        $organizations = $doc->createElementNS($this->ccnamespaces['imscc'], 'organizations');
151
        $rootel->appendChild($organizations);
152
        $resources = $doc->createElementNS($this->ccnamespaces['imscc'], 'resources');
153
        $rootel->appendChild($resources);
154
155
        return true;
156
    }
157
158
    protected function updateAttribute(DOMDocument &$doc, $attrname, $attrvalue, DOMElement &$node)
159
    {
160
        $busenew = (\is_object($node) && $node->hasAttribute($attrname));
161
        $nResult = null;
162
        if (!$busenew && null === $attrvalue) {
163
            $node->removeAttribute($attrname);
164
        } else {
165
            $nResult = $busenew ? $node->getAttributeNode($attrname) : $doc->createAttribute($attrname);
166
            $nResult->nodeValue = $attrvalue;
167
            if (!$busenew) {
168
                $node->appendChild($nResult);
169
            }
170
        }
171
172
        return $nResult;
173
    }
174
175
    protected function updateAttributeNs(DOMDocument &$doc, $attrname, $attrnamespace, $attrvalue, DOMElement &$node)
176
    {
177
        $busenew = (\is_object($node) && $node->hasAttributeNS($attrnamespace, $attrname));
178
        $nResult = null;
179
        if (!$busenew && null === $attrvalue) {
180
            $node->removeAttributeNS($attrnamespace, $attrname);
181
        } else {
182
            $nResult = $busenew ? $node->getAttributeNodeNS($attrnamespace, $attrname) :
183
                $doc->createAttributeNS($attrnamespace, $attrname);
184
            $nResult->nodeValue = $attrvalue;
185
            if (!$busenew) {
186
                $node->appendChild($nResult);
187
            }
188
        }
189
190
        return $nResult;
191
    }
192
193
    protected function getChildNode(DOMDocument &$doc, $itemname, DOMElement &$node)
194
    {
195
        $nlist = $node->getElementsByTagName($itemname);
196
        $item = \is_object($nlist) && ($nlist->length > 0) ? $nlist->item(0) : null;
197
198
        return $item;
199
    }
200
201
    protected function updateChildItem(DOMDocument &$doc, $itemname, $itemvalue, DOMElement &$node, $attrtostore = null): void
202
    {
203
        $tnode = $this->getChildNode($doc, 'title', $node);
204
        $usenew = null === $tnode;
205
        $tnode = $usenew ? $doc->createElementNS($this->ccnamespaces['imscc'], $itemname) : $tnode;
206
        if (null !== $attrtostore) {
207
            foreach ($attrtostore as $key => $value) {
208
                $this->updateAttribute($doc, $key, $value, $tnode);
209
            }
210
        }
211
        $tnode->nodeValue = $itemvalue;
212
        if ($usenew) {
213
            $node->appendChild($tnode);
214
        }
215
    }
216
217
    protected function updateItems($items, DOMDocument &$doc, DOMElement &$xmlnode): void
218
    {
219
        foreach ($items as $key => $item) {
220
            $itemnode = $doc->createElementNS($this->ccnamespaces['imscc'], 'item');
221
            $this->updateAttribute($doc, 'identifier', $key, $itemnode);
222
            $this->updateAttribute($doc, 'identifierref', $item->identifierref, $itemnode);
223
            $this->updateAttribute($doc, 'parameters', $item->parameters, $itemnode);
224
            if (!empty($item->title)) {
225
                $titlenode = $doc->createElementNS(
226
                    $this->ccnamespaces['imscc'],
227
                    'title',
228
                    $item->title
229
                );
230
                $itemnode->appendChild($titlenode);
231
            }
232
            if ($item->hasChildItems()) {
233
                $this->updateItems($item->childitems, $doc, $itemnode);
234
            }
235
            $xmlnode->appendChild($itemnode);
236
        }
237
    }
238
239
    /**
240
     * Create a Resource (How to).
241
     *
242
     * @param object $xmlnode
243
     *
244
     * @return DOMNode
245
     */
246
    protected function createResource(CcIResource &$res, DOMDocument &$doc, $xmlnode = null)
247
    {
248
        $usenew = \is_object($xmlnode);
249
        $dnode = $usenew ? $xmlnode : $doc->createElementNS($this->ccnamespaces['imscc'], 'resource');
250
        $this->updateAttribute($doc, 'identifier', $res->identifier, $dnode);
0 ignored issues
show
Bug introduced by
Accessing identifier on the interface Chamilo\CourseBundle\Com...\Interfaces\CcIResource suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
251
        $this->updateAttribute($doc, 'type', $res->type, $dnode);
0 ignored issues
show
Bug introduced by
Accessing type on the interface Chamilo\CourseBundle\Com...\Interfaces\CcIResource suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
252
        null !== $res->href ? $this->updateAttribute($doc, 'href', $res->href, $dnode) : null;
0 ignored issues
show
Bug introduced by
Accessing href on the interface Chamilo\CourseBundle\Com...\Interfaces\CcIResource suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
253
        $this->updateAttribute($doc, 'base', $res->base, $dnode);
0 ignored issues
show
Bug introduced by
Accessing base on the interface Chamilo\CourseBundle\Com...\Interfaces\CcIResource suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
254
255
        foreach ($res->files as $file) {
0 ignored issues
show
Bug introduced by
Accessing files on the interface Chamilo\CourseBundle\Com...\Interfaces\CcIResource suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
256
            $nd = $doc->createElementNS($this->ccnamespaces['imscc'], 'file');
257
            $ndatt = $doc->createAttribute('href');
258
            $ndatt->nodeValue = $file;
259
            $nd->appendChild($ndatt);
260
            $dnode->appendChild($nd);
261
        }
262
        $this->resources[$res->identifier] = $res;
263
        $this->resourcesInd[$res->files[0]] = $res->identifier;
264
265
        foreach ($res->dependency as $dependency) {
0 ignored issues
show
Bug introduced by
Accessing dependency on the interface Chamilo\CourseBundle\Com...\Interfaces\CcIResource suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
266
            $nd = $doc->createElementNS($this->ccnamespaces['imscc'], 'dependency');
267
            $ndatt = $doc->createAttribute('identifierref');
268
            $ndatt->nodeValue = $dependency;
269
            $nd->appendChild($ndatt);
270
            $dnode->appendChild($nd);
271
        }
272
273
        return $dnode;
274
    }
275
276
    /**
277
     * Create an Item Folder (How To).
278
     */
279
    protected function createItemFolder(CcIOrganization &$org, DOMDocument &$doc, ?DOMElement &$xmlnode = null): void
280
    {
281
        $itemfoldernode = $doc->createElementNS($this->ccnamespaces['imscc'], 'item');
282
        $this->updateAttribute($doc, 'identifier', 'root', $itemfoldernode);
283
284
        if ($org->hasItems()) {
285
            $this->updateItems($org->itemlist, $doc, $itemfoldernode);
0 ignored issues
show
Bug introduced by
Accessing itemlist on the interface Chamilo\CourseBundle\Com...erfaces\CcIOrganization suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
286
        }
287
        if (null === $this->organizations) {
288
            $this->organizations = [];
289
        }
290
        $this->organizations[$org->identifier] = $org;
0 ignored issues
show
Bug introduced by
Accessing identifier on the interface Chamilo\CourseBundle\Com...erfaces\CcIOrganization suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
291
292
        $xmlnode->appendChild($itemfoldernode);
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

292
        $xmlnode->/** @scrutinizer ignore-call */ 
293
                  appendChild($itemfoldernode);

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...
293
    }
294
295
    /**
296
     * Create an Organization (How To).
297
     *
298
     * @param object $xmlnode
299
     *
300
     * @return DOMNode
301
     */
302
    protected function createOrganization(CcIOrganization &$org, DOMDocument &$doc, $xmlnode = null)
303
    {
304
        $usenew = \is_object($xmlnode);
305
        $dnode = $usenew ? $xmlnode : $doc->createElementNS($this->ccnamespaces['imscc'], 'organization');
306
        $this->updateAttribute($doc, 'identifier', $org->identifier, $dnode);
0 ignored issues
show
Bug introduced by
Accessing identifier on the interface Chamilo\CourseBundle\Com...erfaces\CcIOrganization suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
307
        $this->updateAttribute($doc, 'structure', $org->structure, $dnode);
0 ignored issues
show
Bug introduced by
Accessing structure on the interface Chamilo\CourseBundle\Com...erfaces\CcIOrganization suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
308
309
        $this->createItemFolder($org, $doc, $dnode);
310
311
        return $dnode;
312
    }
313
314
    /**
315
     * Create Metadata For Manifest (How To).
316
     *
317
     * @param object $xmlnode
318
     *
319
     * @return DOMNode
320
     */
321
    protected function createMetadataManifest(CcIMetadataManifest $met, DOMDocument &$doc, $xmlnode = null)
322
    {
323
        $dnode = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'lom');
324
        if (!empty($xmlnode)) {
325
            $xmlnode->appendChild($dnode);
326
        }
327
        $dnodegeneral = empty($met->arraygeneral) ? null : $this->createMetadataGeneral($met, $doc, $xmlnode);
0 ignored issues
show
Bug introduced by
Accessing arraygeneral on the interface Chamilo\CourseBundle\Com...ces\CcIMetadataManifest suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
328
        $dnodetechnical = empty($met->arraytech) ? null : $this->createMetadataTechnical($met, $doc, $xmlnode);
0 ignored issues
show
Bug introduced by
Accessing arraytech on the interface Chamilo\CourseBundle\Com...ces\CcIMetadataManifest suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
329
        $dnoderights = empty($met->arrayrights) ? null : $this->createMetadataRights($met, $doc, $xmlnode);
0 ignored issues
show
Bug introduced by
Accessing arrayrights on the interface Chamilo\CourseBundle\Com...ces\CcIMetadataManifest suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
330
        $dnodelifecycle = empty($met->arraylifecycle) ? null : $this->createMetadataLifecycle($met, $doc, $xmlnode);
0 ignored issues
show
Bug introduced by
Accessing arraylifecycle on the interface Chamilo\CourseBundle\Com...ces\CcIMetadataManifest suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
331
332
        null !== $dnodegeneral ? $dnode->appendChild($dnodegeneral) : null;
333
        null !== $dnodetechnical ? $dnode->appendChild($dnodetechnical) : null;
334
        null !== $dnoderights ? $dnode->appendChild($dnoderights) : null;
335
        null !== $dnodelifecycle ? $dnode->appendChild($dnodelifecycle) : null;
336
337
        return $dnode;
338
    }
339
340
    /**
341
     * Create Metadata For Resource (How To).
342
     *
343
     * @param object $xmlnode
344
     *
345
     * @return DOMNode
346
     */
347
    protected function createMetadataResource(CcIMetadataResource $met, DOMDocument &$doc, $xmlnode = null)
348
    {
349
        $dnode = $doc->createElementNS($this->ccnamespaces['lom'], 'lom');
350
351
        !empty($xmlnode) ? $xmlnode->appendChild($dnode) : null;
352
        !empty($met->arrayeducational) ? $this->createMetadataEducational($met, $doc, $dnode) : null;
0 ignored issues
show
Bug introduced by
Accessing arrayeducational on the interface Chamilo\CourseBundle\Com...ces\CcIMetadataResource suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
353
354
        return $dnode;
355
    }
356
357
    /**
358
     * Create Metadata For File (How To).
359
     *
360
     * @param object $xmlnode
361
     *
362
     * @return DOMNode
363
     */
364
    protected function createMetadataFile(CcIMetadataFile $met, DOMDocument &$doc, $xmlnode = null)
365
    {
366
        $dnode = $doc->createElementNS($this->ccnamespaces['lom'], 'lom');
367
368
        !empty($xmlnode) ? $xmlnode->appendChild($dnode) : null;
369
        !empty($met->arrayeducational) ? $this->createMetadataEducational($met, $doc, $dnode) : null;
0 ignored issues
show
Bug introduced by
Accessing arrayeducational on the interface Chamilo\CourseBundle\Com...erfaces\CcIMetadataFile suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
370
371
        return $dnode;
372
    }
373
374
    /**
375
     * Create General Metadata (How To).
376
     *
377
     * @param object $met
378
     * @param object $xmlnode
379
     *
380
     * @return DOMNode
381
     */
382
    protected function createMetadataGeneral($met, DOMDocument &$doc, $xmlnode)
383
    {
384
        $nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'general');
385
386
        foreach ($met->arraygeneral as $name => $value) {
387
            !\is_array($value) ? $value = [$value] : null;
388
            foreach ($value as $v) {
389
                if ('language' != $name && 'catalog' != $name && 'entry' != $name) {
390
                    $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name);
391
                    $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'string', $v[1]);
392
                    $ndatt = $doc->createAttribute('language');
393
                    $ndatt->nodeValue = $v[0];
394
                    $nd3->appendChild($ndatt);
395
                    $nd2->appendChild($nd3);
396
                    $nd->appendChild($nd2);
397
                } else {
398
                    if ('language' == $name) {
399
                        $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name, $v[0]);
400
                        $nd->appendChild($nd2);
401
                    }
402
                }
403
            }
404
        }
405
        if (!empty($met->arraygeneral['catalog']) || !empty($met->arraygeneral['entry'])) {
406
            $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'identifier');
407
            $nd->appendChild($nd2);
408
            if (!empty($met->arraygeneral['catalog'])) {
409
                $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'catalog', $met->arraygeneral['catalog'][0][0]);
410
                $nd2->appendChild($nd3);
411
            }
412
            if (!empty($met->arraygeneral['entry'])) {
413
                $nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'entry', $met->arraygeneral['entry'][0][0]);
414
                $nd2->appendChild($nd4);
415
            }
416
        }
417
418
        return $nd;
419
    }
420
421
    /**
422
     * Create Technical Metadata (How To).
423
     *
424
     * @param object $met
425
     * @param object $xmlnode
426
     *
427
     * @return DOMNode
428
     */
429
    protected function createMetadataTechnical($met, DOMDocument &$doc, $xmlnode)
430
    {
431
        $nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'technical');
432
        $xmlnode->appendChild($nd);
433
434
        foreach ($met->arraytech as $name => $value) {
435
            !\is_array($value) ? $value = [$value] : null;
436
            foreach ($value as $v) {
437
                $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name, $v[0]);
438
                $nd->appendChild($nd2);
439
            }
440
        }
441
442
        return $nd;
443
    }
444
445
    /**
446
     * Create Rights Metadata (How To).
447
     *
448
     * @param object $met
449
     * @param object $xmlnode
450
     *
451
     * @return DOMNode
452
     */
453
    protected function createMetadataRights($met, DOMDocument &$doc, $xmlnode)
454
    {
455
        $nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'rights');
456
457
        foreach ($met->arrayrights as $name => $value) {
458
            !\is_array($value) ? $value = [$value] : null;
459
            foreach ($value as $v) {
460
                if ('description' == $name) {
461
                    $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name);
462
                    $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'string', $v[1]);
463
                    $ndatt = $doc->createAttribute('language');
464
                    $ndatt->nodeValue = $v[0];
465
                    $nd3->appendChild($ndatt);
466
                    $nd2->appendChild($nd3);
467
                    $nd->appendChild($nd2);
468
                } elseif ('copyrightAndOtherRestrictions' == $name || 'cost' == $name) {
469
                    $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name);
470
                    $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'value', $v[0]);
471
                    $nd2->appendChild($nd3);
472
                    $nd->appendChild($nd2);
473
                }
474
            }
475
        }
476
477
        return $nd;
478
    }
479
480
    /**
481
     * Create Lifecycle Metadata (How To).
482
     *
483
     * @param object $met
484
     * @param object $doc
485
     * @param object $xmlnode
486
     *
487
     * @return DOMNode
488
     */
489
    protected function createMetadataLifecycle($met, DOMDocument &$doc, $xmlnode)
490
    {
491
        $nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'lifeCycle');
492
        $nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'contribute');
493
494
        $nd->appendChild($nd2);
495
        $xmlnode->appendChild($nd);
496
497
        foreach ($met->arraylifecycle as $name => $value) {
498
            !\is_array($value) ? $value = [$value] : null;
499
            foreach ($value as $v) {
500
                if ('role' == $name) {
501
                    $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name);
502
                    $nd2->appendChild($nd3);
503
                    $nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'value', $v[0]);
504
                    $nd3->appendChild($nd4);
505
                } else {
506
                    if ('date' == $name) {
507
                        $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name);
508
                        $nd2->appendChild($nd3);
509
                        $nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'dateTime', $v[0]);
510
                        $nd3->appendChild($nd4);
511
                    } else {
512
                        $nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name, $v[0]);
513
                        $nd2->appendChild($nd3);
514
                    }
515
                }
516
            }
517
        }
518
519
        return $nd;
520
    }
521
}
522