From 7023b65ef53d9210c879fd3c02789c232477f851 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Tue, 20 Sep 2011 11:23:32 -0400 Subject: [PATCH] Favor course tools over global tools --- mod/lti/locallib.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index 3dca134e163..ac025422c95 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -427,7 +427,7 @@ function lti_get_domain_from_url($url){ function lti_get_tool_by_url_match($url, $courseid = null, $state = LTI_TOOL_STATE_CONFIGURED){ $possibletools = lti_get_tools_by_url($url, $state, $courseid); - return lti_get_best_tool_by_url($url, $possibletools); + return lti_get_best_tool_by_url($url, $possibletools, $courseid); } function lti_get_url_thumbprint($url){ @@ -443,7 +443,7 @@ function lti_get_url_thumbprint($url){ return $urllower = $urlparts['host'] . '/' . $urlparts['path']; } -function lti_get_best_tool_by_url($url, $tools){ +function lti_get_best_tool_by_url($url, $tools, $courseid = null){ if(count($tools) === 0){ return null; } @@ -456,12 +456,20 @@ function lti_get_best_tool_by_url($url, $tools){ $toolbaseurllower = lti_get_url_thumbprint($tool->baseurl); if($urllower === $toolbaseurllower){ - //100 points for exact match + //100 points for exact thumbprint match $tool->_matchscore += 100; } else if(substr($urllower, 0, strlen($toolbaseurllower)) === $toolbaseurllower){ - //50 points if it starts with the base URL + //50 points if tool thumbprint starts with the base URL thumbprint $tool->_matchscore += 50; } + + //Prefer course tools over site tools + if(!empty($courseid)){ + //Minus 25 points for not matching the course id (global tools) + if($tool->course != $courseid){ + $tool->_matchscore -= 10; + } + } } $bestmatch = array_reduce($tools, function($value, $tool){ -- 2.36.1