Skip to content

Commit

Permalink
Fixes #54 (#55)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: ferishili <[email protected]>
  • Loading branch information
3 people authored Jan 16, 2025
1 parent 3ade3f8 commit 3754760
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
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

0 comments on commit 3754760

Please sign in to comment.