commit 8cda3d6ecc28cd8e677b9b399f0c3921a0420b40 Author: smarcet Date: Mon Oct 5 16:03:18 2020 -0300 Added new Summit event property to serializer stream_thumbnail Change-Id: Id42fc4faea08c3ffdeddd9c50a991c8bab9ed34c Signed-off-by: smarcet diff --git a/app/ModelSerializers/Summit/SummitEventSerializer.php b/app/ModelSerializers/Summit/SummitEventSerializer.php index 84bd781..a175bdb 100644 --- a/app/ModelSerializers/Summit/SummitEventSerializer.php +++ b/app/ModelSerializers/Summit/SummitEventSerializer.php @@ -47,6 +47,7 @@ class SummitEventSerializer extends SilverStripeSerializer 'TotalAttendanceCount' => 'attendance_count:json_int', 'CurrentAttendanceCount' => 'current_attendance_count:json_int', 'ImageUrl' => 'image:json_url', + "StreamThumbnailUrl" => "stream_thumbnail:json_url" ]; protected static $allowed_fields = [ diff --git a/app/Models/Foundation/Summit/Events/SummitEvent.php b/app/Models/Foundation/Summit/Events/SummitEvent.php index daaa739..d938e52 100644 --- a/app/Models/Foundation/Summit/Events/SummitEvent.php +++ b/app/Models/Foundation/Summit/Events/SummitEvent.php @@ -1259,4 +1259,26 @@ class SummitEvent extends SilverstripeBaseModel if($member->hasPaidTicketOnSummit($this->summit)) return true; return false; } + + /** + * @return bool + */ + public function isMuxStream():bool{ + if(empty($this->streaming_url)) return false; + if (preg_match("/(.*\.mux\.com)/i", $this->streaming_url)) return true; + return false; + } + + /** + * @return string|null + */ + public function getStreamThumbnailUrl():?string{ + if($this->isMuxStream()){ + $matches = []; + if(preg_match("/^(.*\.mux\.com)\/(.*)(\.m3u8)$/",$this->streaming_url, $matches)){ + return sprintf("https://image.mux.com/%s/thumbnail.jpg", $matches[2]); + } + } + return null; + } } \ No newline at end of file