From b02ea27a15bc0f1758a53173c73148127dc4795a Mon Sep 17 00:00:00 2001 From: Elke Kreim Date: Wed, 15 Jan 2025 15:35:09 +0100 Subject: [PATCH] Use Opencast PHP Library for api call Change error message --- classes/local/lti_helper.php | 21 +++++++++++---------- lang/en/filter_opencast.php | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/classes/local/lti_helper.php b/classes/local/lti_helper.php index ced02ea..190e4ac 100644 --- a/classes/local/lti_helper.php +++ b/classes/local/lti_helper.php @@ -24,7 +24,6 @@ namespace filter_opencast\local; -use core\check\performance\debugging; use oauth_helper; use tool_opencast\local\settings_api; use tool_opencast\local\api; @@ -199,20 +198,22 @@ public static function get_filter_lti_launch_url(int $ocinstanceid, int $coursei * This function calls an api endpoint because the url of the engage.ui is different depending on * the installation (All-In-One or Multiple Servers). * - * @param int $ocinstancid + * @param int $ocinstanceid * @return string $url the url of the engage.ui of the opencast installation * @throws \moodle_exception */ - public static function get_engage_url(int $ocinstancid) { - $api = api::get_instance($ocinstancid); + public static function get_engage_url(int $ocinstanceid) { + $api = api::get_instance($ocinstanceid); // Endpoint to call the engage.ui url of presentation node. // Make sure the api user has the rights to call that api endpoint. - $engageurlendpoint = '/api/info/organization/properties/engageuiurl'; - $result = json_decode($api->oc_get($engageurlendpoint), true); - $url = $result['org.opencastproject.engage.ui.url']; - if (!$url) { - throw new \moodle_exception('no_engageurl_error', 'filter_opencast'); + $response = $api->opencastapi->baseApi->getOrgEngageUIUrl(); + if ($response['code'] != 200) { + global $CFG; + $supportemail = $CFG->supportemail; + throw new \moodle_exception('no_engageurl_error', 'filter_opencast', '', $supportemail); + } else { + $engageui = $response['body']; + return $engageui->{'org.opencastproject.engage.ui.url'}; } - return $url; } } diff --git a/lang/en/filter_opencast.php b/lang/en/filter_opencast.php index 52b6afc..ffe78cb 100644 --- a/lang/en/filter_opencast.php +++ b/lang/en/filter_opencast.php @@ -35,4 +35,4 @@ $string['setting_uselti_desc'] = 'When enabled, Opencast videos are delivered through LTI authentication using the default Opencast video player. This is typically used alongside Secure Static Files in Opencast for enhanced security.'; $string['setting_uselti_nolti_desc'] = 'To enable LTI Authentication for Opencast, you must configure the required credentials (Consumer Key and Consumer Secret) for this instance. Please do so via this link: {$a}'; $string['setting_uselti_ocinstance_name'] = 'Opencast API {$a} Instance'; -$string['no_engageurl_error'] = 'No URL available. Please check if the api endpoint is available and if the api user has the proper rights.'; +$string['no_engageurl_error'] = 'Opencast API call for Engage URL not successful. Please contact your support {$a}.';