Skip to content

Commit

Permalink
introducing new studio settingsFile param, fixes #337 (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili authored Jul 26, 2023
1 parent 74be65d commit cf94c4b
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 55 deletions.
80 changes: 80 additions & 0 deletions classes/local/apibridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -2957,4 +2957,84 @@ public function can_show_directaccess_link($video, $courseid, $capabilitycheck =
}
return false;
}

/**
* Central place to generate studio url path and its query params if applicable.
*
* @param string $courseid Course ID
* @param string $seriesid Series identifier
* @return ?string the generated studio url path or null if something went wrong.
*/
public function generate_studio_url_path($courseid, $seriesid) {
global $SITE;
// Return null if the requirements are missing.
if (empty($courseid) || empty($seriesid)) {
return null;
}
$studiourlpath = '/studio';
$queryparams = [
'upload.seriesId=' . $seriesid
];
// Check if Studio return button is enabled.
if (get_config('block_opencast', 'show_opencast_studio_return_btn_' . $this->ocinstanceid)) {
// Initializing default label for studio return button.
$studioreturnbtnlabel = $SITE->fullname;
// Check if custom label is configured.
if (!empty(get_config('block_opencast', 'opencast_studio_return_btn_label_' . $this->ocinstanceid))) {
$studioreturnbtnlabel = get_config('block_opencast', 'opencast_studio_return_btn_label_' . $this->ocinstanceid);
}

// Initializing default studio return url.
$studioreturnurl = new \moodle_url('/blocks/opencast/index.php',
array('courseid' => $courseid, 'ocinstanceid' => $this->ocinstanceid));
// Check if custom return url is configured.
if (!empty(get_config('block_opencast', 'opencast_studio_return_url_' . $this->ocinstanceid))) {
// Prepare the custom url.
$customreturnurl = get_config('block_opencast', 'opencast_studio_return_url_' . $this->ocinstanceid);
// Slipt it into parts, to extract endpoint and query strings.
$customreturnurlarray = explode('?', $customreturnurl);
$customurl = $customreturnurlarray[0];
$customquerystring = count($customreturnurlarray) > 1 ? $customreturnurlarray[1] : null;

$customurldata = [];
// If there is any query string.
if (!empty($customquerystring)) {
// Split them.
$customquerystringdata = explode('&', $customquerystring);
// Put them into loop to replace the placeholders and add them into the customurldata array.
foreach ($customquerystringdata as $data) {
$datastring = str_replace(['[COURSEID]', '[OCINSTANCEID]'], [$courseid, $this->ocinstanceid], $data);
$dataarray = explode('=', $datastring);
if (count($dataarray) == 2) {
$customurldata[$dataarray[0]] = $dataarray[1];
}
}
}

if (!empty($customurl)) {
$studioreturnurl = new \moodle_url($customurl, $customurldata);
}
}

// Appending studio return data, only when there is a url.
if (!empty($studioreturnurl)) {
$queryparams[] = 'return.label=' . urlencode($studioreturnbtnlabel);
$queryparams[] = 'return.target=' . urlencode($studioreturnurl->out(false));
}
}

// Checking if custom settings filename is set.
$customseetingsfilename = get_config('block_opencast', 'opencast_studio_custom_settings_filename_' . $this->ocinstanceid);
if (!empty($customseetingsfilename)) {
$queryparams[] = 'settingsFile=' . $customseetingsfilename;
}

// Append query params to the url path.
if (!empty($queryparams)) {
$studiourlpath .= '?' . implode('&', $queryparams);
}

// Finally we return the generate studio url path.
return $studiourlpath;
}
}
4 changes: 3 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@
$endpoint = 'http://' . $endpoint;
}

$url = $endpoint . '/studio?upload.seriesId=' . $apibridge->get_stored_seriesid($courseid, true, $USER->id);
$seriesid = $apibridge->get_stored_seriesid($courseid, true, $USER->id);
$studiourlpath = $apibridge->generate_studio_url_path($courseid, $seriesid);
$url = $endpoint . $studiourlpath;
$recordvideobutton = $OUTPUT->action_link($url, get_string('recordvideo', 'block_opencast'),
null, array('class' => 'btn btn-secondary', 'target' => $target));
echo html_writer::div($recordvideobutton, 'opencast-recordvideo-wrap');
Expand Down
2 changes: 2 additions & 0 deletions lang/en/block_opencast.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@
$string['opencaststudioreturnurl_desc'] = 'When empty the return url redirects back to the same Moodle opencast block overview where the request comes from. A custom endpoint URL will then be passed to Studio as return url when configured, in this case, admin is able to use 2 placeholders including [OCINSTANCEID] and [COURSEID]. Please NOTE: the URL must be relative to wwwroot.';
$string['opencaststudioreturnbtnlabel'] = 'Label for Studio\'s return button';
$string['opencaststudioreturnbtnlabel_desc'] = 'This label works as a short description where the return link leads to. This label will be appended to the Studio return button text, when empty, moodle site name will be passed as label.';
$string['opencaststudiocustomsettingsfilename'] = 'Custom Studio settings filename';
$string['opencaststudiocustomsettingsfilename_desc'] = 'This custom settings filename will be appended to the query when redirecting to Studio, afterwards the Studio looks for this filename relative to its directory and read its settings from that file.<br><b>NOTE</b>: Requires Opencast 14.2 or later.';

