Skip to content

Commit 8de3077

Browse files
committed
Handle document options for insertDocument API.
1 parent ac1c77a commit 8de3077

3 files changed

Lines changed: 98 additions & 18 deletions

File tree

src/Enum/DocumentOption.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5+
*
6+
* Copyright (c) 2016-2024 BigBlueButton Inc. and by respective authors (see below).
7+
*
8+
* This program is free software; you can redistribute it and/or modify it under the
9+
* terms of the GNU Lesser General Public License as published by the Free Software
10+
* Foundation; either version 3.0 of the License, or (at your option) any later
11+
* version.
12+
*
13+
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License along
18+
* with BigBlueButton; if not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
namespace BigBlueButton\Enum;
22+
23+
use MabeEnum\Enum;
24+
25+
class DocumentOption extends Enum
26+
{
27+
public const CURRENT = 'current';
28+
public const DOWNLOADABLE = 'downloadable';
29+
public const REMOVABLE = 'removable';
30+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5+
*
6+
* Copyright (c) 2016-2024 BigBlueButton Inc. and by respective authors (see below).
7+
*
8+
* This program is free software; you can redistribute it and/or modify it under the
9+
* terms of the GNU Lesser General Public License as published by the Free Software
10+
* Foundation; either version 3.0 of the License, or (at your option) any later
11+
* version.
12+
*
13+
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License along
18+
* with BigBlueButton; if not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
namespace BigBlueButton\Parameters\Config;
22+
23+
class DocumentOptionsStore
24+
{
25+
private $attributes = [];
26+
27+
public function __construct(array $attributes = [])
28+
{
29+
$this->attributes = $attributes;
30+
}
31+
32+
public function addAttribute($name, $value)
33+
{
34+
if (is_bool($value)) {
35+
$value = $value ? 'true' : 'false';
36+
}
37+
$this->attributes[$name] = $value;
38+
}
39+
40+
public function getAttributes()
41+
{
42+
return $this->attributes;
43+
}
44+
}

src/Parameters/DocumentableTrait.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
namespace BigBlueButton\Parameters;
2222

23+
use BigBlueButton\Parameters\Config\DocumentOptionsStore;
24+
2325
trait DocumentableTrait
2426
{
2527
/**
@@ -35,40 +37,44 @@ public function getPresentations(): array
3537
return $this->presentations;
3638
}
3739

38-
/**
39-
* @param mixed $content
40-
*/
41-
public function addPresentation(string $nameOrUrl, $content = null, ?string $filename = null): self
40+
public function addPresentation(string $nameOrUrl, $content = null, ?string $filename = null, DocumentOptionsStore $attributes = null): self
4241
{
43-
if (!$filename) {
44-
$this->presentations[$nameOrUrl] = !$content ?: base64_encode($content);
45-
} else {
46-
$this->presentations[$nameOrUrl] = $filename;
47-
}
42+
$this->presentations[$nameOrUrl] = [
43+
'content' => !$content ?: base64_encode($content),
44+
'filename' => $filename,
45+
'attributes' => $attributes
46+
];
4847

4948
return $this;
5049
}
5150

5251
public function getPresentationsAsXML(): string
5352
{
5453
$result = '';
55-
5654
if (!empty($this->presentations)) {
5755
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><modules/>');
5856
$module = $xml->addChild('module');
5957
$module->addAttribute('name', 'presentation');
6058

61-
foreach ($this->presentations as $nameOrUrl => $content) {
59+
foreach ($this->presentations as $nameOrUrl => $data) {
60+
$presentation = $module->addChild('document');
6261
if (0 === mb_strpos($nameOrUrl, 'http')) {
63-
$presentation = $module->addChild('document');
6462
$presentation->addAttribute('url', $nameOrUrl);
65-
if (is_string($content)) {
66-
$presentation->addAttribute('filename', $content);
67-
}
6863
} else {
69-
$document = $module->addChild('document');
70-
$document->addAttribute('name', $nameOrUrl);
71-
$document[0] = $content;
64+
$presentation->addAttribute('name', $nameOrUrl);
65+
}
66+
67+
if (!empty($data['filename'])) {
68+
$presentation->addAttribute('filename', $data['filename']);
69+
}
70+
71+
if (!empty($data['content'])) {
72+
$presentation[0] = $data['content'];
73+
}
74+
75+
// Add attributes using DocumentAttributes class
76+
foreach ($data['attributes']->getAttributes() as $attrName => $attrValue) {
77+
$presentation->addAttribute($attrName, $attrValue);
7278
}
7379
}
7480
$result = $xml->asXML();

0 commit comments

Comments
 (0)