|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of littleredbutton/bigbluebutton-api-php. |
| 7 | + * |
| 8 | + * littleredbutton/bigbluebutton-api-php is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Lesser General Public License as published by |
| 10 | + * the Free Software Foundation, either version 3 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * littleredbutton/bigbluebutton-api-php is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Lesser General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Lesser General Public License |
| 19 | + * along with littleredbutton/bigbluebutton-api-php. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + */ |
| 21 | +namespace BigBlueButton\Parameters; |
| 22 | + |
| 23 | +/** |
| 24 | + * @method string getMeetingID() |
| 25 | + * @method $this setMeetingID(string $id) |
| 26 | + */ |
| 27 | +final class InsertDocumentParameters extends MetaParameters |
| 28 | +{ |
| 29 | + /** |
| 30 | + * @var string |
| 31 | + */ |
| 32 | + protected $meetingID; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var array |
| 36 | + */ |
| 37 | + private $presentations = []; |
| 38 | + |
| 39 | + public function __construct(string $meetingID) |
| 40 | + { |
| 41 | + $this->meetingID = $meetingID; |
| 42 | + } |
| 43 | + |
| 44 | + public function addPresentation(string $url, string $filename, ?bool $downloadable = null, ?bool $removable = null): self |
| 45 | + { |
| 46 | + $this->presentations[$url] = [ |
| 47 | + 'filename' => $filename, |
| 48 | + 'downloadable' => $downloadable, |
| 49 | + 'removable' => $removable, |
| 50 | + ]; |
| 51 | + |
| 52 | + return $this; |
| 53 | + } |
| 54 | + |
| 55 | + public function removePresentation(string $url): void |
| 56 | + { |
| 57 | + unset($this->presentations[$url]); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @return mixed |
| 62 | + */ |
| 63 | + public function getPresentationsAsXML() |
| 64 | + { |
| 65 | + $result = ''; |
| 66 | + |
| 67 | + if (!empty($this->presentations)) { |
| 68 | + $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><modules/>'); |
| 69 | + $module = $xml->addChild('module'); |
| 70 | + $module->addAttribute('name', 'presentation'); |
| 71 | + |
| 72 | + foreach ($this->presentations as $url => $content) { |
| 73 | + $presentation = $module->addChild('document'); |
| 74 | + $presentation->addAttribute('url', $url); |
| 75 | + $presentation->addAttribute('filename', $content['filename']); |
| 76 | + |
| 77 | + if (is_bool($content['downloadable'])) { |
| 78 | + $presentation->addAttribute('downloadable', $content['downloadable'] ? 'true' : 'false'); |
| 79 | + } |
| 80 | + |
| 81 | + if (is_bool($content['removable'])) { |
| 82 | + $presentation->addAttribute('removable', $content['removable'] ? 'true' : 'false'); |
| 83 | + } |
| 84 | + } |
| 85 | + $result = $xml->asXML(); |
| 86 | + } |
| 87 | + |
| 88 | + return $result; |
| 89 | + } |
| 90 | +} |
0 commit comments