Skip to content

Commit 3754760

Browse files
elke-hshferishili
andauthored
Fixes #54 (#55)
* Fixes #54 * read paella json data properly from mod, (#57) fixes #56 * Use Opencast PHP Library for api call Change error message * make sure lti launch gets a proper base url in both allinone and multi-nodes opencast instances * change the service to search and make sure it is active * get rid of services --------- Co-authored-by: FarbodZamani <53179227+ferishili@users.noreply.github.com> Co-authored-by: ferishili <zamanifarbod2@gmail.com>
1 parent 3ade3f8 commit 3754760

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

classes/local/lti_helper.php

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
namespace filter_opencast\local;
2626

2727
use oauth_helper;
28+
use tool_opencast\exception\opencast_api_response_exception;
2829
use tool_opencast\local\settings_api;
30+
use tool_opencast\local\api;
31+
use moodle_exception;
2932

3033
/**
3134
* LTI helper class for filter opencast.
@@ -147,11 +150,12 @@ public static function is_lti_credentials_configured(int $ocinstanceid) {
147150
* - ocinstanceid: The ID of the Opencast instance.
148151
* - consumerkey: The LTI consumer key for the instance.
149152
* - consumersecret: The LTI consumer secret for the instance.
150-
* - baseurl: The API URL for the Opencast instance.
153+
* - baseurl: The API URL for the presentation node of Opencast instance.
151154
*/
152155
public static function get_lti_set_object(int $ocinstanceid) {
153156
$lticredentials = self::get_lti_credentials($ocinstanceid);
154-
$baseurl = settings_api::get_apiurl($ocinstanceid);
157+
// Get url of the engage.ui.
158+
$baseurl = self::get_engage_url($ocinstanceid);
155159

156160
return (object) [
157161
'ocinstanceid' => $ocinstanceid,
@@ -188,4 +192,51 @@ public static function get_filter_lti_launch_url(int $ocinstanceid, int $coursei
188192
}
189193
return $ltilaunchurl;
190194
}
195+
196+
197+
/**
198+
* Retrieves the engage URL for a given Opencast instance.
199+
*
200+
* This function attempts to get the engage URL for the specified Opencast instance.
201+
* It first tries to fetch the URL from the Opencast API. If that fails, it falls back
202+
* to using the API URL as the engage URL.
203+
*
204+
* @param int $ocinstanceid The ID of the Opencast instance.
205+
*
206+
* @return string The engage URL for the Opencast instance.
207+
*
208+
* @throws opencast_api_response_exception If the API request fails.
209+
*/
210+
public static function get_engage_url(int $ocinstanceid) {
211+
$api = api::get_instance($ocinstanceid);
212+
213+
// As a default fallback, we assume that the engage node url is the same as the api url.
214+
$engageurl = settings_api::get_apiurl($ocinstanceid);
215+
216+
// Try to get the engage url from engage ui url once more, as secondary fallback method.
217+
$response = $api->opencastapi->baseApi->getOrgEngageUIUrl();
218+
$code = $response['code'];
219+
// If something went wrong, we throw opencast_api_response_exception exception.
220+
if ($code != 200) {
221+
throw new opencast_api_response_exception($response);
222+
}
223+
224+
// Get the engage ui object from the get call.
225+
$engageuiobj = (array) $response['body'];
226+
227+
// Check if we have a valid engage ui url.
228+
if (isset($engageuiobj['org.opencastproject.engage.ui.url'])) {
229+
$engageuiurl = $engageuiobj['org.opencastproject.engage.ui.url'];
230+
231+
// Check if the engage ui url is not empty and not a localhost url.
232+
if (!empty($engageuiurl) &&
233+
strpos($engageuiurl, 'http://') === false &&
234+
strpos($engageuiurl, 'localhost') === false ) {
235+
$engageurl = $engageuiurl;
236+
}
237+
}
238+
239+
// Finally, we return it.
240+
return $engageurl;
241+
}
191242
}

classes/text_filter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected function render_player(int $ocinstanceid, string $episodeid, bool $sho
212212
int $playerid, $width = null, $height = null) {
213213
global $OUTPUT, $PAGE, $COURSE;
214214

215-
$data = paella_transform::get_paella_data_json($ocinstanceid, $episodeid);
215+
list($data, $errormessage) = paella_transform::get_paella_data_json($ocinstanceid, $episodeid);
216216

217217
if (!$data) {
218218
return null;
@@ -253,9 +253,10 @@ protected function render_player(int $ocinstanceid, string $episodeid, bool $sho
253253
$renderer = $PAGE->get_renderer('filter_opencast');
254254
return $renderer->render_player($mustachedata);
255255
} else {
256+
$notificationmessage = !empty($errormessage) ? $errormessage : get_string('erroremptystreamsources', 'mod_opencast');
256257
return $OUTPUT->render(new \core\output\notification(
257-
get_string('erroremptystreamsources', 'mod_opencast'),
258-
\core\output\notification::NOTIFY_ERROR
258+
$notificationmessage,
259+
\core\output\notification::NOTIFY_ERROR
259260
));
260261
}
261262
}

0 commit comments

Comments
 (0)