mirror of
https://github.com/moodle/moodle.git
synced 2025-04-06 00:42:44 +02:00
Test launch works
This commit is contained in:
parent
285f825046
commit
5f24742f86
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="mod/blti/db" VERSION="20110826" COMMENT="XMLDB file for Moodle mod/blti"
|
||||
<XMLDB PATH="mod/blti/db" VERSION="20110829" COMMENT="XMLDB file for Moodle mod/blti"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@ -38,8 +38,9 @@
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="basiclti Activity" SEQUENCE="false" COMMENT="Activity name" PREVIOUS="id" NEXT="baseurl"/>
|
||||
<FIELD NAME="baseurl" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="name" NEXT="state"/>
|
||||
<FIELD NAME="state" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="2" SEQUENCE="false" COMMENT="Active = 1, Pending = 2, Rejected = 3" PREVIOUS="baseurl" NEXT="course"/>
|
||||
<FIELD NAME="baseurl" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="name" NEXT="tooldomain"/>
|
||||
<FIELD NAME="tooldomain" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="baseurl" NEXT="state"/>
|
||||
<FIELD NAME="state" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="2" SEQUENCE="false" COMMENT="Active = 1, Pending = 2, Rejected = 3" PREVIOUS="tooldomain" NEXT="course"/>
|
||||
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="state" NEXT="coursevisible"/>
|
||||
<FIELD NAME="coursevisible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="course" NEXT="createdby"/>
|
||||
<FIELD NAME="createdby" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="coursevisible" NEXT="timecreated"/>
|
||||
@ -50,7 +51,8 @@
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
|
||||
<INDEX NAME="course" UNIQUE="false" FIELDS="course" NEXT="tooldomain"/>
|
||||
<INDEX NAME="tooldomain" UNIQUE="false" FIELDS="tooldomain" PREVIOUS="course"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="blti_types_config" COMMENT="Basic LTI types configuration" PREVIOUS="blti_types">
|
||||
|
@ -49,6 +49,8 @@ defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
require_once($CFG->dirroot.'/mod/blti/OAuth.php');
|
||||
|
||||
define('BLTI_URL_DOMAIN_REGEX', '/(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i');
|
||||
|
||||
/**
|
||||
* Prints a Basic LTI activity
|
||||
*
|
||||
@ -57,10 +59,21 @@ require_once($CFG->dirroot.'/mod/blti/OAuth.php');
|
||||
function blti_view($instance, $makeobject=false) {
|
||||
global $PAGE;
|
||||
|
||||
$typeconfig = blti_get_type_config($instance->typeid);
|
||||
$endpoint = $typeconfig['toolurl'];
|
||||
$key = $typeconfig['resourcekey'];
|
||||
$secret = $typeconfig['password'];
|
||||
if(empty($instance->typeid)){
|
||||
$tool = blti_get_tool_by_url_match($instance->toolurl);
|
||||
if($tool){
|
||||
$typeid = $tool->id;
|
||||
} else {
|
||||
//Tool not found
|
||||
}
|
||||
} else {
|
||||
$typeid = $instance->typeid;
|
||||
}
|
||||
|
||||
$typeconfig = blti_get_type_config($typeid);
|
||||
$endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl'];
|
||||
$key = !empty($instance->resourcekey) ? $instance->resourcekey : $typeconfig['resourcekey'];
|
||||
$secret = !empty($instance->password) ? $instance->password : $typeconfig['password'];
|
||||
$orgid = $typeconfig['organizationid'];
|
||||
/* Suppress this for now - Chuck
|
||||
$orgdesc = $typeconfig['organizationdescr'];
|
||||
@ -80,11 +93,8 @@ function blti_view($instance, $makeobject=false) {
|
||||
|
||||
$debuglaunch = ( $instance->debuglaunch == 1 );
|
||||
if ( $makeobject ) {
|
||||
// TODO: Need frame height
|
||||
$height = $instance->preferheight;
|
||||
if ((!$height) || ($height == 0)) {
|
||||
$height = 400;
|
||||
}
|
||||
$height = 600;
|
||||
|
||||
$content = post_launch_html($parms, $endpoint, $debuglaunch, $height);
|
||||
} else {
|
||||
$content = post_launch_html($parms, $endpoint, $debuglaunch, false);
|
||||
@ -126,7 +136,7 @@ function blti_build_request($instance, $typeconfig, $course) {
|
||||
"launch_presentation_locale" => $locale,
|
||||
);
|
||||
|
||||
$placementsecret = $instance->placementsecret;
|
||||
$placementsecret = $typeconfig['servicesalt'];
|
||||
if ( isset($placementsecret) ) {
|
||||
$suffix = ':::' . $USER->id . ':::' . $instance->id;
|
||||
$plaintext = $placementsecret . $suffix;
|
||||
@ -148,17 +158,6 @@ function blti_build_request($instance, $typeconfig, $course) {
|
||||
$requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/blti/service.php';
|
||||
}
|
||||
|
||||
if ( isset($placementsecret) &&
|
||||
( $typeconfig['allowsetting'] == 1 ||
|
||||
( $typeconfig['allowsetting'] == 2 && $instance->instructorchoiceallowsetting == 1 ) ) ) {
|
||||
$requestparams["ext_ims_lti_tool_setting_id"] = $sourcedid;
|
||||
$requestparams["ext_ims_lti_tool_setting_url"] = $CFG->wwwroot.'/mod/blti/service.php';
|
||||
$setting = $instance->setting;
|
||||
if ( isset($setting) ) {
|
||||
$requestparams["ext_ims_lti_tool_setting"] = $setting;
|
||||
}
|
||||
}
|
||||
|
||||
// Send user's name and email data if appropriate
|
||||
if ( $typeconfig['sendname'] == 1 ||
|
||||
( $typeconfig['sendname'] == 2 && $instance->instructorchoicesendname == 1 ) ) {
|
||||
@ -299,16 +298,10 @@ function blti_get_type_config($typeid) {
|
||||
return $typeconfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all tool instances with a typeid of 0 that
|
||||
* marks them as unconfigured. These tools usually proceed from a
|
||||
* backup - restore process.
|
||||
*
|
||||
*/
|
||||
function blti_get_unconfigured_tools() {
|
||||
function blti_get_tools_by_domain($domain){
|
||||
global $DB;
|
||||
|
||||
return $DB->get_records('blti', array('typeid' => 0));
|
||||
|
||||
return $DB->get_records('blti_types', array('tooldomain' => $domain));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -334,6 +327,53 @@ function blti_get_types_for_add_instance(){
|
||||
return $types;
|
||||
}
|
||||
|
||||
function blti_get_domain_from_url($url){
|
||||
$matches = array();
|
||||
|
||||
if(preg_match(BLTI_URL_DOMAIN_REGEX, $url, $matches)){
|
||||
return $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
function blti_get_tool_by_url_match($url){
|
||||
$domain = blti_get_domain_from_url($url);
|
||||
|
||||
$possibletools = blti_get_tools_by_domain($domain);
|
||||
|
||||
return blti_get_best_tool_by_url($url, $possibletools);
|
||||
}
|
||||
|
||||
function blti_get_best_tool_by_url($url, $tools){
|
||||
if(count($tools) === 0){
|
||||
return null;
|
||||
}
|
||||
|
||||
$urllower = strtolower($url);
|
||||
|
||||
foreach($tools as $tool){
|
||||
$tool->_matchscore = 0;
|
||||
|
||||
$toolbaseurllower = strtolower($tool->baseurl);
|
||||
|
||||
if($urllower === $toolbaseurllower){
|
||||
$tool->_matchscore += 100;
|
||||
} else if(strstr($urllower, $toolbaseurllower) >= 0){
|
||||
$tool->_matchscore += 50;
|
||||
}
|
||||
}
|
||||
|
||||
$bestmatch = array_reduce($tools, function($value, $tool){
|
||||
if($tool->_matchscore > $value->_matchscore){
|
||||
return $tool;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
|
||||
}, (object)array('_matchscore' => -1));
|
||||
|
||||
return $bestmatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the various configured tool types
|
||||
*
|
||||
@ -554,7 +594,9 @@ function blti_update_config($config) {
|
||||
global $DB;
|
||||
|
||||
$return = true;
|
||||
if ($old = $DB->get_record('blti_types_config', array('typeid' => $config->typeid, 'name' => $config->name))) {
|
||||
$old = $DB->get_record('blti_types_config', array('typeid' => $config->typeid, 'name' => $config->name));
|
||||
|
||||
if ($old) {
|
||||
$config->id = $old->id;
|
||||
$return = $DB->update_record('blti_types_config', $config);
|
||||
} else {
|
||||
@ -563,52 +605,6 @@ function blti_update_config($config) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the screen that handles misconfigured objects due to
|
||||
* an incomplete backup - restore process
|
||||
*
|
||||
* @param int $id ID of the misconfigured tool
|
||||
*
|
||||
*/
|
||||
function blti_fix_misconfigured_choice($id) {
|
||||
global $CFG, $USER, $OUTPUT;
|
||||
|
||||
echo $OUTPUT->box_start('generalbox');
|
||||
echo '<div>';
|
||||
$types = blti_filter_get_types();
|
||||
if (!empty($types)) {
|
||||
echo '<h4 class="main">'.get_string('fixexistingconf', 'blti').'</h4></br>';
|
||||
echo '<form action='.$CFG->wwwroot.'/mod/blti/typessettings.php?action=fix&sesskey='.$USER->sesskey.' method="post">';
|
||||
|
||||
foreach ($types as $type) {
|
||||
echo '<input type="radio" name="useexisting" value="'.$type->id.'" />'.$type->name.'<br />';
|
||||
}
|
||||
echo '<input type="hidden" name="id" value="'.$id.'"/>';
|
||||
echo '<br />';
|
||||
echo '<div class="message"><input type="submit" value="'.get_string('fixold', 'blti').'"></div>';
|
||||
echo '</form>';
|
||||
} else {
|
||||
echo '<div class="message">';
|
||||
echo get_string('notypes', 'blti');
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
echo $OUTPUT->box_end();
|
||||
|
||||
echo $OUTPUT->box_start("generalbox");
|
||||
echo '<div>';
|
||||
echo '<h4 class="main">'.get_string('fixnewconf', 'blti').'</h4></br>';
|
||||
echo '<form action='.$CFG->wwwroot.'/mod/blti/typessettings.php?action=fix&sesskey='.$USER->sesskey.' method="post">';
|
||||
echo '<input type="hidden" name="id" value="'.$id.'"/>';
|
||||
echo '<input type="hidden" name="definenew" value="1"/>';
|
||||
echo '<div class="message"><input type="submit" value="'.get_string('fixnew', 'blti').'"></div>';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
echo $OUTPUT->box_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Signs the petition to launch the external tool using OAuth
|
||||
*
|
||||
|
@ -79,22 +79,5 @@ if ($ADMIN->fulltree) {
|
||||
|
||||
|
||||
$settings->add(new admin_setting_heading('blti_types', get_string('configuredtools', 'blti'), $str));
|
||||
|
||||
$unconfigured = blti_get_unconfigured_tools();
|
||||
if (!empty($unconfigured)) {
|
||||
$newstr = '<table>';
|
||||
$newstr .= '<tr> <th>Course</th> <th>Tool Name</th> </tr>';
|
||||
|
||||
foreach ($unconfigured as $unconf) {
|
||||
$coursename = $DB->get_field('course', 'shortname', array('id' => $unconf->course));
|
||||
$newstr .= '<tr>'.
|
||||
'<td>'.$coursename.'</td><td>'.$unconf->name.'</td>'.
|
||||
'<td align="center"><a class="editing_update" href="'.$CFG->wwwroot.'/mod/blti/typessettings.php?action=fix&id='.$unconf->id.'&sesskey='.$USER->sesskey.'" title="Fix">'.
|
||||
'<img class="iconsmall" alt="Update" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>'.' '.'</td>'.
|
||||
'</tr>';
|
||||
}
|
||||
$newstr .= '</table>';
|
||||
|
||||
$settings->add(new admin_setting_heading('blti_mis_types', get_string('misconfiguredtools', 'blti'), $newstr));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton
|
||||
$type = new StdClass();
|
||||
$type->name = $data->lti_typename;
|
||||
$type->baseurl = $data->lti_toolurl;
|
||||
$type->tooldomain = blti_get_domain_from_url($data->lti_toolurl);
|
||||
$type->course = $SITE->id;
|
||||
$type->coursevisible = 1;
|
||||
$type->timemodified = time();
|
||||
@ -86,7 +87,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton
|
||||
|
||||
if ($DB->update_record('blti_types', $type)) {
|
||||
unset ($data->lti_typename);
|
||||
//@TODO: update work
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (substr($key, 0, 4)=='lti_' && !is_null($value)) {
|
||||
$record = new StdClass();
|
||||
@ -107,14 +108,12 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton
|
||||
$type->createdby = $USER->id;
|
||||
$type->timecreated = time();
|
||||
|
||||
if ($id = $DB->insert_record('blti_types', $type)) {
|
||||
if (!empty($data->lti_fix)) {
|
||||
$instance = $DB->get_record('blti', array('id' => $data->lti_fix));
|
||||
$instance->typeid = $id;
|
||||
$DB->update_record('blti', $instance);
|
||||
}
|
||||
unset ($data->lti_fix);
|
||||
|
||||
//Create a salt value to be used for signing passed data to extension services
|
||||
$data->lti_servicesalt = uniqid('', true);
|
||||
|
||||
$id = $DB->insert_record('blti_types', $type);
|
||||
|
||||
if ($id) {
|
||||
unset ($data->lti_typename);
|
||||
foreach ($data as $key => $value) {
|
||||
if (substr($key, 0, 4)=='lti_' && !is_null($value)) {
|
||||
@ -135,18 +134,6 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton
|
||||
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingblti");
|
||||
die;
|
||||
}
|
||||
if (empty($adminroot->errors)) {
|
||||
switch ($return) {
|
||||
case 'site': redirect("$CFG->wwwroot/");
|
||||
case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
|
||||
}
|
||||
} else {
|
||||
$errormsg = get_string('errorwithsettings', 'admin');
|
||||
$firsterror = reset($adminroot->errors);
|
||||
$focus = $firsterror->id;
|
||||
}
|
||||
$adminroot =& admin_get_root(true); //reload tree
|
||||
$page =& $adminroot->locate($section);
|
||||
}
|
||||
|
||||
if ($action == 'delete') {
|
||||
@ -236,15 +223,6 @@ if (empty($SITE->fullname)) {
|
||||
$type = blti_get_type_type_config($id);
|
||||
$form->set_data($type);
|
||||
$form->display();
|
||||
} else if ($action == 'fix') {
|
||||
if (!isset($definenew) && !isset($useexisting)) {
|
||||
blti_fix_misconfigured_choice($id);
|
||||
} else if (isset($definenew)) {
|
||||
$form = new mod_blti_edit_types_form();
|
||||
$type = blti_get_type_config_from_instance($id);
|
||||
$form->set_data($type);
|
||||
$form->display();
|
||||
}
|
||||
}
|
||||
|
||||
echo $OUTPUT->box_end();
|
||||
|
@ -99,10 +99,6 @@ echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(format_string($basiclti->name));
|
||||
echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro');
|
||||
|
||||
if ($basiclti->typeid == 0) {
|
||||
print_error('errormisconfig', 'blti');
|
||||
}
|
||||
|
||||
if ($basiclti->instructorchoiceacceptgrades == 1) {
|
||||
echo '<div class="reportlink">'.submittedlink($cm).'</div>';
|
||||
}
|
||||
@ -110,7 +106,7 @@ if ($basiclti->instructorchoiceacceptgrades == 1) {
|
||||
echo $OUTPUT->box_start('generalbox activity');
|
||||
|
||||
|
||||
if ( $basiclti->launchinpopup > 0 ) {
|
||||
if ( false /*$basiclti->launchinpopup > 0*/ ) {
|
||||
print "<script language=\"javascript\">//<![CDATA[\n";
|
||||
print "window.open('launch.php?id=".$cm->id."','window name');";
|
||||
print "//]]\n";
|
||||
@ -118,10 +114,11 @@ if ( $basiclti->launchinpopup > 0 ) {
|
||||
print "<p>".get_string("basiclti_in_new_window", "blti")."</p>\n";
|
||||
} else {
|
||||
// Request the launch content with an object tag
|
||||
$height = $basiclti->preferheight;
|
||||
/*$height = $basiclti->preferheight;
|
||||
if ((!$height) || ($height == 0)) {
|
||||
$height = 400;
|
||||
}
|
||||
}*/
|
||||
$height=600;
|
||||
print '<object height="'.$height.'" width="100%" data="launch.php?id='.$cm->id.'&withobject=true"></object>';
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user