// Strings for new visibility feature during initail upload.
$string['visibilityheader'] = 'Event Visibility';
Expand Down
55 changes: 3 additions & 52 deletions recordvideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,59 +63,10 @@
// Get series ID, create a new one if necessary.
$seriesid = $apibridge->get_stored_seriesid($courseid, true, $USER->id);

// Create lti customtool to redirect to Studio.
$customtoolparams = [];
// Check if Studio return button is enabled.
if (get_config('block_opencast', 'show_opencast_studio_return_btn_' . $ocinstanceid)) {
// Initializing default label for studio return button.
$studioreturnbtnlabel = $SITE->fullname;
// Check if custom label is configured.
if (!empty(get_config('block_opencast', 'opencast_studio_return_btn_label_' . $ocinstanceid))) {
$studioreturnbtnlabel = get_config('block_opencast', 'opencast_studio_return_btn_label_' . $ocinstanceid);
}

// Initializing default studio return url.
$studioreturnurl = new moodle_url('/blocks/opencast/index.php',
array('courseid' => $courseid, 'ocinstanceid' => $ocinstanceid));
// Check if custom return url is configured.
if (!empty(get_config('block_opencast', 'opencast_studio_return_url_' . $ocinstanceid))) {
// Prepare the custom url.
$customreturnurl = get_config('block_opencast', 'opencast_studio_return_url_' . $ocinstanceid);
// Slipt it into parts, to extract endpoint and query strings.
$customreturnurlarray = explode('?', $customreturnurl);
$customurl = $customreturnurlarray[0];
$customquerystring = count($customreturnurlarray) > 1 ? $customreturnurlarray[1] : null;

$customurldata = [];
// If there is any query string.
if (!empty($customquerystring)) {
// Split them.
$customquerystringdata = explode('&', $customquerystring);
// Put them into loop to replace the placeholders and add them into the customurldata array.
foreach ($customquerystringdata as $data) {
$datastring = str_replace(['[COURSEID]', '[OCINSTANCEID]'], [$courseid, $ocinstanceid], $data);
$dataarray = explode('=', $datastring);
if (count($dataarray) == 2) {
$customurldata[$dataarray[0]] = $dataarray[1];
}
}
}

if (!empty($customurl)) {
$studioreturnurl = new moodle_url($customurl, $customurldata);
}
}

// Appending studio return data, only when there is a url.
if (!empty($studioreturnurl)) {
$customtoolparams[] = 'return.label=' . urlencode($studioreturnbtnlabel);
$customtoolparams[] = 'return.target=' . urlencode($studioreturnurl->out(false));
}
}
$customtoolparams[] = 'upload.seriesId=' . $seriesid;
$customtool = '/studio?' . implode('&', $customtoolparams);
// Create parameters.
// Get Studio url path to insert as customtool.
$customtool = $apibridge->generate_studio_url_path($courseid, $seriesid);

// Create parameters.
$consumerkey = $apibridge->get_lti_consumerkey();
$consumersecret = $apibridge->get_lti_consumersecret();
$params = \block_opencast\local\lti_helper::create_lti_parameters($consumerkey, $consumersecret, $ltiendpoint, $customtool);
Expand Down
5 changes: 3 additions & 2 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,9 @@ public function render_block_content($courseid, $videodata, $ocinstance, $render
if (strpos($endpoint, 'http') !== 0) {
$endpoint = 'http://' . $endpoint;
}

$url = $endpoint . '/studio?upload.seriesId=' . $apibridge->get_stored_seriesid($courseid, true, $USER->id);
$seriesid = $apibridge->get_stored_seriesid($courseid, true, $USER->id);
$studiourlpath = $apibridge->generate_studio_url_path($courseid, $seriesid);
$url = $endpoint . $studiourlpath;
$recordvideobutton = $this->output->action_link($url, get_string('recordvideo', 'block_opencast'),
null, array('class' => 'btn btn-secondary', 'target' => $target));
$html .= html_writer::div($recordvideobutton, 'opencast-recordvideo-wrap overview');
Expand Down
6 changes: 6 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@
get_string('opencaststudioreturnurl_desc', 'block_opencast'),
'/blocks/opencast/index.php?courseid=[COURSEID]&ocinstanceid=[OCINSTANCEID]'));

$additionalsettings->add(
new admin_setting_configtext('block_opencast/opencast_studio_custom_settings_filename_' . $instance->id,
get_string('opencaststudiocustomsettingsfilename', 'block_opencast'),
get_string('opencaststudiocustomsettingsfilename_desc', 'block_opencast'),
''));

// Opencast Editor Integration in additional feature settings.
$additionalsettings->add(
new admin_setting_heading('block_opencast/opencast_videoeditor_' . $instance->id,
Expand Down

0 comments on commit cf94c4b

Please sign in to comment.