MDL-20534 lti: A3, coding style + some scope, constructors
This commit is contained in:
committed by
Chris Scribner
parent
e27cb316aa
commit
ea04a9f989
+2
-2
@@ -34,13 +34,13 @@ $action = required_param('action', PARAM_TEXT);
|
||||
|
||||
$response = new stdClass();
|
||||
|
||||
switch($action){
|
||||
switch ($action) {
|
||||
case 'find_tool_config':
|
||||
$toolurl = required_param('toolurl', PARAM_RAW);
|
||||
|
||||
$tool = lti_get_tool_by_url_match($toolurl, $courseid);
|
||||
|
||||
if(!empty($tool)){
|
||||
if (!empty($tool)) {
|
||||
$response->toolid = $tool->id;
|
||||
$response->toolname = htmlspecialchars($tool->name);
|
||||
$response->tooldomain = htmlspecialchars($tool->tooldomain);
|
||||
|
||||
+2
-3
@@ -48,10 +48,9 @@
|
||||
|
||||
function basicltiDebugToggle() {
|
||||
var ele = document.getElementById('basicltiDebug');
|
||||
if(ele.style.display == 'block') {
|
||||
if (ele.style.display == 'block') {
|
||||
ele.style.display = 'none';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ele.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -52,17 +52,17 @@ defined('MOODLE_INTERNAL') || die;
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
require_once($CFG->dirroot.'/mod/lti/locallib.php');
|
||||
|
||||
class mod_lti_edit_types_form extends moodleform{
|
||||
function definition() {
|
||||
public class mod_lti_edit_types_form extends moodleform{
|
||||
public function definition() {
|
||||
$mform =& $this->_form;
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------
|
||||
// Add basiclti elements
|
||||
$mform->addElement('header', 'setup', get_string('tool_settings', 'lti'));
|
||||
|
||||
$mform->addElement('text', 'lti_typename', get_string('typename', 'lti'));
|
||||
$mform->setType('lti_typename', PARAM_INT);
|
||||
$mform->addHelpButton('lti_typename', 'typename','lti');
|
||||
$mform->addHelpButton('lti_typename', 'typename', 'lti');
|
||||
$mform->addRule('lti_typename', null, 'required', null, 'client');
|
||||
|
||||
$mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'lti'), array('size'=>'64'));
|
||||
@@ -82,7 +82,7 @@ class mod_lti_edit_types_form extends moodleform{
|
||||
$mform->setType('lti_customparameters', PARAM_TEXT);
|
||||
$mform->addHelpButton('lti_customparameters', 'custom', 'lti');
|
||||
|
||||
if(!empty($this->_customdata->isadmin)){
|
||||
if (!empty($this->_customdata->isadmin)) {
|
||||
$mform->addElement('checkbox', 'lti_coursevisible', ' ', ' ' . get_string('show_in_course', 'lti'));
|
||||
$mform->addHelpButton('lti_coursevisible', 'show_in_course', 'lti');
|
||||
} else {
|
||||
@@ -116,7 +116,7 @@ class mod_lti_edit_types_form extends moodleform{
|
||||
$mform->setDefault('lti_sendemailaddr', '2');
|
||||
$mform->addHelpButton('lti_sendemailaddr', 'share_email_admin', 'lti');
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------
|
||||
// LTI Extensions
|
||||
|
||||
// Add grading preferences fieldset where the tool is allowed to return grades
|
||||
@@ -129,11 +129,11 @@ class mod_lti_edit_types_form extends moodleform{
|
||||
$mform->setDefault('lti_allowroster', '2');
|
||||
$mform->addHelpButton('lti_allowroster', 'share_roster_admin', 'lti');
|
||||
|
||||
$mform->addElement('checkbox', 'lti_forcessl',' ', ' ' . get_string('force_ssl', 'lti'), $options);
|
||||
$mform->addElement('checkbox', 'lti_forcessl', ' ', ' ' . get_string('force_ssl', 'lti'), $options);
|
||||
$mform->setDefault('lti_forcessl', '0');
|
||||
$mform->addHelpButton('lti_forcessl', 'force_ssl', 'lti');
|
||||
|
||||
if(!empty($this->_customdata->isadmin)){
|
||||
if (!empty($this->_customdata->isadmin)) {
|
||||
//-------------------------------------------------------------------------------
|
||||
// Add setup parameters fieldset
|
||||
$mform->addElement('header', 'setupoptions', get_string('miscellaneous', 'lti'));
|
||||
@@ -158,7 +158,7 @@ class mod_lti_edit_types_form extends moodleform{
|
||||
$mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'lti');
|
||||
*/
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------
|
||||
// Add a hidden element to signal a tool fixing operation after a problematic backup - restore process
|
||||
//$mform->addElement('hidden', 'lti_fix');
|
||||
|
||||
@@ -168,7 +168,7 @@ class mod_lti_edit_types_form extends moodleform{
|
||||
$courseid = optional_param('course', 1, PARAM_INT);
|
||||
$mform->addElement('hidden', 'course', $courseid);
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------
|
||||
// Add standard buttons, common to all modules
|
||||
$this->add_action_buttons();
|
||||
|
||||
|
||||
+3
-3
@@ -154,11 +154,11 @@ HTML;
|
||||
|
||||
$rows = '';
|
||||
|
||||
foreach($submissions as $submission){
|
||||
foreach ($submissions as $submission) {
|
||||
$row = $rowtemplate;
|
||||
|
||||
foreach($submission as $key => $value){
|
||||
if($key === 'datesubmitted'){
|
||||
foreach ($submission as $key => $value) {
|
||||
if ($key === 'datesubmitted') {
|
||||
$value = userdate($value);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,9 @@ $typeid = optional_param('typeid', null, PARAM_INT);
|
||||
|
||||
require_capability('mod/lti:addcoursetool', get_context_instance(CONTEXT_COURSE, $courseid));
|
||||
|
||||
if(!empty($typeid)){
|
||||
if (!empty($typeid)) {
|
||||
$type = lti_get_type($typeid);
|
||||
if($type->course != $courseid){
|
||||
if ($type->course != $courseid) {
|
||||
throw new Exception('You do not have permissions to edit this tool type.');
|
||||
die;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ SCRIPT;
|
||||
|
||||
die;
|
||||
}
|
||||
} else if(isset($data->cancel)){
|
||||
} else if (isset($data->cancel)) {
|
||||
$script = <<<SCRIPT
|
||||
<script type="text/javascript">
|
||||
window.close();
|
||||
@@ -105,17 +105,17 @@ SCRIPT;
|
||||
}
|
||||
|
||||
//Delete action is called via ajax
|
||||
if ($action == 'delete'){
|
||||
if ($action == 'delete') {
|
||||
lti_delete_type($typeid);
|
||||
die;
|
||||
}
|
||||
|
||||
echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
|
||||
|
||||
if($action == 'add') {
|
||||
if ($action == 'add') {
|
||||
$form = new mod_lti_edit_types_form();
|
||||
$form->display();
|
||||
} else if($action == 'edit'){
|
||||
} else if ($action == 'edit') {
|
||||
$form = new mod_lti_edit_types_form();
|
||||
$type = lti_get_type_type_config($typeid);
|
||||
$form->set_data($type);
|
||||
|
||||
+8
-8
@@ -85,7 +85,7 @@ function lti_add_instance($formdata) {
|
||||
$formdata->timemodified = $formdata->timecreated;
|
||||
$formdata->servicesalt = uniqid('', true);
|
||||
|
||||
if(!isset($formdata->grade)){
|
||||
if (!isset($formdata->grade)) {
|
||||
$formdata->grade = 100;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ function lti_add_instance($formdata) {
|
||||
if ($formdata->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS) {
|
||||
$basiclti = $DB->get_record('lti', array('id'=>$id));
|
||||
|
||||
if(!isset($formdata->cmidnumber)){
|
||||
if (!isset($formdata->cmidnumber)) {
|
||||
$formdata->cmidnumber = '';
|
||||
}
|
||||
|
||||
@@ -120,11 +120,11 @@ function lti_update_instance($formdata) {
|
||||
$formdata->timemodified = time();
|
||||
$formdata->id = $formdata->instance;
|
||||
|
||||
if(!isset($formdata->showtitle)){
|
||||
if (!isset($formdata->showtitle)) {
|
||||
$formdata->showtitle = 0;
|
||||
}
|
||||
|
||||
if(!isset($formdata->showdescription)){
|
||||
if (!isset($formdata->showdescription)) {
|
||||
$formdata->showdescription = 0;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ function lti_delete_instance($id) {
|
||||
return $DB->delete_records("lti", array("id" => $basiclti->id));
|
||||
}
|
||||
|
||||
function lti_get_coursemodule_info($coursemodule){
|
||||
function lti_get_coursemodule_info($coursemodule) {
|
||||
global $DB;
|
||||
|
||||
$lti = $DB->get_record('lti', array('id' => $coursemodule->instance), 'icon, secureicon');
|
||||
@@ -172,10 +172,10 @@ function lti_get_coursemodule_info($coursemodule){
|
||||
|
||||
//We want to use the right icon based on whether the current page is being requested over http or https.
|
||||
//There's a potential problem here as the icon URLs are cached in the modinfo field and won't be updated for each request.
|
||||
if(lti_request_is_using_ssl() && !empty($lti->secureicon)){
|
||||
if (lti_request_is_using_ssl() && !empty($lti->secureicon)) {
|
||||
$info->icon = $lti->secureicon;
|
||||
} else {
|
||||
if(!empty($lti->icon)){
|
||||
if (!empty($lti->icon)) {
|
||||
$info->icon = $lti->icon;
|
||||
}
|
||||
}
|
||||
@@ -390,7 +390,7 @@ function lti_grade_item_delete($basiclti) {
|
||||
function lti_extend_settings_navigation($settings, $parentnode) {
|
||||
global $PAGE;
|
||||
|
||||
if(has_capability('mod/lti:grade', get_context_instance(CONTEXT_MODULE, $PAGE->cm->id))){
|
||||
if (has_capability('mod/lti:grade', get_context_instance(CONTEXT_MODULE, $PAGE->cm->id))) {
|
||||
$keys = $parentnode->get_children_key_list();
|
||||
|
||||
$node = navigation_node::create('Submissions',
|
||||
|
||||
@@ -55,7 +55,7 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
*
|
||||
* @TODO: finish doc this class and it's functions
|
||||
*/
|
||||
class admin_setting_ltimodule_configlink extends admin_setting {
|
||||
public class admin_setting_ltimodule_configlink extends admin_setting {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -63,19 +63,19 @@ class admin_setting_ltimodule_configlink extends admin_setting {
|
||||
* @param string $visiblename localised
|
||||
* @param string $description long localised info
|
||||
*/
|
||||
function admin_setting_ltimodule_configlink($name, $visiblename, $description) {
|
||||
public function __construct($name, $visiblename, $description) {
|
||||
parent::__construct($name, $visiblename, $description, '');
|
||||
}
|
||||
|
||||
function get_setting() {
|
||||
public function get_setting() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function write_setting($data) {
|
||||
public function write_setting($data) {
|
||||
return "";
|
||||
}
|
||||
|
||||
function output_html($data, $query='') {
|
||||
public function output_html($data, $query='') {
|
||||
global $CFG;
|
||||
return format_admin_setting($this, "",
|
||||
'<div class="defaultsnext" >'.
|
||||
|
||||
+82
-83
@@ -77,9 +77,9 @@ define('LTI_SETTING_DELEGATE', 2);
|
||||
function lti_view($instance) {
|
||||
global $PAGE, $CFG;
|
||||
|
||||
if(empty($instance->typeid)){
|
||||
if (empty($instance->typeid)) {
|
||||
$tool = lti_get_tool_by_url_match($instance->toolurl, $instance->course);
|
||||
if($tool){
|
||||
if ($tool) {
|
||||
$typeid = $tool->id;
|
||||
} else {
|
||||
$typeid = null;
|
||||
@@ -88,7 +88,7 @@ function lti_view($instance) {
|
||||
$typeid = $instance->typeid;
|
||||
}
|
||||
|
||||
if($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.
|
||||
@@ -103,23 +103,23 @@ function lti_view($instance) {
|
||||
}
|
||||
|
||||
//Default the organizationid if not specified
|
||||
if(empty($typeconfig['organizationid'])){
|
||||
if (empty($typeconfig['organizationid'])) {
|
||||
$urlparts = parse_url($CFG->wwwroot);
|
||||
|
||||
$typeconfig['organizationid'] = $urlparts['host'];
|
||||
}
|
||||
|
||||
if(!empty($instance->resourcekey)){
|
||||
if (!empty($instance->resourcekey)) {
|
||||
$key = $instance->resourcekey;
|
||||
} else if(!empty($typeconfig['resourcekey'])){
|
||||
} else if (!empty($typeconfig['resourcekey'])) {
|
||||
$key = $typeconfig['resourcekey'];
|
||||
} else {
|
||||
$key = '';
|
||||
}
|
||||
|
||||
if(!empty($instance->password)){
|
||||
if (!empty($instance->password)) {
|
||||
$secret = $instance->password;
|
||||
} else if(!empty($typeconfig['password'])){
|
||||
} else if (!empty($typeconfig['password'])) {
|
||||
$secret = $typeconfig['password'];
|
||||
} else {
|
||||
$secret = '';
|
||||
@@ -129,19 +129,19 @@ function lti_view($instance) {
|
||||
$endpoint = trim($endpoint);
|
||||
|
||||
//If the current request is using SSL and a secure tool URL is specified, use it
|
||||
if(lti_request_is_using_ssl() && !empty($instance->securetoolurl)){
|
||||
if (lti_request_is_using_ssl() && !empty($instance->securetoolurl)) {
|
||||
$endpoint = trim($instance->securetoolurl);
|
||||
}
|
||||
|
||||
//If SSL is forced, use the secure tool url if specified. Otherwise, make sure https is on the normal launch URL.
|
||||
if($typeconfig['forcessl'] == '1'){
|
||||
if(!empty($instance->securetoolurl)){
|
||||
if ($typeconfig['forcessl'] == '1') {
|
||||
if (!empty($instance->securetoolurl)) {
|
||||
$endpoint = trim($instance->securetoolurl);
|
||||
}
|
||||
|
||||
$endpoint = lti_ensure_url_is_https($endpoint);
|
||||
} else {
|
||||
if(!strstr($endpoint, '://')){
|
||||
if (!strstr($endpoint, '://')) {
|
||||
$endpoint = 'http://' . $endpoint;
|
||||
}
|
||||
}
|
||||
@@ -158,21 +158,21 @@ function lti_view($instance) {
|
||||
$requestparams["tool_consumer_instance_guid"] = $orgid;
|
||||
}
|
||||
|
||||
if(empty($key) || empty($secret)){
|
||||
if (empty($key) || empty($secret)) {
|
||||
$returnurlparams['unsigned'] = '1';
|
||||
|
||||
//Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns
|
||||
$url = new moodle_url('/mod/lti/return.php', $returnurlparams);
|
||||
$returnurl = $url->out(false);
|
||||
|
||||
if($typeconfig['forcessl'] == '1'){
|
||||
if ($typeconfig['forcessl'] == '1') {
|
||||
$returnurl = lti_ensure_url_is_https($returnurl);
|
||||
}
|
||||
|
||||
$requestparams['launch_presentation_return_url'] = $returnurl;
|
||||
}
|
||||
|
||||
if(!empty($key) && !empty($secret)){
|
||||
if (!empty($key) && !empty($secret)) {
|
||||
$parms = lti_sign_parameters($requestparams, $endpoint, "POST", $key, $secret);
|
||||
} else {
|
||||
//If no key and secret, do the launch unsigned.
|
||||
@@ -186,12 +186,12 @@ function lti_view($instance) {
|
||||
echo $content;
|
||||
}
|
||||
|
||||
function lti_build_sourcedid($instanceid, $userid, $launchid = null, $servicesalt){
|
||||
function lti_build_sourcedid($instanceid, $userid, $launchid = null, $servicesalt) {
|
||||
$data = new stdClass();
|
||||
|
||||
$data->instanceid = $instanceid;
|
||||
$data->userid = $userid;
|
||||
if(!empty($launchid)){
|
||||
if (!empty($launchid)) {
|
||||
$data->launchid = $launchid;
|
||||
} else {
|
||||
$data->launchid = mt_rand();
|
||||
@@ -220,7 +220,7 @@ function lti_build_sourcedid($instanceid, $userid, $launchid = null, $servicesal
|
||||
function lti_build_request($instance, $typeconfig, $course) {
|
||||
global $USER, $CFG;
|
||||
|
||||
if(empty($instance->cmid)){
|
||||
if (empty($instance->cmid)) {
|
||||
$instance->cmid = 0;
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ function lti_build_request($instance, $typeconfig, $course) {
|
||||
$requestparams["lis_result_sourcedid"] = $sourcedid;
|
||||
|
||||
$serviceurl = $CFG->wwwroot . '/mod/lti/service.php';
|
||||
if($typeconfig['forcessl'] == '1'){
|
||||
if ($typeconfig['forcessl'] == '1') {
|
||||
$serviceurl = lti_ensure_url_is_https($serviceurl);
|
||||
}
|
||||
|
||||
@@ -303,9 +303,8 @@ function lti_build_request($instance, $typeconfig, $course) {
|
||||
$instructorcustom = lti_split_custom_parameters($instructorcustomstr);
|
||||
}
|
||||
foreach ($instructorcustom as $key => $val) {
|
||||
if (array_key_exists($key, $custom)) {
|
||||
// Ignore the instructor's parameter
|
||||
} else {
|
||||
// Ignore the instructor's parameter
|
||||
if (!array_key_exists($key, $custom)) {
|
||||
$custom[$key] = $val;
|
||||
}
|
||||
}
|
||||
@@ -332,7 +331,7 @@ function lti_build_request($instance, $typeconfig, $course) {
|
||||
return $requestparams;
|
||||
}
|
||||
|
||||
function lti_get_tool_table($tools, $id){
|
||||
function lti_get_tool_table($tools, $id) {
|
||||
global $CFG, $USER;
|
||||
$html = '';
|
||||
|
||||
@@ -341,7 +340,7 @@ function lti_get_tool_table($tools, $id){
|
||||
$action = get_string('action', 'lti');
|
||||
$createdon = get_string('createdon', 'lti');
|
||||
|
||||
if($id == 'lti_configured'){
|
||||
if ($id == 'lti_configured') {
|
||||
$html .= '<div><a style="margin-top:.25em" href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=add&sesskey='.$USER->sesskey.'">'.get_string('addtype', 'lti').'</a></div>';
|
||||
}
|
||||
|
||||
@@ -373,11 +372,11 @@ HTML;
|
||||
|
||||
$deleteaction = 'delete';
|
||||
|
||||
if($type->state == LTI_TOOL_STATE_CONFIGURED){
|
||||
if ($type->state == LTI_TOOL_STATE_CONFIGURED) {
|
||||
$accepthtml = '';
|
||||
}
|
||||
|
||||
if($type->state != LTI_TOOL_STATE_REJECTED) {
|
||||
if ($type->state != LTI_TOOL_STATE_REJECTED) {
|
||||
$deleteaction = 'reject';
|
||||
$delete = get_string('reject', 'lti');
|
||||
}
|
||||
@@ -470,13 +469,13 @@ function lti_map_keyname($key) {
|
||||
function lti_get_ims_role($user, $cmid, $courseid) {
|
||||
$roles = array();
|
||||
|
||||
if(empty($cmid)){
|
||||
if (empty($cmid)) {
|
||||
//If no cmid is passed, check if the user is a teacher in the course
|
||||
//This allows other modules to programmatically "fake" a launch without
|
||||
//a real LTI instance
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
|
||||
if(has_capability('moodle/course:manageactivities', $coursecontext)){
|
||||
if (has_capability('moodle/course:manageactivities', $coursecontext)) {
|
||||
array_push($roles, 'Instructor');
|
||||
} else {
|
||||
array_push($roles, 'Learner');
|
||||
@@ -484,14 +483,14 @@ function lti_get_ims_role($user, $cmid, $courseid) {
|
||||
} else {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
||||
|
||||
if(has_capability('mod/lti:manage', $context)){
|
||||
if (has_capability('mod/lti:manage', $context)) {
|
||||
array_push($roles, 'Instructor');
|
||||
} else {
|
||||
array_push($roles, 'Learner');
|
||||
}
|
||||
}
|
||||
|
||||
if(is_siteadmin($user)){
|
||||
if (is_siteadmin($user)) {
|
||||
array_push($roles, 'urn:lti:sysrole:ims/lis/Administrator');
|
||||
}
|
||||
|
||||
@@ -532,13 +531,13 @@ QUERY;
|
||||
return $typeconfig;
|
||||
}
|
||||
|
||||
function lti_get_tools_by_url($url, $state, $courseid = null){
|
||||
function lti_get_tools_by_url($url, $state, $courseid = null) {
|
||||
$domain = lti_get_domain_from_url($url);
|
||||
|
||||
return lti_get_tools_by_domain($domain, $state, $courseid);
|
||||
}
|
||||
|
||||
function lti_get_tools_by_domain($domain, $state = null, $courseid = null){
|
||||
function lti_get_tools_by_domain($domain, $state = null, $courseid = null) {
|
||||
global $DB, $SITE;
|
||||
|
||||
$filters = array('tooldomain' => $domain);
|
||||
@@ -546,11 +545,11 @@ function lti_get_tools_by_domain($domain, $state = null, $courseid = null){
|
||||
$statefilter = '';
|
||||
$coursefilter = '';
|
||||
|
||||
if($state){
|
||||
if ($state) {
|
||||
$statefilter = 'AND state = :state';
|
||||
}
|
||||
|
||||
if($courseid && $courseid != $SITE->id){
|
||||
if ($courseid && $courseid != $SITE->id) {
|
||||
$coursefilter = 'OR course = :courseid';
|
||||
}
|
||||
|
||||
@@ -577,7 +576,7 @@ QUERY;
|
||||
function lti_filter_get_types($course) {
|
||||
global $DB;
|
||||
|
||||
if(!empty($course)){
|
||||
if (!empty($course)) {
|
||||
$filter = array('course' => $course);
|
||||
} else {
|
||||
$filter = array();
|
||||
@@ -586,7 +585,7 @@ function lti_filter_get_types($course) {
|
||||
return $DB->get_records('lti_types', $filter);
|
||||
}
|
||||
|
||||
function lti_get_types_for_add_instance(){
|
||||
function lti_get_types_for_add_instance() {
|
||||
global $DB, $SITE, $COURSE;
|
||||
|
||||
$query = <<<QUERY
|
||||
@@ -603,75 +602,75 @@ QUERY;
|
||||
$types = array();
|
||||
$types[0] = (object)array('name' => get_string('automatic', 'lti'), 'course' => $SITE->id);
|
||||
|
||||
foreach($admintypes as $type) {
|
||||
foreach ($admintypes as $type) {
|
||||
$types[$type->id] = $type;
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
function lti_get_domain_from_url($url){
|
||||
function lti_get_domain_from_url($url) {
|
||||
$matches = array();
|
||||
|
||||
if(preg_match(LTI_URL_DOMAIN_REGEX, $url, $matches)){
|
||||
if (preg_match(LTI_URL_DOMAIN_REGEX, $url, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
function lti_get_tool_by_url_match($url, $courseid = null, $state = LTI_TOOL_STATE_CONFIGURED){
|
||||
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, $courseid);
|
||||
}
|
||||
|
||||
function lti_get_url_thumbprint($url){
|
||||
function lti_get_url_thumbprint($url) {
|
||||
$urlparts = parse_url(strtolower($url));
|
||||
if(!isset($urlparts['path'])){
|
||||
if (!isset($urlparts['path'])) {
|
||||
$urlparts['path'] = '';
|
||||
}
|
||||
|
||||
if(!isset($urlparts['host'])){
|
||||
if (!isset($urlparts['host'])) {
|
||||
$urlparts['host'] = '';
|
||||
}
|
||||
|
||||
if(substr($urlparts['host'], 0, 4) === 'www.'){
|
||||
if (substr($urlparts['host'], 0, 4) === 'www.') {
|
||||
$urlparts['host'] = substr($urlparts['host'], 4);
|
||||
}
|
||||
|
||||
return $urllower = $urlparts['host'] . '/' . $urlparts['path'];
|
||||
}
|
||||
|
||||
function lti_get_best_tool_by_url($url, $tools, $courseid = null){
|
||||
if(count($tools) === 0){
|
||||
function lti_get_best_tool_by_url($url, $tools, $courseid = null) {
|
||||
if (count($tools) === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$urllower = lti_get_url_thumbprint($url);
|
||||
|
||||
foreach($tools as $tool){
|
||||
foreach ($tools as $tool) {
|
||||
$tool->_matchscore = 0;
|
||||
|
||||
$toolbaseurllower = lti_get_url_thumbprint($tool->baseurl);
|
||||
|
||||
if($urllower === $toolbaseurllower){
|
||||
if ($urllower === $toolbaseurllower) {
|
||||
//100 points for exact thumbprint match
|
||||
$tool->_matchscore += 100;
|
||||
} else if(substr($urllower, 0, strlen($toolbaseurllower)) === $toolbaseurllower){
|
||||
} else if (substr($urllower, 0, strlen($toolbaseurllower)) === $toolbaseurllower) {
|
||||
//50 points if tool thumbprint starts with the base URL thumbprint
|
||||
$tool->_matchscore += 50;
|
||||
}
|
||||
|
||||
//Prefer course tools over site tools
|
||||
if(!empty($courseid)){
|
||||
if (!empty($courseid)) {
|
||||
//Minus 25 points for not matching the course id (global tools)
|
||||
if($tool->course != $courseid){
|
||||
if ($tool->course != $courseid) {
|
||||
$tool->_matchscore -= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$bestmatch = array_reduce($tools, function($value, $tool){
|
||||
if($tool->_matchscore > $value->_matchscore){
|
||||
$bestmatch = array_reduce($tools, function($value, $tool) {
|
||||
if ($tool->_matchscore > $value->_matchscore) {
|
||||
return $tool;
|
||||
} else {
|
||||
return $value;
|
||||
@@ -680,14 +679,14 @@ function lti_get_best_tool_by_url($url, $tools, $courseid = null){
|
||||
}, (object)array('_matchscore' => -1));
|
||||
|
||||
//None of the tools are suitable for this URL
|
||||
if($bestmatch->_matchscore <= 0){
|
||||
if ($bestmatch->_matchscore <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $bestmatch;
|
||||
}
|
||||
|
||||
function lti_get_shared_secrets_by_key($key){
|
||||
function lti_get_shared_secrets_by_key($key) {
|
||||
global $DB;
|
||||
|
||||
//Look up the shared secret for the specified key in both the types_config table (for configured tools)
|
||||
@@ -712,7 +711,7 @@ QUERY;
|
||||
|
||||
$sharedsecrets = $DB->get_records_sql($query, array('configured' => LTI_TOOL_STATE_CONFIGURED, 'key1' => $key, 'key2' => $key));
|
||||
|
||||
$values = array_map(function($item){
|
||||
$values = array_map(function($item) {
|
||||
return $item->value;
|
||||
}, $sharedsecrets);
|
||||
|
||||
@@ -773,7 +772,7 @@ function lti_delete_type($id) {
|
||||
$DB->delete_records('lti_types_config', array('typeid' => $id));
|
||||
}
|
||||
|
||||
function lti_set_state_for_type($id, $state){
|
||||
function lti_set_state_for_type($id, $state) {
|
||||
global $DB;
|
||||
|
||||
$DB->update_record('lti_types', array('id' => $id, 'state' => $state));
|
||||
@@ -862,25 +861,25 @@ function lti_get_type_type_config($id) {
|
||||
if (isset($config['sendname'])) {
|
||||
$type->lti_sendname = $config['sendname'];
|
||||
}
|
||||
if (isset($config['instructorchoicesendname'])){
|
||||
if (isset($config['instructorchoicesendname'])) {
|
||||
$type->lti_instructorchoicesendname = $config['instructorchoicesendname'];
|
||||
}
|
||||
if (isset($config['sendemailaddr'])){
|
||||
if (isset($config['sendemailaddr'])) {
|
||||
$type->lti_sendemailaddr = $config['sendemailaddr'];
|
||||
}
|
||||
if (isset($config['instructorchoicesendemailaddr'])){
|
||||
if (isset($config['instructorchoicesendemailaddr'])) {
|
||||
$type->lti_instructorchoicesendemailaddr = $config['instructorchoicesendemailaddr'];
|
||||
}
|
||||
if (isset($config['acceptgrades'])){
|
||||
if (isset($config['acceptgrades'])) {
|
||||
$type->lti_acceptgrades = $config['acceptgrades'];
|
||||
}
|
||||
if (isset($config['instructorchoiceacceptgrades'])){
|
||||
if (isset($config['instructorchoiceacceptgrades'])) {
|
||||
$type->lti_instructorchoiceacceptgrades = $config['instructorchoiceacceptgrades'];
|
||||
}
|
||||
if (isset($config['allowroster'])){
|
||||
if (isset($config['allowroster'])) {
|
||||
$type->lti_allowroster = $config['allowroster'];
|
||||
}
|
||||
if (isset($config['instructorchoiceallowroster'])){
|
||||
if (isset($config['instructorchoiceallowroster'])) {
|
||||
$type->lti_instructorchoiceallowroster = $config['instructorchoiceallowroster'];
|
||||
}
|
||||
|
||||
@@ -888,7 +887,7 @@ function lti_get_type_type_config($id) {
|
||||
$type->lti_customparameters = $config['customparameters'];
|
||||
}
|
||||
|
||||
if(isset($config['forcessl'])){
|
||||
if (isset($config['forcessl'])) {
|
||||
$type->lti_forcessl = $config['forcessl'];
|
||||
}
|
||||
|
||||
@@ -920,7 +919,7 @@ function lti_get_type_type_config($id) {
|
||||
return $type;
|
||||
}
|
||||
|
||||
function lti_prepare_type_for_save($type, $config){
|
||||
function lti_prepare_type_for_save($type, $config) {
|
||||
$type->baseurl = $config->lti_toolurl;
|
||||
$type->tooldomain = lti_get_domain_from_url($config->lti_toolurl);
|
||||
$type->name = $config->lti_typename;
|
||||
@@ -937,7 +936,7 @@ function lti_prepare_type_for_save($type, $config){
|
||||
unset ($config->lti_toolurl);
|
||||
}
|
||||
|
||||
function lti_update_type($type, $config){
|
||||
function lti_update_type($type, $config) {
|
||||
global $DB;
|
||||
|
||||
lti_prepare_type_for_save($type, $config);
|
||||
@@ -956,24 +955,24 @@ function lti_update_type($type, $config){
|
||||
}
|
||||
}
|
||||
|
||||
function lti_add_type($type, $config){
|
||||
function lti_add_type($type, $config) {
|
||||
global $USER, $SITE, $DB;
|
||||
|
||||
lti_prepare_type_for_save($type, $config);
|
||||
|
||||
if(!isset($type->state)){
|
||||
if (!isset($type->state)) {
|
||||
$type->state = LTI_TOOL_STATE_PENDING;
|
||||
}
|
||||
|
||||
if(!isset($type->timecreated)){
|
||||
if (!isset($type->timecreated)) {
|
||||
$type->timecreated = time();
|
||||
}
|
||||
|
||||
if(!isset($type->createdby)){
|
||||
if (!isset($type->createdby)) {
|
||||
$type->createdby = $USER->id;
|
||||
}
|
||||
|
||||
if(!isset($type->course)){
|
||||
if (!isset($type->course)) {
|
||||
$type->course = $SITE->id;
|
||||
}
|
||||
|
||||
@@ -1101,7 +1100,7 @@ function lti_post_launch_html($newparms, $endpoint, $debug=false) {
|
||||
$r .= " //<![CDATA[ \n";
|
||||
$r .= "function basicltiDebugToggle() {\n";
|
||||
$r .= " var ele = document.getElementById(\"basicltiDebug\");\n";
|
||||
$r .= " if(ele.style.display == \"block\") {\n";
|
||||
$r .= " if (ele.style.display == \"block\") {\n";
|
||||
$r .= " ele.style.display = \"none\";\n";
|
||||
$r .= " }\n";
|
||||
$r .= " else {\n";
|
||||
@@ -1145,26 +1144,26 @@ function lti_post_launch_html($newparms, $endpoint, $debug=false) {
|
||||
return $r;
|
||||
}
|
||||
|
||||
function lti_get_type($typeid){
|
||||
function lti_get_type($typeid) {
|
||||
global $DB;
|
||||
|
||||
return $DB->get_record('lti_types', array('id' => $typeid));
|
||||
}
|
||||
|
||||
function lti_get_launch_container($lti, $toolconfig){
|
||||
if(empty($lti->launchcontainer)){
|
||||
function lti_get_launch_container($lti, $toolconfig) {
|
||||
if (empty($lti->launchcontainer)) {
|
||||
$lti->launchcontainer = LTI_LAUNCH_CONTAINER_DEFAULT;
|
||||
}
|
||||
|
||||
if($lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT){
|
||||
if(isset($toolconfig['launchcontainer'])){
|
||||
if ($lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT) {
|
||||
if (isset($toolconfig['launchcontainer'])) {
|
||||
$launchcontainer = $toolconfig['launchcontainer'];
|
||||
}
|
||||
} else {
|
||||
$launchcontainer = $lti->launchcontainer;
|
||||
}
|
||||
|
||||
if(empty($launchcontainer) || $launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT){
|
||||
if (empty($launchcontainer) || $launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT) {
|
||||
$launchcontainer = LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS;
|
||||
}
|
||||
|
||||
@@ -1173,7 +1172,7 @@ function lti_get_launch_container($lti, $toolconfig){
|
||||
//Scrolling within the object element doesn't work on iOS or Android
|
||||
//Opening the popup window also had some issues in testing
|
||||
//For mobile devices, always take up the entire screen to ensure the best experience
|
||||
if($devicetype === 'mobile' || $devicetype === 'tablet' ){
|
||||
if ($devicetype === 'mobile' || $devicetype === 'tablet' ) {
|
||||
$launchcontainer = LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW;
|
||||
}
|
||||
|
||||
@@ -1185,12 +1184,12 @@ function lti_request_is_using_ssl() {
|
||||
return (stripos($ME, 'https://') === 0);
|
||||
}
|
||||
|
||||
function lti_ensure_url_is_https($url){
|
||||
if(!strstr($url, '://')){
|
||||
function lti_ensure_url_is_https($url) {
|
||||
if (!strstr($url, '://')) {
|
||||
$url = 'https://' . $url;
|
||||
} else {
|
||||
//If the URL starts with http, replace with https
|
||||
if(stripos($url, 'http://') === 0){
|
||||
if (stripos($url, 'http://') === 0) {
|
||||
$url = 'https://' . substr($url, 8);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-18
@@ -51,22 +51,22 @@ defined('MOODLE_INTERNAL') || die;
|
||||
require_once($CFG->dirroot.'/course/moodleform_mod.php');
|
||||
require_once($CFG->dirroot.'/mod/lti/locallib.php');
|
||||
|
||||
class mod_lti_mod_form extends moodleform_mod {
|
||||
public class mod_lti_mod_form extends moodleform_mod {
|
||||
|
||||
function definition() {
|
||||
public function definition() {
|
||||
global $DB, $PAGE, $OUTPUT, $USER, $COURSE;
|
||||
|
||||
$this->typeid = 0;
|
||||
|
||||
$mform =& $this->_form;
|
||||
//-------------------------------------------------------------------------------
|
||||
/// Adding the "general" fieldset, where all the common settings are shown
|
||||
//-------------------------------------------------------------------------------
|
||||
// Adding the "general" fieldset, where all the common settings are shown
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
/// Adding the standard "name" field
|
||||
// Adding the standard "name" field
|
||||
$mform->addElement('text', 'name', get_string('basicltiname', 'lti'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
/// Adding the optional "intro" and "introformat" pair of fields
|
||||
// Adding the optional "intro" and "introformat" pair of fields
|
||||
$this->add_intro_editor(false, get_string('basicltiintro', 'lti'));
|
||||
$mform->setAdvanced('introeditor');
|
||||
|
||||
@@ -78,14 +78,14 @@ class mod_lti_mod_form extends moodleform_mod {
|
||||
$mform->setAdvanced('showdescription');
|
||||
$mform->addHelpButton('showdescription', 'display_description', 'lti');
|
||||
|
||||
//Tool settings
|
||||
// Tool settings
|
||||
$tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array());
|
||||
$mform->addHelpButton('typeid', 'external_tool_type', 'lti');
|
||||
|
||||
foreach(lti_get_types_for_add_instance() as $id => $type){
|
||||
if($type->course == $COURSE->id) {
|
||||
foreach (lti_get_types_for_add_instance() as $id => $type) {
|
||||
if ($type->course == $COURSE->id) {
|
||||
$attributes = array( 'editable' => 1, 'courseTool' => 1, 'domain' => $type->tooldomain );
|
||||
} else if($id != 0) {
|
||||
} else if ($id != 0) {
|
||||
$attributes = array( 'globalTool' => 1, 'domain' => $type->tooldomain);
|
||||
} else {
|
||||
$attributes = array();
|
||||
@@ -138,7 +138,7 @@ class mod_lti_mod_form extends moodleform_mod {
|
||||
$mform->setAdvanced('secureicon');
|
||||
$mform->addHelpButton('secureicon', 'secure_icon_url', 'lti');
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------
|
||||
// Add privacy preferences fieldset where users choose whether to send their data
|
||||
$mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
|
||||
|
||||
@@ -158,9 +158,10 @@ class mod_lti_mod_form extends moodleform_mod {
|
||||
$mform->setDefault('instructorchoiceallowroster', '1');
|
||||
$mform->addHelpButton('instructorchoiceallowroster', 'share_roster', 'lti');
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------
|
||||
|
||||
/* $debugoptions=array();
|
||||
/**
|
||||
$debugoptions=array();
|
||||
$debugoptions[0] = get_string('debuglaunchoff', 'lti');
|
||||
$debugoptions[1] = get_string('debuglaunchon', 'lti');
|
||||
|
||||
@@ -173,13 +174,13 @@ class mod_lti_mod_form extends moodleform_mod {
|
||||
$mform->setDefault('debuglaunch', '1');
|
||||
}
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------
|
||||
// add standard elements, common to all modules
|
||||
$this->standard_coursemodule_elements();
|
||||
$mform->setAdvanced('cmidnumber');
|
||||
//-------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------
|
||||
// add standard buttons, common to all modules
|
||||
$this->add_action_buttons();
|
||||
|
||||
@@ -224,7 +225,7 @@ class mod_lti_mod_form extends moodleform_mod {
|
||||
* Make fields editable or non-editable depending on the administrator choices
|
||||
* @see moodleform_mod::definition_after_data()
|
||||
*/
|
||||
function definition_after_data() {
|
||||
public function definition_after_data() {
|
||||
parent::definition_after_data();
|
||||
|
||||
//$mform =& $this->_form;
|
||||
@@ -236,7 +237,7 @@ class mod_lti_mod_form extends moodleform_mod {
|
||||
*
|
||||
* @param array $default_values passed by reference
|
||||
*/
|
||||
function data_preprocessing(&$default_values) {
|
||||
protected function data_preprocessing(&$default_values) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ $PAGE->set_pagelayout('incourse');
|
||||
echo $OUTPUT->header();
|
||||
|
||||
//Add a tool type if one does not exist already
|
||||
if(!lti_get_tool_by_url_match($lti->toolurl, $lti->course, LTI_TOOL_STATE_ANY)){
|
||||
if (!lti_get_tool_by_url_match($lti->toolurl, $lti->course, LTI_TOOL_STATE_ANY)) {
|
||||
//There are no tools (active, pending, or rejected) for the launch URL. Create a new pending tool
|
||||
$tooltype = new stdClass();
|
||||
$toolconfig = new stdClass();
|
||||
|
||||
+4
-4
@@ -38,7 +38,7 @@ $course = $DB->get_record('course', array('id' => $courseid));
|
||||
|
||||
require_login($course);
|
||||
|
||||
if(!empty($errormsg)){
|
||||
if (!empty($errormsg)) {
|
||||
$url = new moodle_url('/mod/lti/return.php', array('course' => $courseid));
|
||||
$PAGE->set_url($url);
|
||||
|
||||
@@ -47,7 +47,7 @@ if(!empty($errormsg)){
|
||||
$PAGE->set_heading($course->fullname);
|
||||
|
||||
//Avoid frame-in-frame action
|
||||
if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
|
||||
if ($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
|
||||
$PAGE->set_pagelayout('embedded');
|
||||
} else {
|
||||
$PAGE->set_pagelayout('incourse');
|
||||
@@ -61,7 +61,7 @@ if(!empty($errormsg)){
|
||||
|
||||
$canaddtools = has_capability('mod/lti:addcoursetool', get_context_instance(CONTEXT_COURSE, $courseid));
|
||||
|
||||
if($unsigned == 1 && $canaddtools){
|
||||
if ($unsigned == 1 && $canaddtools) {
|
||||
echo '<br /><br />';
|
||||
|
||||
$links = new stdClass();
|
||||
@@ -82,7 +82,7 @@ if(!empty($errormsg)){
|
||||
$url = $courseurl->out();
|
||||
|
||||
//Avoid frame-in-frame action
|
||||
if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
|
||||
if ($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
|
||||
//Output a page containing some script to break out of frames and redirect them
|
||||
|
||||
echo '<html><body>';
|
||||
|
||||
+8
-10
@@ -31,8 +31,8 @@ use moodle\mod\lti as lti;
|
||||
|
||||
$rawbody = file_get_contents("php://input");
|
||||
|
||||
foreach(getallheaders() as $name => $value){
|
||||
if($name === 'Authorization'){
|
||||
foreach (getallheaders() as $name => $value) {
|
||||
if ($name === 'Authorization') {
|
||||
$oauthparams = lti\OAuthUtil::split_header($value);
|
||||
|
||||
$consumerkey = $oauthparams['oauth_consumer_key'];
|
||||
@@ -40,24 +40,24 @@ foreach(getallheaders() as $name => $value){
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($consumerkey)){
|
||||
if (empty($consumerkey)) {
|
||||
throw new Exception('Consumer key is missing.');
|
||||
}
|
||||
|
||||
$sharedsecret = lti_verify_message($consumerkey, lti_get_shared_secrets_by_key($consumerkey), $rawbody);
|
||||
|
||||
if($sharedsecret === false){
|
||||
if ($sharedsecret === false) {
|
||||
throw new Exception('Message signature not valid');
|
||||
}
|
||||
|
||||
$xml = new SimpleXMLElement($rawbody);
|
||||
|
||||
$body = $xml->imsx_POXBody;
|
||||
foreach($body->children() as $child){
|
||||
foreach ($body->children() as $child) {
|
||||
$messagetype = $child->getName();
|
||||
}
|
||||
|
||||
switch($messagetype){
|
||||
switch ($messagetype) {
|
||||
case 'replaceResultRequest':
|
||||
$parsed = lti_parse_grade_replace_message($xml);
|
||||
|
||||
@@ -99,9 +99,7 @@ switch($messagetype){
|
||||
);
|
||||
|
||||
$node = $responsexml->imsx_POXBody->readResultResponse;
|
||||
$node->addChild('result')
|
||||
->addChild('resultScore')
|
||||
->addChild('textString', isset($grade) ? $grade : '');
|
||||
$node->addChild('result')->addChild('resultScore')->addChild('textString', isset($grade) ? $grade : '');
|
||||
|
||||
echo $responsexml->asXML();
|
||||
|
||||
@@ -145,7 +143,7 @@ switch($messagetype){
|
||||
|
||||
events_trigger('lti_unknown_service_api_call', $data);
|
||||
|
||||
if(!$lti_web_service_handled){
|
||||
if (!$lti_web_service_handled) {
|
||||
$responsexml = lti_get_response_xml(
|
||||
'unsupported',
|
||||
'unsupported',
|
||||
|
||||
+20
-25
@@ -31,12 +31,11 @@ define('LTI_ITEM_TYPE', 'mod');
|
||||
define('LTI_ITEM_MODULE', 'lti');
|
||||
define('LTI_SOURCE', 'mod/lti');
|
||||
|
||||
function lti_get_response_xml($codemajor, $description, $messageref, $messagetype){
|
||||
function lti_get_response_xml($codemajor, $description, $messageref, $messagetype) {
|
||||
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><imsx_POXEnvelopeResponse />');
|
||||
$xml->addAttribute('xmlns', 'http://www.imsglobal.org/lis/oms1p0/pox');
|
||||
|
||||
$headerinfo = $xml->addChild('imsx_POXHeader')
|
||||
->addChild('imsx_POXResponseHeaderInfo');
|
||||
$headerinfo = $xml->addChild('imsx_POXHeader')->addChild('imsx_POXResponseHeaderInfo');
|
||||
|
||||
$headerinfo->addChild('imsx_version', 'V1.0');
|
||||
$headerinfo->addChild('imsx_messageIdentifier', (string)mt_rand());
|
||||
@@ -47,20 +46,19 @@ function lti_get_response_xml($codemajor, $description, $messageref, $messagetyp
|
||||
$statusinfo->addChild('imsx_description', $description);
|
||||
$statusinfo->addChild('imsx_messageRefIdentifier', $messageref);
|
||||
|
||||
$xml->addChild('imsx_POXBody')
|
||||
->addChild($messagetype);
|
||||
$xml->addChild('imsx_POXBody')->addChild($messagetype);
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
function lti_parse_message_id($xml){
|
||||
function lti_parse_message_id($xml) {
|
||||
$node = $xml->imsx_POXHeader->imsx_POXRequestHeaderInfo->imsx_messageIdentifier;
|
||||
$messageid = (string)$node;
|
||||
|
||||
return $messageid;
|
||||
}
|
||||
|
||||
function lti_parse_grade_replace_message($xml){
|
||||
function lti_parse_grade_replace_message($xml) {
|
||||
$node = $xml->imsx_POXBody->replaceResultRequest->resultRecord->sourcedGUID->sourcedId;
|
||||
$resultjson = json_decode((string)$node);
|
||||
|
||||
@@ -80,7 +78,7 @@ function lti_parse_grade_replace_message($xml){
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
function lti_parse_grade_read_message($xml){
|
||||
function lti_parse_grade_read_message($xml) {
|
||||
$node = $xml->imsx_POXBody->readResultRequest->resultRecord->sourcedGUID->sourcedId;
|
||||
$resultjson = json_decode((string)$node);
|
||||
|
||||
@@ -95,7 +93,7 @@ function lti_parse_grade_read_message($xml){
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
function lti_parse_grade_delete_message($xml){
|
||||
function lti_parse_grade_delete_message($xml) {
|
||||
$node = $xml->imsx_POXBody->deleteResultRequest->resultRecord->sourcedGUID->sourcedId;
|
||||
$resultjson = json_decode((string)$node);
|
||||
|
||||
@@ -110,7 +108,7 @@ function lti_parse_grade_delete_message($xml){
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
function lti_update_grade($ltiinstance, $userid, $launchid, $gradeval){
|
||||
function lti_update_grade($ltiinstance, $userid, $launchid, $gradeval) {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->libdir . '/gradelib.php');
|
||||
|
||||
@@ -124,13 +122,13 @@ function lti_update_grade($ltiinstance, $userid, $launchid, $gradeval){
|
||||
$status = grade_update(LTI_SOURCE, $ltiinstance->course, LTI_ITEM_TYPE, LTI_ITEM_MODULE, $ltiinstance->id, 0, $grade, $params);
|
||||
|
||||
$record = $DB->get_record('lti_submission', array('ltiid' => $ltiinstance->id, 'userid' => $userid, 'launchid' => $launchid), 'id');
|
||||
if($record){
|
||||
if ($record) {
|
||||
$id = $record->id;
|
||||
} else {
|
||||
$id = null;
|
||||
}
|
||||
|
||||
if(!empty($id)){
|
||||
if (!empty($id)) {
|
||||
$DB->update_record('lti_submission', array(
|
||||
'id' => $id,
|
||||
'dateupdated' => time(),
|
||||
@@ -153,7 +151,7 @@ function lti_update_grade($ltiinstance, $userid, $launchid, $gradeval){
|
||||
return $status == GRADE_UPDATE_OK;
|
||||
}
|
||||
|
||||
function lti_read_grade($ltiinstance, $userid){
|
||||
function lti_read_grade($ltiinstance, $userid) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/gradelib.php');
|
||||
|
||||
@@ -166,12 +164,12 @@ function lti_read_grade($ltiinstance, $userid){
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($grade)){
|
||||
if (isset($grade)) {
|
||||
return $grade;
|
||||
}
|
||||
}
|
||||
|
||||
function lti_delete_grade($ltiinstance, $userid){
|
||||
function lti_delete_grade($ltiinstance, $userid) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/gradelib.php');
|
||||
|
||||
@@ -184,18 +182,17 @@ function lti_delete_grade($ltiinstance, $userid){
|
||||
return $status == GRADE_UPDATE_OK || $status == GRADE_UPDATE_ITEM_DELETED; //grade_update seems to return ok now, but could reasonably return deleted in the future
|
||||
}
|
||||
|
||||
function lti_verify_message($key, $sharedsecrets, $body, $headers = null){
|
||||
foreach($sharedsecrets as $secret){
|
||||
function lti_verify_message($key, $sharedsecrets, $body, $headers = null) {
|
||||
foreach ($sharedsecrets as $secret) {
|
||||
$signaturefailed = false;
|
||||
|
||||
try{
|
||||
try {
|
||||
lti\handleOAuthBodyPOST($key, $secret, $body, $headers);
|
||||
}
|
||||
catch(Exception $e){
|
||||
} catch (Exception $e) {
|
||||
$signaturefailed = true;
|
||||
}
|
||||
|
||||
if(!$signaturefailed){
|
||||
if (!$signaturefailed) {
|
||||
return $secret;//Return the secret used to sign the message)
|
||||
}
|
||||
}
|
||||
@@ -203,12 +200,10 @@ function lti_verify_message($key, $sharedsecrets, $body, $headers = null){
|
||||
return false;
|
||||
}
|
||||
|
||||
function lti_verify_sourcedid($ltiinstance, $parsed){
|
||||
function lti_verify_sourcedid($ltiinstance, $parsed) {
|
||||
$sourceid = lti_build_sourcedid($parsed->instanceid, $parsed->userid, $parsed->launchid, $ltiinstance->servicesalt);
|
||||
|
||||
if($sourceid->hash != $parsed->sourcedidhash){
|
||||
if ($sourceid->hash != $parsed->sourcedidhash) {
|
||||
throw new Exception('SourcedId hash not valid');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -67,19 +67,19 @@ if ($ADMIN->fulltree) {
|
||||
|
||||
$types = lti_filter_get_types($SITE->id);
|
||||
|
||||
$configuredtools = array_filter($types, function($value){
|
||||
$configuredtools = array_filter($types, function($value) {
|
||||
return $value->state == LTI_TOOL_STATE_CONFIGURED;
|
||||
});
|
||||
|
||||
$configuredtoolshtml = lti_get_tool_table($configuredtools, 'lti_configured');
|
||||
|
||||
$pendingtools = array_filter($types, function($value){
|
||||
$pendingtools = array_filter($types, function($value) {
|
||||
return $value->state == LTI_TOOL_STATE_PENDING;
|
||||
});
|
||||
|
||||
$pendingtoolshtml = lti_get_tool_table($pendingtools, 'lti_pending');
|
||||
|
||||
$rejectedtools = array_filter($types, function($value){
|
||||
$rejectedtools = array_filter($types, function($value) {
|
||||
return $value->state == LTI_TOOL_STATE_REJECTED;
|
||||
});
|
||||
|
||||
@@ -89,7 +89,7 @@ if ($ADMIN->fulltree) {
|
||||
$activeselected = '';
|
||||
$pendingselected = '';
|
||||
$rejectedselected = '';
|
||||
switch($tab){
|
||||
switch ($tab) {
|
||||
case 'lti_pending':
|
||||
$pendingselected = 'class="selected"';
|
||||
break;
|
||||
|
||||
@@ -57,7 +57,7 @@ require_once($CFG->dirroot . '/mod/lti/servicelib.php');
|
||||
class lti_locallib_test extends UnitTestCase {
|
||||
public static $includecoverage = array('mod/lti/locallib.php');
|
||||
|
||||
function test_split_custom_parameters() {
|
||||
public function test_split_custom_parameters() {
|
||||
$this->assertEqual(lti_split_custom_parameters("x=1\ny=2"),
|
||||
array('custom_x' => '1', 'custom_y'=> '2'));
|
||||
|
||||
@@ -71,7 +71,7 @@ class lti_locallib_test extends UnitTestCase {
|
||||
array('custom_complex____________key' => 'Complex!@#$^*(){}[]Value'));
|
||||
}
|
||||
|
||||
function test_sign_parameters() {
|
||||
public function test_sign_parameters() {
|
||||
$correct = array ( 'context_id' => '12345', 'context_label' => 'SI124', 'context_title' => 'Social Computing', 'ext_submit' => 'Click Me', 'lti_message_type' => 'basic-lti-launch-request', 'lti_version' => 'LTI-1p0', 'oauth_consumer_key' => 'lmsng.school.edu', 'oauth_nonce' => '47458148e33a8f9dafb888c3684cf476', 'oauth_signature' => 'qWgaBIezihCbeHgcwUy14tZcyDQ=', 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => '1307141660', 'oauth_version' => '1.0', 'resource_link_id' => '123', 'resource_link_title' => 'Weekly Blog', 'roles' => 'Learner', 'tool_consumer_instance_guid' => 'lmsng.school.edu', 'user_id' => '789');
|
||||
|
||||
$requestparams = array('resource_link_id' => '123', 'resource_link_title' => 'Weekly Blog', 'user_id' => '789', 'roles' => 'Learner', 'context_id' => '12345', 'context_label' => 'SI124', 'context_title' => 'Social Computing');
|
||||
@@ -91,7 +91,7 @@ class lti_locallib_test extends UnitTestCase {
|
||||
$this->assertEqual($parms, $correct);
|
||||
}
|
||||
|
||||
function test_parse_grade_replace_message(){
|
||||
public function test_parse_grade_replace_message() {
|
||||
$message = <<<XML
|
||||
<imsx_POXEnvelopeRequest xmlns = "http://www.imsglobal.org/lis/oms1p0/pox">
|
||||
<imsx_POXHeader>
|
||||
|
||||
@@ -33,5 +33,3 @@
|
||||
|
||||
/* Styles for instructor_edit_tool_type.php */
|
||||
#page-mod-lti-instructor_edit_tool_type .mform .fitem .fitemtitle { min-width:18em;padding-right:1em } /* Prevent setting titles from wrapping */
|
||||
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@
|
||||
}
|
||||
|
||||
this.setupTable();
|
||||
|
||||
|
||||
},
|
||||
|
||||
setupTable: function(){
|
||||
|
||||
@@ -96,7 +96,7 @@ if (confirm_sesskey() && isset($data->submitbutton)) {
|
||||
redirect($redirect);
|
||||
die;
|
||||
}
|
||||
} else if(isset($data->cancel)){
|
||||
} else if (isset($data->cancel)) {
|
||||
redirect($redirect);
|
||||
die;
|
||||
}
|
||||
|
||||
+5
-5
@@ -79,7 +79,7 @@ if ($id) {
|
||||
}
|
||||
|
||||
$tool = lti_get_tool_by_url_match($basiclti->toolurl);
|
||||
if($tool){
|
||||
if ($tool) {
|
||||
$toolconfig = lti_get_type_config($tool->id);
|
||||
} else {
|
||||
$toolconfig = array();
|
||||
@@ -94,10 +94,10 @@ $PAGE->set_url($url);
|
||||
|
||||
$launchcontainer = lti_get_launch_container($basiclti, $toolconfig);
|
||||
|
||||
if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){
|
||||
if ($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
|
||||
$PAGE->set_pagelayout('frametop'); //Most frametops don't include footer, and pre-post blocks
|
||||
$PAGE->blocks->show_only_fake_blocks(); //Disable blocks for layouts which do include pre-post blocks
|
||||
} else if($launchcontainer == LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW) {
|
||||
} else if ($launchcontainer == LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW) {
|
||||
redirect('launch.php?id=' . $cm->id);
|
||||
} else {
|
||||
$PAGE->set_pagelayout('incourse');
|
||||
@@ -114,12 +114,12 @@ $PAGE->set_heading($course->fullname);
|
||||
/// Print the page header
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if($basiclti->showtitle) {
|
||||
if ($basiclti->showtitle) {
|
||||
/// Print the main part of the page
|
||||
echo $OUTPUT->heading(format_string($basiclti->name));
|
||||
}
|
||||
|
||||
if($basiclti->showdescription && $basiclti->intro){
|
||||
if ($basiclti->showdescription && $basiclti->intro) {
|
||||
echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user