Skip to content

Commit 443b3c6

Browse files
Refactor presentation files (#234)
* Add support for downloadable and removable attribute * Add support for embedded slides * Add current parameter * Refactor: Use Object to manage presentation attributes * Remove wrong doctype * Code cleanup * Adjust deprecation message * Bugfix * Make classes final Co-authored-by: Felix Jacobi <felix@jacobi-hamburg.net> --------- Co-authored-by: Felix Jacobi <felix@jacobi-hamburg.net>
1 parent 393f197 commit 443b3c6

5 files changed

Lines changed: 267 additions & 39 deletions

File tree

src/Core/InlinePresentation.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
7+
*
8+
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
9+
*
10+
* This program is free software; you can redistribute it and/or modify it under the
11+
* terms of the GNU Lesser General Public License as published by the Free Software
12+
* Foundation; either version 3.0 of the License, or (at your option) any later
13+
* version.
14+
*
15+
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
16+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
17+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License along
20+
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
namespace BigBlueButton\Core;
24+
25+
use BigBlueButton\Util\SimpleXMLElementExtended;
26+
27+
final class InlinePresentation extends Presentation
28+
{
29+
public function __construct(private readonly string $content, string $filename)
30+
{
31+
$this->filename = $filename;
32+
}
33+
34+
public function getArrayKey(): string
35+
{
36+
return $this->filename;
37+
}
38+
39+
public function addDocumentToXML(SimpleXMLElementExtended $module): ?SimpleXMLElementExtended
40+
{
41+
$document = parent::addDocumentToXML($module);
42+
43+
/* @phpstan-ignore-next-line */
44+
$document[0] = base64_encode($this->content);
45+
46+
if (isset($this->filename)) {
47+
$document->addAttribute('name', $this->filename);
48+
}
49+
50+
return $document;
51+
}
52+
}

src/Core/Presentation.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
7+
*
8+
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
9+
*
10+
* This program is free software; you can redistribute it and/or modify it under the
11+
* terms of the GNU Lesser General Public License as published by the Free Software
12+
* Foundation; either version 3.0 of the License, or (at your option) any later
13+
* version.
14+
*
15+
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
16+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
17+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License along
20+
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
namespace BigBlueButton\Core;
24+
25+
use BigBlueButton\Util\SimpleXMLElementExtended;
26+
27+
abstract class Presentation
28+
{
29+
protected ?string $filename = null;
30+
31+
protected ?bool $current = null;
32+
33+
protected ?bool $downloadable = null;
34+
35+
protected ?bool $removable = null;
36+
37+
public function addDocumentToXML(SimpleXMLElementExtended $module): ?SimpleXMLElementExtended
38+
{
39+
$document = $module->addChild('document');
40+
41+
if (\is_bool($this->downloadable)) {
42+
$document->addAttribute('downloadable', $this->downloadable ? 'true' : 'false');
43+
}
44+
45+
if (\is_bool($this->removable)) {
46+
$document->addAttribute('removable', $this->removable ? 'true' : 'false');
47+
}
48+
49+
if (\is_bool($this->current)) {
50+
$document->addAttribute('current', $this->current ? 'true' : 'false');
51+
}
52+
53+
return $document;
54+
}
55+
56+
abstract public function getArrayKey(): string;
57+
58+
public function getFilename(): ?string
59+
{
60+
return $this->filename;
61+
}
62+
63+
public function setFilename(string $filename): self
64+
{
65+
$this->filename = $filename;
66+
67+
return $this;
68+
}
69+
70+
public function getCurrent(): ?bool
71+
{
72+
return $this->current;
73+
}
74+
75+
public function setCurrent(bool $current): self
76+
{
77+
$this->current = $current;
78+
79+
return $this;
80+
}
81+
82+
public function getDownloadable(): ?bool
83+
{
84+
return $this->downloadable;
85+
}
86+
87+
public function setDownloadable(bool $downloadable): self
88+
{
89+
$this->downloadable = $downloadable;
90+
91+
return $this;
92+
}
93+
94+
public function getRemovable(): ?bool
95+
{
96+
return $this->removable;
97+
}
98+
99+
public function setRemovable(bool $removable): self
100+
{
101+
$this->removable = $removable;
102+
103+
return $this;
104+
}
105+
}

src/Core/UrlPresentation.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
7+
*
8+
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
9+
*
10+
* This program is free software; you can redistribute it and/or modify it under the
11+
* terms of the GNU Lesser General Public License as published by the Free Software
12+
* Foundation; either version 3.0 of the License, or (at your option) any later
13+
* version.
14+
*
15+
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
16+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
17+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License along
20+
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
namespace BigBlueButton\Core;
24+
25+
use BigBlueButton\Util\SimpleXMLElementExtended;
26+
27+
final class UrlPresentation extends Presentation
28+
{
29+
public function __construct(private readonly string $url)
30+
{
31+
}
32+
33+
public function getArrayKey(): string
34+
{
35+
return $this->url;
36+
}
37+
38+
public function addDocumentToXML(SimpleXMLElementExtended $module): ?SimpleXMLElementExtended
39+
{
40+
$document = parent::addDocumentToXML($module);
41+
$document->addAttribute('url', $this->url);
42+
43+
if (isset($this->filename)) {
44+
$document->addAttribute('filename', $this->filename);
45+
}
46+
47+
return $document;
48+
}
49+
}

src/Parameters/CreateMeetingParameters.php

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
namespace BigBlueButton\Parameters;
2424

25+
use BigBlueButton\Core\InlinePresentation;
26+
use BigBlueButton\Core\Presentation;
27+
use BigBlueButton\Core\UrlPresentation;
2528
use BigBlueButton\Enum\Feature;
2629
use BigBlueButton\Enum\GuestPolicy;
2730
use BigBlueButton\Enum\MeetingLayout;
@@ -259,9 +262,7 @@ final class CreateMeetingParameters extends MetaParameters
259262
protected ?string $sharedNotesEditor = null;
260263
protected ?string $sharedNotesInitialContentJsonUrl = null;
261264

262-
/**
263-
* @var array<string,string>
264-
*/
265+
/** @var array<string,Presentation> */
265266
private array $presentations = [];
266267

267268
public function __construct(protected string $meetingID, protected string $name)
@@ -361,12 +362,30 @@ public function setGuestPolicyAlwaysAccept(): self
361362
return $this;
362363
}
363364

