Permalink
Browse files

Implemented admin tool management

  • Loading branch information...
1 parent 7330033 commit a4a07996f0fedc4d797c2f4b9e4492bcb9fcb14a @scriby scriby committed Aug 31, 2011
Showing with 273 additions and 44 deletions.
  1. +4 −0 mod/lti/edit_form.php
  2. +15 −2 mod/lti/lang/en/lti.php
  3. +17 −5 mod/lti/locallib.php
  4. +210 −23 mod/lti/settings.php
  5. +24 −11 mod/lti/typessettings.php
  6. +3 −3 mod/lti/view.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
@@ -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
@@ -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
@@ -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*/));
}
Oops, something went wrong. Retry.

0 comments on commit a4a0799

Please sign in to comment.