-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathDocumentableTrait.php
More file actions
91 lines (77 loc) · 3.1 KB
/
Copy pathDocumentableTrait.php
File metadata and controls
91 lines (77 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/*
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2024 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <https://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Parameters;
use BigBlueButton\Parameters\Config\DocumentOptionsStore;
trait DocumentableTrait
{
/**
* @var array<string, mixed>
*/
protected array $presentations = [];
/**
* @return array<string, mixed>
*/
public function getPresentations(): array
{
return $this->presentations;
}
public function addPresentation(string $nameOrUrl, $content = null, ?string $filename = null, ?DocumentOptionsStore $attributes = null): self
{
$this->presentations[$nameOrUrl] = [
'content' => null !== $content ? base64_encode($content) : null,
'filename' => $filename,
'attributes' => $attributes
];
return $this;
}
public function getPresentationsAsXML(): string
{
$result = '';
if (!empty($this->presentations)) {
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><modules/>');
$module = $xml->addChild('module');
$module->addAttribute('name', 'presentation');
foreach ($this->presentations as $nameOrUrl => $data) {
$presentation = $module->addChild('document');
if (0 === mb_strpos($nameOrUrl, 'http')) {
$presentation->addAttribute('url', $nameOrUrl);
} else {
$presentation->addAttribute('name', $nameOrUrl);
}
if (!empty($data['filename'])) {
$presentation->addAttribute('filename', $data['filename']);
}
if (!empty($data['content'])) {
$presentation[0] = $data['content'];
}
// Add attributes using DocumentAttributes class
if ($data['attributes'] instanceof DocumentOptionsStore) {
foreach ($data['attributes']->getAttributes() as $attrName => $attrValue) {
$presentation->addAttribute($attrName, $attrValue);
}
}
}
$result = $xml->asXML();
}
if (!is_string($result)) {
throw new \RuntimeException('String expected, but ' . gettype($result) . ' received.');
}
return $result;
}
}