Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Opencast-Moodle/moodle-filter_opencast#54 (#55) #58

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions classes/local/lti_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
namespace filter_opencast\local;

use oauth_helper;
use tool_opencast\exception\opencast_api_response_exception;
use tool_opencast\local\settings_api;
use tool_opencast\local\api;
use moodle_exception;

/**
* LTI helper class for filter opencast.
Expand Down Expand Up @@ -147,11 +150,12 @@ public static function is_lti_credentials_configured(int $ocinstanceid) {
* - ocinstanceid: The ID of the Opencast instance.
* - consumerkey: The LTI consumer key for the instance.
* - consumersecret: The LTI consumer secret for the instance.
* - baseurl: The API URL for the Opencast instance.
* - baseurl: The API URL for the presentation node of Opencast instance.
*/
public static function get_lti_set_object(int $ocinstanceid) {
$lticredentials = self::get_lti_credentials($ocinstanceid);
$baseurl = settings_api::get_apiurl($ocinstanceid);
// Get url of the engage.ui.
$baseurl = self::get_engage_url($ocinstanceid);

return (object) [
'ocinstanceid' => $ocinstanceid,
Expand Down Expand Up @@ -188,4 +192,51 @@ public static function get_filter_lti_launch_url(int $ocinstanceid, int $coursei
}
return $ltilaunchurl;
}


/**
* Retrieves the engage URL for a given Opencast instance.
*
* This function attempts to get the engage URL for the specified Opencast instance.
* It first tries to fetch the URL from the Opencast API. If that fails, it falls back
* to using the API URL as the engage URL.
*
* @param int $ocinstanceid The ID of the Opencast instance.
*
* @return string The engage URL for the Opencast instance.
*
* @throws opencast_api_response_exception If the API request fails.
*/
public static function get_engage_url(int $ocinstanceid) {
$api = api::get_instance($ocinstanceid);

// As a default fallback, we assume that the engage node url is the same as the api url.
$engageurl = settings_api::get_apiurl($ocinstanceid);

// Try to get the engage url from engage ui url once more, as secondary fallback method.
$response = $api->opencastapi->baseApi->getOrgEngageUIUrl();
$code = $response['code'];
// If something went wrong, we throw opencast_api_response_exception exception.
if ($code != 200) {
throw new opencast_api_response_exception($response);
}

// Get the engage ui object from the get call.
$engageuiobj = (array) $response['body'];

// Check if we have a valid engage ui url.
if (isset($engageuiobj['org.opencastproject.engage.ui.url'])) {
$engageuiurl = $engageuiobj['org.opencastproject.engage.ui.url'];

// Check if the engage ui url is not empty and not a localhost url.
if (!empty($engageuiurl) &&
strpos($engageuiurl, 'http://') === false &&
strpos($engageuiurl, 'localhost') === false ) {
$engageurl = $engageuiurl;
}
}

// Finally, we return it.
return $engageurl;
}
}
7 changes: 4 additions & 3 deletions classes/text_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected function render_player(int $ocinstanceid, string $episodeid, bool $sho
int $playerid, $width = null, $height = null) {
global $OUTPUT, $PAGE, $COURSE;

$data = paella_transform::get_paella_data_json($ocinstanceid, $episodeid);
list($data, $errormessage) = paella_transform::get_paella_data_json($ocinstanceid, $episodeid);

if (!$data) {
return null;
Expand Down Expand Up @@ -253,9 +253,10 @@ protected function render_player(int $ocinstanceid, string $episodeid, bool $sho
$renderer = $PAGE->get_renderer('filter_opencast');
return $renderer->render_player($mustachedata);
} else {
$notificationmessage = !empty($errormessage) ? $errormessage : get_string('erroremptystreamsources', 'mod_opencast');
return $OUTPUT->render(new \core\output\notification(
get_string('erroremptystreamsources', 'mod_opencast'),
\core\output\notification::NOTIFY_ERROR
$notificationmessage,
\core\output\notification::NOTIFY_ERROR
));
}
}
Expand Down
Loading