|
25 | 25 | namespace filter_opencast\local;
|
26 | 26 |
|
27 | 27 | use oauth_helper;
|
| 28 | +use tool_opencast\exception\opencast_api_response_exception; |
28 | 29 | use tool_opencast\local\settings_api;
|
| 30 | +use tool_opencast\local\api; |
| 31 | +use moodle_exception; |
29 | 32 |
|
30 | 33 | /**
|
31 | 34 | * LTI helper class for filter opencast.
|
@@ -147,11 +150,12 @@ public static function is_lti_credentials_configured(int $ocinstanceid) {
|
147 | 150 | * - ocinstanceid: The ID of the Opencast instance.
|
148 | 151 | * - consumerkey: The LTI consumer key for the instance.
|
149 | 152 | * - 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. |
151 | 154 | */
|
152 | 155 | public static function get_lti_set_object(int $ocinstanceid) {
|
153 | 156 | $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); |
155 | 159 |
|
156 | 160 | return (object) [
|
157 | 161 | 'ocinstanceid' => $ocinstanceid,
|
@@ -188,4 +192,51 @@ public static function get_filter_lti_launch_url(int $ocinstanceid, int $coursei
|
188 | 192 | }
|
189 | 193 | return $ltilaunchurl;
|
190 | 194 | }
|
| 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 | + } |
191 | 242 | }
|
0 commit comments