From 0a00430a2bafca8f57076829301dbc2df5e6eff0 Mon Sep 17 00:00:00 2001 From: Mohamed Aziz Haddad Date: Wed, 15 Jun 2022 20:34:32 +0100 Subject: [PATCH 1/2] formats d'enregistrements multiples --- src/Core/Image.php | 111 ++++++++++++++++++ src/Core/Record.php | 39 ++++++ tests/Responses/GetRecordingsResponseTest.php | 32 +++++ tests/fixtures/get_recordings.xml | 19 ++- 4 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 src/Core/Image.php diff --git a/src/Core/Image.php b/src/Core/Image.php new file mode 100644 index 00000000..69f1f347 --- /dev/null +++ b/src/Core/Image.php @@ -0,0 +1,111 @@ +. + */ + +namespace BigBlueButton\Core; + +/** + * Class Record + * @package BigBlueButton\Core + */ +class Image +{ + /** + * @var string + */ + private $alt; + + /** + * @var int + */ + private $height; + + /** + * @var int + */ + private $width; + + /** + * @var string + */ + private $link; + + /** + * @return string + */ + public function getAlt(): string + { + return $this->alt; + } + + /** + * @param string $alt + */ + public function setAlt(string $alt): void + { + $this->alt = $alt; + } + + /** + * @return int + */ + public function getHeight(): int + { + return $this->height; + } + + /** + * @param int $height + */ + public function setHeight(int $height): void + { + $this->height = $height; + } + + /** + * @return int + */ + public function getWidth(): int + { + return $this->width; + } + + /** + * @param int $width + */ + public function setWidth(int $width): void + { + $this->width = $width; + } + + /** + * @return string + */ + public function getLink(): string + { + return $this->link; + } + + /** + * @param string $link + */ + public function setLink(string $link): void + { + $this->link = $link; + } +} diff --git a/src/Core/Record.php b/src/Core/Record.php index 41d61fe4..2b2685d5 100644 --- a/src/Core/Record.php +++ b/src/Core/Record.php @@ -16,6 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License along * with BigBlueButton; if not, see . */ + namespace BigBlueButton\Core; /** @@ -35,6 +36,7 @@ class Record private $playbackUrl; private $playbackLength; private $metas; + private $playbacks; /** * Record constructor. @@ -56,6 +58,43 @@ public function __construct($xml) foreach ($xml->metadata->children() as $meta) { $this->metas[$meta->getName()] = $meta->__toString(); } + + foreach ($xml->playback->children() as $format) { + $aFormat = []; + foreach ($format->children() as $formAttribut) { + // if ($formAttribut != "preview"){ } + $aFormat[$formAttribut->getName()] = $formAttribut->__toString(); + } + if (isset($format->preview)) { + $images = []; + foreach ($format->preview->images->children() as $image) { + $imageObj = new Image(); + $imageObj->setAlt( $image['alt']->__toString()); + $imageObj->setHeight((int) $image['height']->__toString()); + $imageObj->setWidth((int) $image['width']->__toString()); + $imageObj->setLink($image->__toString()); + $images[] = $imageObj; + } + $aFormat['preview'] = $images; + } + $this->playbacks[] = $aFormat; + } + } + + /** + * @return array + */ + public function getPlaybacks(): array + { + return $this->playbacks; + } + + /** + * @param array $playbacks + */ + public function setPlaybacks(array $playbacks): void + { + $this->playbacks = $playbacks; } /** diff --git a/tests/Responses/GetRecordingsResponseTest.php b/tests/Responses/GetRecordingsResponseTest.php index 71967705..fa068130 100644 --- a/tests/Responses/GetRecordingsResponseTest.php +++ b/tests/Responses/GetRecordingsResponseTest.php @@ -65,6 +65,38 @@ public function testRecordMetadataContent() $this->assertEquals('moodle-mod_bigbluebuttonbn (2015080611)', $metas['bbb-origin-tag']); } + public function testRecordingsPlayback() + { + $this->assertEquals('SUCCESS', $this->records->getReturnCode()); + + $this->assertCount(6, $this->records->getRecords()); + $aRecord = $this->records->getRecords()[0]; + $formatN1 = $aRecord->getPlaybacks()[0]; // without images preview + $this->assertEquals('podcast', $formatN1['type']); + $this->assertEquals('https://testurl/podcast/1.ogg', $formatN1['url']); + $this->assertEquals('111', $formatN1['processingTime']); + $this->assertEquals('222', $formatN1['length']); + $this->assertEquals('333', $formatN1['size']); + + $formatN2 = $aRecord->getPlaybacks()[1]; // having images preview + $this->assertEquals('presentation', $formatN2['type']); + $this->assertEquals('https://testurl/podcast/2.ogg', $formatN2['url']); + $this->assertEquals('444', $formatN2['processingTime']); + $this->assertEquals('555', $formatN2['length']); + $this->assertEquals('666', $formatN2['size']); + + $images = $formatN2['preview']; + $this->assertEquals('testurl1', $images[0]->getAlt()); + $this->assertEquals('136', $images[0]->getHeight()); + $this->assertEquals('176', $images[0]->getWidth()); + $this->assertEquals('https://testurl1.png', $images[0]->getLink()); + + $this->assertEquals('testurl2', $images[1]->getAlt()); + $this->assertEquals('136', $images[1]->getHeight()); + $this->assertEquals('176', $images[1]->getWidth()); + $this->assertEquals('https://testurl2.png', $images[1]->getLink()); + } + public function testGetRecordingResponseTypes() { $this->assertEachGetterValueIsString($this->records, ['getReturnCode']); diff --git a/tests/fixtures/get_recordings.xml b/tests/fixtures/get_recordings.xml index 9a5c51a4..bd00edec 100644 --- a/tests/fixtures/get_recordings.xml +++ b/tests/fixtures/get_recordings.xml @@ -21,10 +21,25 @@ + + podcast + https://testurl/podcast/1.ogg + 111 + 222 + 333 + presentation - http://test-install.blindsidenetworks.com/playback/presentation/0.9.0/playback.html?meetingId=f71d810b6e90a4a34ae02b8c7143e8733178578e-1462807897120 - 44 + https://testurl/podcast/2.ogg + 444 + 555 + 666 + + + testurl1https://testurl1.png + testurl2https://testurl2.png + + From 3711b94b571b0d4a6771a5737cfc2aee4feb19d6 Mon Sep 17 00:00:00 2001 From: tothetop430 Date: Wed, 15 Jun 2022 23:03:40 +0100 Subject: [PATCH 2/2] Improve multiple recording formats implementation. --- src/BigBlueButton.php | 14 +-- src/Core/Format.php | 105 ++++++++++++++++++ src/Core/Image.php | 59 ++-------- src/Core/Record.php | 73 ++++++------ tests/Responses/GetRecordingsResponseTest.php | 50 ++++----- tests/fixtures/get_recordings.xml | 26 +++-- 6 files changed, 197 insertions(+), 130 deletions(-) create mode 100644 src/Core/Format.php diff --git a/src/BigBlueButton.php b/src/BigBlueButton.php index 5a1f7f89..1c9d18a9 100644 --- a/src/BigBlueButton.php +++ b/src/BigBlueButton.php @@ -397,7 +397,7 @@ public function setJSessionId($jSessionId) $this->jSessionId = $jSessionId; } - /** + /** * @param array $curlopts */ public function setCurlOpts($curlopts) @@ -429,7 +429,7 @@ private function processXmlResponse($url, $payload = '', $contentType = 'applica $cookiefile = tmpfile(); $cookiefilepath = stream_get_meta_data($cookiefile)['uri']; - foreach ($this->curlopts as $opt => $value){ + foreach ($this->curlopts as $opt => $value) { curl_setopt($ch, $opt, $value); } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); @@ -487,12 +487,12 @@ public function setTimeOut($TimeOutInSeconds) /** * Public accessor for buildUrl - * @param string $method - * @param string $params - * @param bool $append - * @return string + * @param string $method + * @param string $params + * @param bool $append + * @return string */ - public function buildUrl($method = '', $params = '', $append = TRUE) + public function buildUrl($method = '', $params = '', $append = true) { return $this->urlBuilder->buildUrl($method, $params, $append); } diff --git a/src/Core/Format.php b/src/Core/Format.php new file mode 100644 index 00000000..7b18ec8c --- /dev/null +++ b/src/Core/Format.php @@ -0,0 +1,105 @@ +. + */ + +namespace BigBlueButton\Core; + +class Format +{ + /** + * @var \SimpleXMLElement + */ + protected $rawXml; + + private $type; + private $url; + private $processingTime; + private $length; + private $size; + private $images; + + /** + * Record constructor. + * @param $xml \SimpleXMLElement + */ + public function __construct($xml) + { + $this->rawXml = $xml; + $this->type = $xml->type->__toString(); + $this->url = $xml->url->__toString(); + $this->processingTime = (int) $xml->processingTime->__toString(); + $this->length = (int) $xml->length->__toString(); + $this->size = (int) $xml->size->__toString(); + } + + /** + * @return Image[] + */ + public function getImages() + { + if ($this->images === null) { + $this->images = []; + foreach ($this->rawXml->preview->images->image as $imageXml) { + $this->images[] = new Image($imageXml); + } + } + + return $this->images; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @return int + */ + public function getProcessingTime(): int + { + return $this->processingTime; + } + + /** + * @return int + */ + public function getLength(): int + { + return $this->length; + } + + /** + * @return int + */ + public function getSize(): int + { + return $this->size; + } +} diff --git a/src/Core/Image.php b/src/Core/Image.php index 69f1f347..f7344bb9 100644 --- a/src/Core/Image.php +++ b/src/Core/Image.php @@ -25,25 +25,22 @@ */ class Image { - /** - * @var string - */ private $alt; - - /** - * @var int - */ private $height; - - /** - * @var int - */ private $width; + private $url; /** - * @var string + * Record constructor. + * @param $xml \SimpleXMLElement */ - private $link; + public function __construct($xml) + { + $this->alt = $xml['alt']->__toString(); + $this->height = (int) $xml['height']; + $this->width = (int) $xml['width']; + $this->url = $xml->__toString(); + } /** * @return string @@ -53,14 +50,6 @@ public function getAlt(): string return $this->alt; } - /** - * @param string $alt - */ - public function setAlt(string $alt): void - { - $this->alt = $alt; - } - /** * @return int */ @@ -69,14 +58,6 @@ public function getHeight(): int return $this->height; } - /** - * @param int $height - */ - public function setHeight(int $height): void - { - $this->height = $height; - } - /** * @return int */ @@ -85,27 +66,11 @@ public function getWidth(): int return $this->width; } - /** - * @param int $width - */ - public function setWidth(int $width): void - { - $this->width = $width; - } - /** * @return string */ - public function getLink(): string - { - return $this->link; - } - - /** - * @param string $link - */ - public function setLink(string $link): void + public function getUrl(): string { - $this->link = $link; + return $this->url; } } diff --git a/src/Core/Record.php b/src/Core/Record.php index 2b2685d5..d1c84787 100644 --- a/src/Core/Record.php +++ b/src/Core/Record.php @@ -25,6 +25,12 @@ */ class Record { + + /** + * @var \SimpleXMLElement + */ + protected $rawXml; + private $recordId; private $meetingId; private $name; @@ -32,11 +38,20 @@ class Record private $state; private $startTime; private $endTime; + /** + * @deprecated deprecated since 2.1.2 + */ private $playbackType; + /** + * @deprecated deprecated since 2.1.2 + */ private $playbackUrl; + /** + * @deprecated deprecated since 2.1.2 + */ private $playbackLength; private $metas; - private $playbacks; + private $formats; /** * Record constructor. @@ -44,6 +59,7 @@ class Record */ public function __construct($xml) { + $this->rawXml = $xml; $this->recordId = $xml->recordID->__toString(); $this->meetingId = $xml->meetingID->__toString(); $this->name = $xml->name->__toString(); @@ -58,43 +74,6 @@ public function __construct($xml) foreach ($xml->metadata->children() as $meta) { $this->metas[$meta->getName()] = $meta->__toString(); } - - foreach ($xml->playback->children() as $format) { - $aFormat = []; - foreach ($format->children() as $formAttribut) { - // if ($formAttribut != "preview"){ } - $aFormat[$formAttribut->getName()] = $formAttribut->__toString(); - } - if (isset($format->preview)) { - $images = []; - foreach ($format->preview->images->children() as $image) { - $imageObj = new Image(); - $imageObj->setAlt( $image['alt']->__toString()); - $imageObj->setHeight((int) $image['height']->__toString()); - $imageObj->setWidth((int) $image['width']->__toString()); - $imageObj->setLink($image->__toString()); - $images[] = $imageObj; - } - $aFormat['preview'] = $images; - } - $this->playbacks[] = $aFormat; - } - } - - /** - * @return array - */ - public function getPlaybacks(): array - { - return $this->playbacks; - } - - /** - * @param array $playbacks - */ - public function setPlaybacks(array $playbacks): void - { - $this->playbacks = $playbacks; } /** @@ -155,6 +134,7 @@ public function getEndTime() /** * @return string + * @deprecated */ public function getPlaybackType() { @@ -163,6 +143,7 @@ public function getPlaybackType() /** * @return string + * @deprecated */ public function getPlaybackUrl() { @@ -171,6 +152,7 @@ public function getPlaybackUrl() /** * @return string + * @deprecated */ public function getPlaybackLength() { @@ -184,4 +166,19 @@ public function getMetas() { return $this->metas; } + + /** + * @return Format[] + */ + public function getFormats() + { + if ($this->formats === null) { + $this->formats = []; + foreach ($this->rawXml->playback->format as $formatXml) { + $this->formats[] = new Format($formatXml); + } + } + + return $this->formats; + } } diff --git a/tests/Responses/GetRecordingsResponseTest.php b/tests/Responses/GetRecordingsResponseTest.php index fa068130..2140522b 100644 --- a/tests/Responses/GetRecordingsResponseTest.php +++ b/tests/Responses/GetRecordingsResponseTest.php @@ -16,6 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License along * with BigBlueButton; if not, see . */ + namespace BigBlueButton\Parameters; use BigBlueButton\Responses\GetRecordingsResponse; @@ -65,36 +66,33 @@ public function testRecordMetadataContent() $this->assertEquals('moodle-mod_bigbluebuttonbn (2015080611)', $metas['bbb-origin-tag']); } - public function testRecordingsPlayback() + public function testRecordingsPlaybackFormats() { $this->assertEquals('SUCCESS', $this->records->getReturnCode()); $this->assertCount(6, $this->records->getRecords()); - $aRecord = $this->records->getRecords()[0]; - $formatN1 = $aRecord->getPlaybacks()[0]; // without images preview - $this->assertEquals('podcast', $formatN1['type']); - $this->assertEquals('https://testurl/podcast/1.ogg', $formatN1['url']); - $this->assertEquals('111', $formatN1['processingTime']); - $this->assertEquals('222', $formatN1['length']); - $this->assertEquals('333', $formatN1['size']); - - $formatN2 = $aRecord->getPlaybacks()[1]; // having images preview - $this->assertEquals('presentation', $formatN2['type']); - $this->assertEquals('https://testurl/podcast/2.ogg', $formatN2['url']); - $this->assertEquals('444', $formatN2['processingTime']); - $this->assertEquals('555', $formatN2['length']); - $this->assertEquals('666', $formatN2['size']); - - $images = $formatN2['preview']; - $this->assertEquals('testurl1', $images[0]->getAlt()); - $this->assertEquals('136', $images[0]->getHeight()); - $this->assertEquals('176', $images[0]->getWidth()); - $this->assertEquals('https://testurl1.png', $images[0]->getLink()); - - $this->assertEquals('testurl2', $images[1]->getAlt()); - $this->assertEquals('136', $images[1]->getHeight()); - $this->assertEquals('176', $images[1]->getWidth()); - $this->assertEquals('https://testurl2.png', $images[1]->getLink()); + $aRecord = $this->records->getRecords()[0]; + + // Test podcast format + $podcastFormat = $aRecord->getFormats()[0]; // without images preview + $this->assertEquals('podcast', $podcastFormat->getType()); + $this->assertEquals('https://test-install.blindsidenetworks.com/podcast/f71d810b6e90a4a34ae02b8c7143e8733178578e-1462807897120/audio.ogg', $podcastFormat->getUrl()); + $this->assertEquals('111', $podcastFormat->getProcessingTime()); + $this->assertEquals('632', $podcastFormat->getLength()); + $this->assertEquals('10500', $podcastFormat->getSize()); + + $presentationFormat = $aRecord->getFormats()[1]; // having images preview + $this->assertEquals('presentation', $presentationFormat->getType()); + $this->assertEquals('http://test-install.blindsidenetworks.com/playback/presentation/0.9.0/playback.html?meetingId=f71d810b6e90a4a34ae02b8c7143e8733178578e-1462807897120', $presentationFormat->getUrl()); + $this->assertEquals(2973, $presentationFormat->getProcessingTime()); + $this->assertEquals(532, $presentationFormat->getLength()); + $this->assertEquals(168019, $presentationFormat->getSize()); + + $image = $presentationFormat->getImages()[0]; + $this->assertEquals('Welcome', $image->getAlt()); + $this->assertEquals(136, $image->getHeight()); + $this->assertEquals(176, $image->getWidth()); + $this->assertEquals('https://test-install.blindsidenetworks.com/presentation/f71d810b6e90a4a34ae02b8c7143e8733178578e-1462807897120/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1632646357291/thumbnails/thumb-1.png', $image->getUrl()); } public function testGetRecordingResponseTypes() diff --git a/tests/fixtures/get_recordings.xml b/tests/fixtures/get_recordings.xml index bd00edec..1a3c9bf1 100644 --- a/tests/fixtures/get_recordings.xml +++ b/tests/fixtures/get_recordings.xml @@ -23,21 +23,21 @@ podcast - https://testurl/podcast/1.ogg + https://test-install.blindsidenetworks.com/podcast/f71d810b6e90a4a34ae02b8c7143e8733178578e-1462807897120/audio.ogg 111 - 222 - 333 + 632 + 10500 presentation - https://testurl/podcast/2.ogg - 444 - 555 - 666 + http://test-install.blindsidenetworks.com/playback/presentation/0.9.0/playback.html?meetingId=f71d810b6e90a4a34ae02b8c7143e8733178578e-1462807897120 + 2973 + 532 + 168019 - testurl1https://testurl1.png - testurl2https://testurl2.png + Welcomehttps://test-install.blindsidenetworks.com/presentation/f71d810b6e90a4a34ae02b8c7143e8733178578e-1462807897120/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1632646357291/thumbnails/thumb-1.png + Coursehttps://test-install.blindsidenetworks.com/presentation/f71d810b6e90a4a34ae02b8c7143e8733178578e-1462807897120/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1632646357291/thumbnails/thumb-2.png @@ -65,7 +65,7 @@ presentation - http://test-install.blindsidenetworks.com/playback/presentation/0.9.0/playback.html?meetingId=f71d810b6e90a4a34ae02b8c7143e8733178578e-1463153001071 + https://test-install.blindsidenetworks.com/playback/presentation/0.9.0/playback.html?meetingId=f71d810b6e90a4a34ae02b8c7143e8733178578e-1463153001071 126 @@ -86,7 +86,8 @@ - + + @@ -140,7 +141,8 @@ - + +