364-
public function addPresentation(string $nameOrUrl, ?string $content = null, ?string $filename = null): self
365+
/**
366+
* @return $this
367+
*/
368+
public function addPresentation(string|Presentation $nameOrUrlOrPresentation, ?string $content = null, ?string $filename = null): self
365369
{
366-
if (!$filename) {
367-
$this->presentations[$nameOrUrl] = !$content ?: base64_encode($content);
370+
if ($nameOrUrlOrPresentation instanceof Presentation) {
371+
$this->presentations[$nameOrUrlOrPresentation->getArrayKey()] = $nameOrUrlOrPresentation;
372+
373+
return $this;
374+
}
375+
376+
@trigger_error(\sprintf('Calling addPresentation in "%s" with any parameters other than a single Presentation object is deprecated and will throw an exception in 7.0.', self::class), \E_USER_DEPRECATED);
377+
378+
if ($content) {
379+
$presentation = new InlinePresentation($content, $nameOrUrlOrPresentation);
380+
$this->presentations[$presentation->getArrayKey()] = $presentation;
368381
} else {
369-
$this->presentations[$nameOrUrl] = $filename;
382+
$presentation = new UrlPresentation($nameOrUrlOrPresentation);
383+
384+
if ($filename != null) {
385+
$presentation->setFilename($filename);
386+
}
387+
388+
$this->presentations[$presentation->getArrayKey()] = $presentation;
370389
}
371390

372391
return $this;
@@ -392,7 +411,7 @@ public function addBreakoutRoomsGroup(string $id, ?string $name, array $roster):
392411
return $this;
393412
}
394413

395-
/** @return array<string,string> */
414+
/** @return array<string,Presentation> */
396415
public function getPresentations(): array
397416
{
398417
return $this->presentations;
@@ -433,18 +452,9 @@ public function addPresentationsModule(SimpleXMLElementExtended $xml): void
433452
$module = $xml->addChild('module');
434453
$module->addAttribute('name', 'presentation');
435454

436-
foreach ($this->presentations as $nameOrUrl => $content) {
437-
if (str_starts_with($nameOrUrl, 'http')) {
438-
$presentation = $module->addChild('document');
439-
$presentation->addAttribute('url', $nameOrUrl);
440-
if (\is_string($content)) {
441-
$presentation->addAttribute('filename', $content);
442-
}
443-
} else {
444-
$document = $module->addChild('document');
445-
$document->addAttribute('name', $nameOrUrl);
446-
/* @phpstan-ignore-next-line */
447-
$document[0] = $content;
455+
foreach ($this->presentations as $data) {
456+
if ($data instanceof Presentation) {
457+
$data->addDocumentToXML($module);
448458
}
449459
}
450460
}

src/Parameters/InsertDocumentParameters.php

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,46 @@
2121

2222
namespace BigBlueButton\Parameters;
2323

24+
use BigBlueButton\Core\Presentation;
25+
use BigBlueButton\Core\UrlPresentation;
26+
use BigBlueButton\Util\SimpleXMLElementExtended;
27+
2428
/**
2529
* @method string getMeetingID()
2630
* @method $this setMeetingID(string $id)
2731
*/
2832
final class InsertDocumentParameters extends MetaParameters
2933
{
30-
/** @var array<string,array{filename: string, downloadable: bool|null, removable: bool|null}> */
34+
/** @var array<string,Presentation> */
3135
private array $presentations = [];
3236

3337
public function __construct(protected string $meetingID)
3438
{
3539
}
3640

37-
public function addPresentation(string $url, string $filename, ?bool $downloadable = null, ?bool $removable = null): self
41+
public function addPresentation(string|Presentation $urlOrPresentation, ?string $filename = null, ?bool $downloadable = null, ?bool $removable = null): self
3842
{
39-
$this->presentations[$url] = [
40-
'filename' => $filename,
41-
'downloadable' => $downloadable,
42-
'removable' => $removable,
43-
];
43+
if ($urlOrPresentation instanceof Presentation) {
44+
$this->presentations[$urlOrPresentation->getArrayKey()] = $urlOrPresentation;
45+
46+
return $this;
47+
}
48+
49+
@trigger_error(\sprintf('Calling addPresentation in "%s" with any parameters other than a single Presentation object is deprecated and will throw an exception in 7.0.', self::class), \E_USER_DEPRECATED);
50+
51+
$presentation = new UrlPresentation($urlOrPresentation);
52+
53+
if ($filename !== null) {
54+
$presentation->setFilename($filename);
55+
}
56+
if ($downloadable !== null) {
57+
$presentation->setDownloadable($downloadable);
58+
}
59+
if ($removable !== null) {
60+
$presentation->setRemovable($removable);
61+
}
62+
63+
$this->presentations[$presentation->getArrayKey()] = $presentation;
4464

4565
return $this;
4666
}
@@ -57,21 +77,13 @@ public function getPresentationsAsXML(): string|false
5777
$result = '';
5878

5979
if (!empty($this->presentations)) {
60-
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><modules/>');
80+
$xml = new SimpleXMLElementExtended('<?xml version="1.0" encoding="UTF-8"?><modules/>');
6181
$module = $xml->addChild('module');
6282
$module->addAttribute('name', 'presentation');
6383

64-
foreach ($this->presentations as $url => $content) {
65-
$presentation = $module->addChild('document');
66-
$presentation->addAttribute('url', $url);
67-
$presentation->addAttribute('filename', $content['filename']);
68-
69-
if (\is_bool($content['downloadable'])) {
70-
$presentation->addAttribute('downloadable', $content['downloadable'] ? 'true' : 'false');
71-
}
72-
73-
if (\is_bool($content['removable'])) {
74-
$presentation->addAttribute('removable', $content['removable'] ? 'true' : 'false');
84+
foreach ($this->presentations as $content) {
85+
if ($content instanceof Presentation) {
86+
$content->addDocumentToXML($module);
7587
}
7688
}
7789
$result = $xml->asXML();

0 commit comments

Comments
 (0)