$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);
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';
}
}
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'));
$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 {
$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
$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'));
$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');
$courseid = optional_param('course', 1, PARAM_INT);
$mform->addElement('hidden', 'course', $courseid);
-//-------------------------------------------------------------------------------
+ //-------------------------------------------------------------------------------
// Add standard buttons, common to all modules
$this->add_action_buttons();
$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);
}
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;
}
die;
}
-} else if(isset($data->cancel)){
+} else if (isset($data->cancel)) {
$script = <<<SCRIPT
<script type="text/javascript">
window.close();
}
//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);
$formdata->timemodified = $formdata->timecreated;
$formdata->servicesalt = uniqid('', true);
- if(!isset($formdata->grade)){
+ if (!isset($formdata->grade)) {
$formdata->grade = 100;
}
if ($formdata->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS) {
$basiclti = $DB->get_record('lti', array('id'=>$id));
- if(!isset($formdata->cmidnumber)){
+ if (!isset($formdata->cmidnumber)) {
$formdata->cmidnumber = '';
}
$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;
}
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');
//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;
}
}
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',
*
* @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
* @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" >'.
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;
$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.
}
//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 = '';
$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;
}
}
$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.
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();
function lti_build_request($instance, $typeconfig, $course) {
global $USER, $CFG;
- if(empty($instance->cmid)){
+ if (empty($instance->cmid)) {
$instance->cmid = 0;
}
$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);
}
$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;
}
}
return $requestparams;
}
-function lti_get_tool_table($tools, $id){
+function lti_get_tool_table($tools, $id) {
global $CFG, $USER;
$html = '';
$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>';
}
$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');
}
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');
} 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');
}
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);
$statefilter = '';
$coursefilter = '';
- if($state){
+ if ($state) {
$statefilter = 'AND state = :state';
}
- if($courseid && $courseid != $SITE->id){
+ if ($courseid && $courseid != $SITE->id) {
$coursefilter = 'OR course = :courseid';
}
function lti_filter_get_types($course) {
global $DB;
- if(!empty($course)){
+ if (!empty($course)) {
$filter = array('course' => $course);
} else {
$filter = array();
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
$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;
}, (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)
$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);
$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));
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'];
}
$type->lti_customparameters = $config['customparameters'];
}
- if(isset($config['forcessl'])){
+ if (isset($config['forcessl'])) {
$type->lti_forcessl = $config['forcessl'];
}
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;
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);
}
}
-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;
}
$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";
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;
}
//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;
}
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);
}
}
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');
$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();
$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'));
$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');
$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();
* 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;
*
* @param array $default_values passed by reference
*/
- function data_preprocessing(&$default_values) {
+ protected function data_preprocessing(&$default_values) {
}
}
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();
require_login($course);
-if(!empty($errormsg)){
+if (!empty($errormsg)) {
$url = new moodle_url('/mod/lti/return.php', array('course' => $courseid));
$PAGE->set_url($url);
$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');
$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();
$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>';
$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'];
}
}
-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);
);
$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();
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',
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());
$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);
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);
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);
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');
$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(),
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');
}
}
- 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');
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)
}
}
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');
}
}
-
-?>
$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;
});
$activeselected = '';
$pendingselected = '';
$rejectedselected = '';
- switch($tab){
+ switch ($tab) {
case 'lti_pending':
$pendingselected = 'class="selected"';
break;
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'));
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');
$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>
/* 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 */
-
-
}
this.setupTable();
-
-
},
setupTable: function(){
redirect($redirect);
die;
}
-} else if(isset($data->cancel)){
+} else if (isset($data->cancel)) {
redirect($redirect);
die;
}
}
$tool = lti_get_tool_by_url_match($basiclti->toolurl);
-if($tool){
+if ($tool) {
$toolconfig = lti_get_type_config($tool->id);
} else {
$toolconfig = array();
$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');
/// 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');
}