Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented admin tool management

  • Loading branch information...
commit a4a07996f0fedc4d797c2f4b9e4492bcb9fcb14a 1 parent 7330033
@scriby scriby authored
View
4 mod/lti/edit_form.php
@@ -149,6 +149,10 @@ function definition() {
//-------------------------------------------------------------------------------
// Add a hidden element to signal a tool fixing operation after a problematic backup - restore process
$mform->addElement('hidden', 'lti_fix');
+
+ $tab = optional_param('tab', '', PARAM_ALPHAEXT);
+ $mform->addElement('hidden', 'tab', $tab);
+
//-------------------------------------------------------------------------------
// Add standard buttons, common to all modules
View
17 mod/lti/lang/en/lti.php
@@ -50,7 +50,7 @@
$string['activity'] = 'Activity';
$string['addnewapp'] = 'Enable External Application';
$string['addserver'] = 'Add new trusted server';
-$string['addtype'] = 'Create a new Basic LTI activity';
+$string['addtype'] = 'Add External Tool Configuration';
$string['allow'] = 'Allow';
$string['allowinstructorcustom'] = 'Allow instructors to add custom parameters';
$string['allowroster'] = 'Tool may access course roster';
@@ -75,7 +75,6 @@
$string['configresourceurl'] = 'Default Resource URL';
$string['configtoolurl'] = 'Default Remote Tool URL';
$string['configtypes'] = 'Enable Basic LTI Applications';
-$string['configuredtools'] = 'Configured Basic LTI activities';
$string['courseid'] = 'Course id number';
$string['coursemisconf'] = 'Course is misconfigured';
$string['curllibrarymissing'] = 'PHP Curl library must be installed to use LTI';
@@ -171,6 +170,20 @@
$string['embed_no_blocks'] = 'Embed, without blocks';
$string['new_window'] = 'New window';
$string['default_launch_container'] = 'Default Launch Container';
+$string['active'] = 'Active';
+$string['pending'] = 'Pending';
+$string['rejected'] = 'Rejected';
+$string['baseurl'] = 'Base URL';
+$string['action'] = 'Action';
+$string['createdon'] = 'Created On';
+$string['accept'] = 'Accept';
+$string['update'] = 'Update';
+$string['delete'] = 'Delete';
+$string['reject'] = 'Reject';
+$string['external_tool_types'] = 'External Tool Types';
+$string['no_lti_configured'] = 'There are no active External Tools configured.';
+$string['no_lti_pending'] = 'There are no pending External Tools.';
+$string['no_lti_external'] = 'There are no rejected External Tools.';
//New instructor strings
$string['display_name'] = 'Display activity name when launched';
View
22 mod/lti/locallib.php
@@ -56,6 +56,10 @@
define('LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS', 3);
define('LTI_LAUNCH_CONTAINER_WINDOW', 4);
+define('LTI_TOOL_STATE_CONFIGURED', 1);
+define('LTI_TOOL_STATE_PENDING', 2);
+define('LTI_TOOL_STATE_REJECTED', 3);
+
/**
* Prints a Basic LTI activity
*
@@ -302,7 +306,7 @@ function lti_get_type_config($typeid) {
function lti_get_tools_by_domain($domain){
global $DB;
- return $DB->get_records('lti_types', array('tooldomain' => $domain));
+ return $DB->get_records('lti_types', array('tooldomain' => $domain, 'state' => LTI_TOOL_STATE_CONFIGURED));
}
/**
@@ -416,16 +420,24 @@ function lti_filter_print_types() {
function lti_delete_type($id) {
global $DB;
+ //We should probably just copy the launch URL to the tool instances in this case... using a single query
+ /*
$instances = $DB->get_records('lti', array('typeid' => $id));
foreach ($instances as $instance) {
$instance->typeid = 0;
$DB->update_record('lti', $instance);
- }
+ }*/
$DB->delete_records('lti_types', array('id' => $id));
$DB->delete_records('lti_types_config', array('typeid' => $id));
}
+function lti_set_state_for_type($id, $state){
+ global $DB;
+
+ $DB->update_record('lti_types', array('id' => $id, 'state' => $state));
+}
+
/**
* Transforms a basic LTI object to an array
*
@@ -494,9 +506,9 @@ function lti_get_type_type_config($id) {
$config = lti_get_type_config($id);
$type->lti_typename = $basicltitype->name;
- if (isset($config['toolurl'])) {
- $type->lti_toolurl = $config['toolurl'];
- }
+
+ $type->lti_toolurl = $basicltitype->baseurl;
+
if (isset($config['resourcekey'])) {
$type->lti_resourcekey = $config['resourcekey'];
}
View
233 mod/lti/settings.php
@@ -47,37 +47,224 @@
defined('MOODLE_INTERNAL') || die;
+global $PAGE, $CFG;
+
+require_once($CFG->dirroot.'/mod/lti/locallib.php');
+
+function blti_get_tool_table($tools, $id){
+ global $CFG, $USER;
+ $html = '';
+
+ $typename = get_string('typename', 'lti');
+ $baseurl = get_string('baseurl', 'lti');
+ $action = get_string('action', 'lti');
+ $createdon = get_string('createdon', 'lti');
+
+ if (!empty($tools)) {
+ if($id == 'lti_configured'){
+ $html .= '<a style="margin-top:.25em" href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=add&amp;sesskey='.$USER->sesskey.'">'.get_string('addtype', 'lti').'</a>';
+ }
+
+ $html .= <<<HTML
+ <div id="{$id}_container" style="margin-top:.5em;margin-bottom:.5em">
+ <table id="{$id}_tools">
+ <thead>
+ <tr>
+ <th>$typename</th>
+ <th>$baseurl</th>
+ <th>$createdon</th>
+ <th>$action</th>
+ </tr>
+ </thead>
+HTML;
+
+ foreach ($tools as $type) {
+ $date = userdate($type->timecreated);
+ $accept = get_string('accept', 'lti');
+ $update = get_string('update', 'lti');
+ $delete = get_string('delete', 'lti');
+
+ $accepthtml = <<<HTML
+ <a class="editing_accept" href="{$CFG->wwwroot}/mod/lti/typessettings.php?action=accept&amp;id={$type->id}&amp;sesskey={$USER->sesskey}&amp;tab={$id}" title="{$accept}">
+ <img class="iconsmall" alt="{$accept}" src="{$CFG->wwwroot}/pix/t/clear.gif"/>
+ </a>
+HTML;
+
+ $deleteaction = 'delete';
+
+ if($type->state == LTI_TOOL_STATE_CONFIGURED){
+ $accepthtml = '';
+ }
+
+ if($type->state != LTI_TOOL_STATE_REJECTED) {
+ $deleteaction = 'reject';
+ $delete = get_string('reject', 'lti');
+ }
+
+ $html .= <<<HTML
+ <tr>
+ <td>
+ {$type->name}
+ </td>
+ <td>
+ {$type->baseurl}
+ </td>
+ <td>
+ {$date}
+ </td>
+ <td align="center">
+ {$accepthtml}
+ <a class="editing_update" href="{$CFG->wwwroot}/mod/lti/typessettings.php?action=update&amp;id={$type->id}&amp;sesskey={$USER->sesskey}&amp;tab={$id}" title="{$update}">
+ <img class="iconsmall" alt="{$update}" src="{$CFG->wwwroot}/pix/t/edit.gif"/>
+ </a>
+ <a class="editing_delete" href="{$CFG->wwwroot}/mod/lti/typessettings.php?action={$deleteaction}&amp;id={$type->id}&amp;sesskey={$USER->sesskey}&amp;tab={$id}" title="{$delete}">
+ <img class="iconsmall" alt="{$delete}" src="{$CFG->wwwroot}/pix/t/delete.gif"/>
+ </a>
+ </td>
+ </tr>
+HTML;
+ }
+ $html .= '</table></div>';
+ } else {
+ $html .= get_string('no_' . $id, 'lti');
+ }
+
+ return $html;
+}
+
if ($ADMIN->fulltree) {
require_once($CFG->dirroot.'/mod/lti/locallib.php');
- $str = '';
+ $configuredtoolshtml = '';
+ $pendingtoolshtml = '';
+ $rejectedtoolshtml = '';
+ $active = get_string('active', 'lti');
+ $pending = get_string('pending', 'lti');
+ $rejected = get_string('rejected', 'lti');
+ $typename = get_string('typename', 'lti');
+ $baseurl = get_string('baseurl', 'lti');
+ $action = get_string('action', 'lti');
+ $createdon = get_string('createdon', 'lti');
+
$types = lti_filter_get_types();
- if (!empty($types)) {
- $str .= '<h4 class="main"><a href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=add&amp;sesskey='.$USER->sesskey.'">'.get_string('addtype', 'lti').'</a></h4>';
- $str .= '<table>';
-
- foreach ($types as $type) {
- $str .= '<tr>'.
- '<td>'.$type->name.'</td>'.
- '<td align="center"><a class="editing_update" href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=update&amp;id='.$type->id.'&amp;sesskey='.$USER->sesskey.'" title="Update">'.
- '<img class="iconsmall" alt="Update" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>'.'&nbsp;&nbsp;'.
- '<a class="editing_delete" href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=delete&amp;id='.$type->id.'&amp;sesskey='.$USER->sesskey.'" title="Delete">'.
- '<img class="iconsmall" alt="Delete" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/>'.
- '</a>'.
- '</td>'.
- '</tr>';
+
+ $configuredtools = array_filter($types, function($value){
+ return $value->state == LTI_TOOL_STATE_CONFIGURED;
+ });
+
+ $configuredtoolshtml = blti_get_tool_table($configuredtools, 'lti_configured');
- }
- $str .= '</table>';
- } else {
- $str .= '<center>';
- $str .= '<h4 class="main"><a href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=add&amp;sesskey='.$USER->sesskey.'">'.get_string('addtype', 'lti').'</a></h4>';
- $str .= get_string('notypes', 'lti');
- $str .= '</center>';
+ $pendingtools = array_filter($types, function($value){
+ return $value->state == LTI_TOOL_STATE_PENDING;
+ });
+
+ $pendingtoolshtml = blti_get_tool_table($pendingtools, 'lti_pending');
+
+ $rejectedtools = array_filter($types, function($value){
+ return $value->state == LTI_TOOL_STATE_REJECTED;
+ });
+
+ $rejectedtoolshtml = blti_get_tool_table($rejectedtools, 'lti_rejected');
+
+ $tab = optional_param('tab', '', PARAM_ALPHAEXT);
+ $activeselected = '';
+ $pendingselected = '';
+ $rejectedselected = '';
+ switch($tab){
+ case 'lti_pending':
+ $pendingselected = 'class="selected"';
+ break;
+ case 'lti_rejected':
+ $rejectedselected = 'class="selected"';
+ break;
+ default:
+ $activeselected = 'class="selected"';
+ break;
}
+
+ $template = <<<HTML
+<div id="lti_tabs" class="yui-navset">
+ <ul id="lti_tab_heading" class="yui-nav" style="display:none">
+ <li {$activeselected}>
+ <a href="#tab1">
+ <em>$active</em>
+ </a>
+ </li>
+ <li {$pendingselected}>
+ <a href="#tab2">
+ <em>$pending</em>
+ </a>
+ </li>
+ <li {$rejectedselected}>
+ <a href="#tab3">
+ <em>$rejected</em>
+ </a>
+ </li>
+ </ul>
+ <div class="yui-content">
+ <div>
+ $configuredtoolshtml
+ </div>
+ <div>
+ $pendingtoolshtml
+ </div>
+ <div>
+ $rejectedtoolshtml
+ </div>
+ </div>
+</div>
+
+<script type='text/javascript'>
+//<![CDATA[
+ (function(){
+ //If javascript is disabled, they will just see the three tabs one after another
+ var lti_tab_heading = document.getElementById('lti_tab_heading');
+ lti_tab_heading.style.display = '';
+
+ new YAHOO.widget.TabView('lti_tabs');
+
+ var setupTools = function(id, sort){
+ var lti_tools = YAHOO.util.Dom.get(id + "_tools");
+
+ if(lti_tools){
+ var dataSource = new YAHOO.util.DataSource(lti_tools);
+
+ var configuredColumns = [
+ {key:"name", label:"$typename", sortable:true},
+ {key:"baseURL", label:"$baseurl", sortable:true},
+ {key:"timecreated", label:"$createdon", sortable:true, formatter:YAHOO.widget.DataTable.formatDate},
+ {key:"action", label:"$action"}
+ ];
+
+ dataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;
+ dataSource.responseSchema = {
+ fields: [
+ {key:"name"},
+ {key:"baseURL"},
+ {key:"timecreated", parser:"date"},
+ {key:"action"}
+ ]
+ };
+ new YAHOO.widget.DataTable(id + "_container", configuredColumns, dataSource,
+ {
+ sortedBy: sort
+ }
+ );
+ }
+ };
- $settings->add(new admin_setting_heading('lti_types', get_string('configuredtools', 'lti'), $str));
+ setupTools('lti_configured', {key:"name", dir:"asc"});
+ setupTools('lti_pending', {key:"timecreated", dir:"desc"});
+ setupTools('lti_rejected', {key:"timecreated", dir:"desc"});
+ })();
+//]]
+</script>
+HTML;
+ $PAGE->requires->yui2_lib('tabview');
+ $PAGE->requires->yui2_lib('datatable');
+
+ $settings->add(new admin_setting_heading('lti_types', get_string('external_tool_types', 'lti'), $template /* $str*/));
}
View
35 mod/lti/typessettings.php
@@ -67,13 +67,18 @@
admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page
+$tab = optional_param('tab', '', PARAM_ALPHAEXT);
+$redirect = "$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti&tab={$tab}";
+
/// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
$statusmsg = '';
$errormsg = '';
$focus = '';
-if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton)) {
+$data = data_submitted();
+
+if (confirm_sesskey() && isset($data->submitbutton)) {
$type = new StdClass();
$type->name = $data->lti_typename;
$type->baseurl = $data->lti_toolurl;
@@ -104,11 +109,12 @@
}
}
}
- redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti");
+ redirect($redirect);
die;
} else {
$type->createdby = $USER->id;
$type->timecreated = time();
+ $type->state = LTI_TOOL_STATE_CONFIGURED;
//Create a salt value to be used for signing passed data to extension services
$data->lti_servicesalt = uniqid('', true);
@@ -133,22 +139,29 @@
} else {
$errormsg = get_string('errorwithsettings', 'admin');
}
- redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti");
+ redirect($redirect);
die;
}
+} else if(isset($data->cancel)){
+ redirect($redirect);
+ die;
}
-if ($action == 'delete') {
- lti_delete_type($id);
- redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti");
+if ($action == 'accept') {
+ lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED);
+ redirect($redirect);
die;
}
-if (($action == 'fix') && isset($useexisting)) {
- $instance = $DB->get_record('lti', array('id' => $id));
- $instance->typeid = $useexisting;
- $DB->update_record('lti', $instance);
- redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti");
+if ($action == 'reject') {
+ lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED);
+ redirect($redirect);
+ die;
+}
+
+if ($action == 'delete') {
+ lti_delete_type($id);
+ redirect($redirect);
die;
}
View
6 mod/lti/view.php
@@ -92,8 +92,8 @@
$basiclti->launchcontainer;
if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){
- $PAGE->set_pagelayout('frametop'); //Use the frametop layout to get the navbar, but no footer
- $PAGE->blocks->show_only_fake_blocks(); //Disable 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 {
$PAGE->set_pagelayout('incourse');
}
@@ -159,7 +159,7 @@
setInterval(resize, 250);
})();
- //]]
+ //]]
</script>
SCRIPT;
Please sign in to comment.
Something went wrong with that request. Please try again.