mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Fixing issues with launching a tool which is not configured in the admin side, and improving utility methods for determing if a tool should be registered
This commit is contained in:
parent
f5134df434
commit
a0eeacf9c7
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="mod/lti/db" VERSION="20110829" COMMENT="XMLDB file for Moodle mod/lti"
|
||||
<XMLDB PATH="mod/lti/db" VERSION="20110901" COMMENT="XMLDB file for Moodle mod/lti"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@ -22,10 +22,13 @@
|
||||
<FIELD NAME="instructorcustomparameters" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Additional custom parameters provided by the instructor" PREVIOUS="instructorchoiceallowsetting" NEXT="instructorchoiceacceptgrades"/>
|
||||
<FIELD NAME="instructorchoiceacceptgrades" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Accept grades from tool" PREVIOUS="instructorcustomparameters" NEXT="grade"/>
|
||||
<FIELD NAME="grade" TYPE="number" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="100" SEQUENCE="false" DECIMALS="5" COMMENT="Grade scale" PREVIOUS="instructorchoiceacceptgrades" NEXT="launchcontainer"/>
|
||||
<FIELD NAME="launchcontainer" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" COMMENT="Launch external tool in a pop-up" PREVIOUS="grade" NEXT="debuglaunch"/>
|
||||
<FIELD NAME="debuglaunch" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Enable the debug-style launch which pauses before auto-submit" PREVIOUS="launchcontainer" NEXT="showtitle"/>
|
||||
<FIELD NAME="launchcontainer" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" COMMENT="Launch external tool in a pop-up" PREVIOUS="grade" NEXT="resourcekey"/>
|
||||
<FIELD NAME="resourcekey" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="launchcontainer" NEXT="password"/>
|
||||
<FIELD NAME="password" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="resourcekey" NEXT="debuglaunch"/>
|
||||
<FIELD NAME="debuglaunch" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Enable the debug-style launch which pauses before auto-submit" PREVIOUS="password" NEXT="showtitle"/>
|
||||
<FIELD NAME="showtitle" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="debuglaunch" NEXT="showdescription"/>
|
||||
<FIELD NAME="showdescription" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="showtitle"/>
|
||||
<FIELD NAME="showdescription" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="showtitle" NEXT="servicesalt"/>
|
||||
<FIELD NAME="servicesalt" TYPE="char" LENGTH="40" NOTNULL="false" SEQUENCE="false" PREVIOUS="showdescription"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
@ -42,7 +45,7 @@
|
||||
<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" DEFAULT="0" PREVIOUS="course" NEXT="createdby"/>
|
||||
<FIELD NAME="coursevisible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="course" NEXT="createdby"/>
|
||||
<FIELD NAME="createdby" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="coursevisible" NEXT="timecreated"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="createdby" NEXT="timemodified"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="timecreated"/>
|
||||
|
@ -60,26 +60,47 @@ define('LTI_TOOL_STATE_CONFIGURED', 1);
|
||||
define('LTI_TOOL_STATE_PENDING', 2);
|
||||
define('LTI_TOOL_STATE_REJECTED', 3);
|
||||
|
||||
define('LTI_SETTING_NEVER', 0);
|
||||
define('LTI_SETTING_ALWAYS', 1);
|
||||
define('LTI_SETTING_DEFAULT', 2);
|
||||
|
||||
/**
|
||||
* Prints a Basic LTI activity
|
||||
*
|
||||
* $param int $basicltiid Basic LTI activity id
|
||||
*/
|
||||
function lti_view($instance, $makeobject=false) {
|
||||
global $PAGE;
|
||||
global $PAGE, $CFG;
|
||||
|
||||
if(empty($instance->typeid)){
|
||||
$tool = lti_get_tool_by_url_match($instance->toolurl);
|
||||
if($tool){
|
||||
$typeid = $tool->id;
|
||||
} else {
|
||||
//Tool not found
|
||||
$typeid = null;
|
||||
}
|
||||
} else {
|
||||
$typeid = $instance->typeid;
|
||||
}
|
||||
|
||||
$typeconfig = lti_get_type_config($typeid);
|
||||
if($typeid){
|
||||
$typeconfig = lti_get_type_config($typeid);
|
||||
} else {
|
||||
//There is no admin configuration for this tool. Use configuration in the lti instance record plus some defaults.
|
||||
$typeconfig = (array)$instance;
|
||||
|
||||
$typeconfig['sendname'] = $instance->instructorchoicesendname;
|
||||
$typeconfig['sendemailaddr'] = $instance->instructorchoicesendemailaddr;
|
||||
$typeconfig['customparameters'] = $instance->instructorcustomparameters;
|
||||
}
|
||||
|
||||
//Default the organizationid if not specified
|
||||
if(empty($typeconfig['organizationid'])){
|
||||
$urlparts = parse_url($CFG->wwwroot);
|
||||
|
||||
$typeconfig['organizationid'] = $urlparts['host'];
|
||||
}
|
||||
|
||||
$endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl'];
|
||||
$key = !empty($instance->resourcekey) ? $instance->resourcekey : $typeconfig['resourcekey'];
|
||||
$secret = !empty($instance->password) ? $instance->password : $typeconfig['password'];
|
||||
@ -104,8 +125,6 @@ function lti_view($instance, $makeobject=false) {
|
||||
|
||||
$content = post_launch_html($parms, $endpoint, $debuglaunch);
|
||||
|
||||
// $cm = get_coursemodule_from_instance("lti", $instance->id);
|
||||
// print '<object height='.$height.' width="80%" data="launch.php?id='.$cm->id.'">'.$content.'</object>';
|
||||
echo $content;
|
||||
}
|
||||
|
||||
@ -303,10 +322,42 @@ function lti_get_type_config($typeid) {
|
||||
return $typeconfig;
|
||||
}
|
||||
|
||||
function lti_get_tools_by_domain($domain){
|
||||
global $DB;
|
||||
function lti_get_tools_by_url($url, $state){
|
||||
$domain = lti_get_domain_from_url($url);
|
||||
|
||||
return $DB->get_records('lti_types', array('tooldomain' => $domain, 'state' => LTI_TOOL_STATE_CONFIGURED));
|
||||
return lti_get_tools_by_domain($domain, $state);
|
||||
}
|
||||
|
||||
function lti_get_tools_by_domain($domain, $state = null, $courseid = null){
|
||||
global $DB, $SITE;
|
||||
|
||||
$filters = array('tooldomain' => $domain);
|
||||
|
||||
$statefilter = '';
|
||||
$coursefilter = '';
|
||||
|
||||
if($state){
|
||||
$statefilter = 'AND state = :state';
|
||||
}
|
||||
|
||||
if($courseid && $courseid != $SITE->id){
|
||||
$coursefilter = 'OR course = :courseid';
|
||||
}
|
||||
|
||||
$query = <<<QUERY
|
||||
SELECT * FROM {lti_types}
|
||||
WHERE
|
||||
tooldomain = :tooldomain
|
||||
AND (course = :siteid $coursefilter)
|
||||
$statefilter
|
||||
QUERY;
|
||||
|
||||
return $DB->get_records_sql($query, array(
|
||||
'courseid' => $courseid,
|
||||
'siteid' => $SITE->id,
|
||||
'tooldomain' => $domain,
|
||||
'state' => $state
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -341,29 +392,42 @@ function lti_get_domain_from_url($url){
|
||||
}
|
||||
}
|
||||
|
||||
function lti_get_tool_by_url_match($url){
|
||||
$domain = lti_get_domain_from_url($url);
|
||||
|
||||
$possibletools = lti_get_tools_by_domain($domain);
|
||||
function lti_get_tool_by_url_match($url, $courseid = null){
|
||||
$possibletools = lti_get_tools_by_url($url, LTI_TOOL_STATE_CONFIGURED, $courseid);
|
||||
|
||||
return lti_get_best_tool_by_url($url, $possibletools);
|
||||
}
|
||||
|
||||
function lti_get_url_thumbprint($url){
|
||||
$urlparts = parse_url(strtolower($url));
|
||||
if(!isset($urlparts['path'])){
|
||||
$urlparts['path'] = '';
|
||||
}
|
||||
|
||||
if(substr($urlparts['host'], 0, 3) === 'www'){
|
||||
$urllparts['host'] = substr(3);
|
||||
}
|
||||
|
||||
return $urllower = $urlparts['host'] . '/' . $urlparts['path'];
|
||||
}
|
||||
|
||||
function lti_get_best_tool_by_url($url, $tools){
|
||||
if(count($tools) === 0){
|
||||
return null;
|
||||
}
|
||||
|
||||
$urllower = strtolower($url);
|
||||
$urllower = lti_get_url_thumbprint($url);
|
||||
|
||||
foreach($tools as $tool){
|
||||
$tool->_matchscore = 0;
|
||||
|
||||
$toolbaseurllower = strtolower($tool->baseurl);
|
||||
|
||||
$toolbaseurllower = lti_get_url_thumbprint($tool->baseurl);
|
||||
|
||||
if($urllower === $toolbaseurllower){
|
||||
//100 points for exact match
|
||||
$tool->_matchscore += 100;
|
||||
} else if(strstr($urllower, $toolbaseurllower) >= 0){
|
||||
} else if(substr($urllower, 0, strlen($toolbaseurllower)) === $toolbaseurllower){
|
||||
//50 points if it starts with the base URL
|
||||
$tool->_matchscore += 50;
|
||||
}
|
||||
}
|
||||
@ -377,6 +441,11 @@ function lti_get_best_tool_by_url($url, $tools){
|
||||
|
||||
}, (object)array('_matchscore' => -1));
|
||||
|
||||
//None of the tools are suitable for this URL
|
||||
if($bestmatch->_matchscore <= 0){
|
||||
return null;
|
||||
}
|
||||
|
||||
return $bestmatch;
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,11 @@ if ($id) {
|
||||
}
|
||||
|
||||
$tool = lti_get_tool_by_url_match($basiclti->toolurl);
|
||||
$toolconfig = lti_get_type_config($tool->id);
|
||||
if($tool){
|
||||
$toolconfig = lti_get_type_config($tool->id);
|
||||
} else {
|
||||
$toolconfig = array('launchcontainer' => LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS);
|
||||
}
|
||||
|
||||
$PAGE->set_cm($cm, $course); // set's up global $COURSE
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user