Skip to content
Snippets Groups Projects
Commit 7b364303 authored by TamaraGunkel's avatar TamaraGunkel
Browse files

Created a render function for the form as suggested in #6

parent ff82234a
Branches
No related tags found
No related merge requests found
......@@ -30,7 +30,7 @@ require_once($CFG->dirroot . '/lib/oauthlib.php');
* Use lti to login and retrieve cookie from opencast.
*/
function filter_opencast_login() {
global $CFG, $PAGE, $COURSE, $USER;
global $PAGE;
// Get api url of opencast.
$endpoint = get_config('tool_opencast', 'apiurl');
......@@ -39,6 +39,20 @@ function filter_opencast_login() {
}
$endpoint .= '/lti';
// Create parameters.
$params = filter_opencast_create_parameters($endpoint);
// Render form.
$renderer = $PAGE->get_renderer('filter_opencast');
echo $renderer->render_player($endpoint, $params);
// Submit form.
$PAGE->requires->js_call_amd('filter_opencast/form', 'init');
}
function filter_opencast_create_parameters() {
global $CFG, $COURSE, $USER;
// Get consumerkey and consumersecret.
$consumerkey = get_config('filter_opencast', 'consumerkey');
$consumersecret = get_config('filter_opencast', 'consumersecret');
......@@ -85,21 +99,5 @@ function filter_opencast_login() {
$params['oauth_signature_method'] = 'HMAC-SHA1';
$params['oauth_signature'] = $helper->sign("POST", $endpoint, $params, $consumersecret . '&');
$content = "<form action=\"" . urlencode($endpoint) .
"\" name=\"ltiLaunchForm\" id=\"ltiLaunchForm\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";
// Construct html form for the launch parameters.
foreach ($params as $key => $value) {
$key = htmlspecialchars($key);
$value = htmlspecialchars($value);
$content .= "<input type=\"hidden\" name=\"{$key}\"";
$content .= " value=\"";
$content .= $value;
$content .= "\"/>\n";
}
$content .= "</form>\n";
echo $content;
// Submit form.
$PAGE->requires->js_call_amd('filter_opencast/form', 'init');
return $params;
}
\ No newline at end of file
......@@ -45,4 +45,28 @@ class filter_opencast_renderer extends plugin_renderer_base {
public function render_player($data) {
return $this->render_from_template('filter_opencast/player', $data);
}
/**
* Display the lti form.
*
* @param object $data The prepared variables.
* @return string
*/
public function render_lti_form($endpoint, $params) {
$content = "<form action=\"" . urlencode($endpoint) .
"\" name=\"ltiLaunchForm\" id=\"ltiLaunchForm\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";
// Construct html form for the launch parameters.
foreach ($params as $key => $value) {
$key = htmlspecialchars($key);
$value = htmlspecialchars($value);
$content .= "<input type=\"hidden\" name=\"{$key}\"";
$content .= " value=\"";
$content .= $value;
$content .= "\"/>\n";
}
$content .= "</form>\n";
return $content;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment