From 230265f330ef5cbb9e1ede7e86b00b99387f5049 Mon Sep 17 00:00:00 2001 From: Justus Dieckmann Date: Mon, 4 Mar 2024 15:33:35 +0100 Subject: [PATCH] Add error message in case there is no stream for the video --- filter.php | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/filter.php b/filter.php index 2bc93b0..62d28f4 100644 --- a/filter.php +++ b/filter.php @@ -44,7 +44,7 @@ class filter_opencast extends moodle_text_filter { * @throws dml_exception */ public function filter($text, array $options = []) { - global $CFG, $PAGE; + global $PAGE, $OUTPUT; $i = 0; if (stripos($text, '') === false) { @@ -134,28 +134,34 @@ public function filter($text, array $options = []) { $mustachedata->height = $height; $mustachedata->modplayerpath = (new moodle_url('/mod/opencast/player.html'))->out(); - if (isset($data['streams']) && count($data['streams']) === 1) { - $sources = $data['streams'][0]['sources']; - $res = $sources[array_key_first($sources)][0]['res']; - $resolution = $res['w'] . '/' . $res['h']; - $mustachedata->resolution = $resolution; - - if ($width xor $height) { - if ($width) { - $mustachedata->height = $width * ($res['h'] / $res['w']); - } else if ($height) { - $mustachedata->width = $height * ($res['w'] / $res['h']); + if (isset($data['streams'])) { + if (count($data['streams']) === 1) { + $sources = $data['streams'][0]['sources']; + $res = $sources[array_key_first($sources)][0]['res']; + $resolution = $res['w'] . '/' . $res['h']; + $mustachedata->resolution = $resolution; + + if ($width xor $height) { + if ($width) { + $mustachedata->height = $width * ($res['h'] / $res['w']); + } else if ($height) { + $mustachedata->width = $height * ($res['w'] / $res['h']); + } + } + } else { + if ($width && $height) { + $mustachedata->width = $width; + $mustachedata->height = $height; } } + $newtext = $renderer->render_player($mustachedata); } else { - if ($width && $height) { - $mustachedata->width = $width; - $mustachedata->height = $height; - } + $newtext = $OUTPUT->render(new \core\output\notification( + get_string('erroremptystreamsources', 'mod_opencast'), + \core\output\notification::NOTIFY_ERROR + )); } - $newtext = $renderer->render_player($mustachedata); - // Replace video tag. $text = preg_replace('/).)*?' . preg_quote($match, '/') . '.*?<\/video>/', $newtext, $text, 1);