Skip to content

Commit

Permalink
Fixes #54 (#55) (#58)
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: elke-hsh <141309452+elke-hsh@users.noreply.github.com>
Co-authored-by: FarbodZamani <53179227+ferishili@users.noreply.github.com>
Co-authored-by: ferishili <zamanifarbod2@gmail.com>
  • Loading branch information
4 people authored Jan 16, 2025
1 parent 55141fc commit 684a3ea
Showing 1 changed file with 53 additions and 2 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;
}
}

0 comments on commit 684a3ea

Please sign in to comment.