Permalink
Browse files

Some code cleaning

  • Loading branch information...
1 parent 531737a commit 8c8420c67a78e0ce55546b6cb6ceb841969451c1 @jleyva committed Jan 9, 2012
Showing with 230 additions and 173 deletions.
  1. +66 −9 README.txt
  2. +5 −5 db/access.php
  3. +28 −28 db/install.xml
  4. +8 −10 edit.php
  5. +30 −30 edit_form.php
  6. +10 −12 index.php
  7. +49 −43 lib.php
  8. +2 −2 styles.php
  9. +29 −33 tool.php
  10. +3 −1 version.php
View
75 README.txt
@@ -2,10 +2,29 @@ IMS LTI PROVIDER PLUGIN FOR MOODLE
== Description ==
+=== About IMS LTI ===
+
+According IMS:
+
+''IMS is developing Learning Tools Interoperability (LTI) to allow remote tools and content to be integrated into a Learning Management System (LMS).''
+
+=== About this plugin ===
+
This is a local plugin for making Moodle a LTI provider tool.
It can be use to provide access to full courses or activities from remote systems (other Moodle installations, Sakai, any LMS LTI consumer compliant)
+Please note that since Moodle 2.2 there is a core activity plugin called "External tool" that is a LTI consumer.
+
+=== Why this plugin ===
+
+This plugin allow remote systems users (LTI consumers) access to Moodle courses or Moodle activities inside a course.
+
+Moodle (version 2.2 and onwards) is a LTI consumer tool also.
+
+You can use this plugin to share activities and courses between Moodle installations without configuring a Moodle network.
+
+You can also share activities and courses with other LTI consumer tools like Sakai
== Main feautres ==
@@ -17,28 +36,66 @@ Send backs course or activity final grades to the LTI consumer tool
Modify the course or activity page for hiding the header, footer and left or right blocks
+== Installing and configuring ==
+
+Follow instructions here: http://moodle.org/plugins/pluginversions.php?plugin=local_ltiprovider
+
+Once installed, a new link called "LTI Provider" will be displayed in the course navigation block .
+
+In this page, you can add, modify and disable the tools provided in your course.
+
+Please note that you can provide a tool n times with different configurations
+
+There are options for hiding the page header, footer, and left and right blocks and also options for force the Moodle navigation inside a course or activity.
+
+There are also options for assign different roles in the course or activity to the remote users.
+
+Once added a tool, you will need to use two settings in your consumer tool:
+
+* Shared secret
+
+* Launch URL
+
+Configure your consumer tool with these two settings. That's all
+
== How it works ==
=== User authentication ===
-Users are created automatically in their first access to the system.
-Users are created with a hashed username and also with an auth method that disable direct login to Moodle.
-Users are allways enrolled in the course where the activities are.
+* Users are created automatically in their first access to the system.
+* Users are created with a hashed username and also with an auth method that disable direct login to Moodle.
+* Users are allways enrolled in the course where the activities are.
+
You can choose which role has the Learner and the Teacher from the remote system.
+
There is also settings for setting Users profile default values (email visible, etc...)
If you are going to have courses with local and remote users enrolled, I recommend you to create these new roles:
-External teacher
-External student
+* External teacher
+* External student
=== Grading ===
A cron job checks periodically activities for sending back grades (overall course grade or activity grade).
== Future versions ==
-Handle authentication with a custom auth plugin for Moodle (for handling logout, etc...)
-Add options for automatically add remote users to course groups.
-Add options for automatically add remote users to system cohorts.
-Add options for enabling duration time for enrolments
+* Handle authentication with a custom auth plugin for Moodle (for handling logout, etc...)
+* Add options for automatically add remote users to course groups.
+* Add options for automatically add remote users to system cohorts.
+* Add options for enabling duration time for enrolments
+
+== Credits ==
+
+Juan Leyva <http://twitter.com/#!/jleyvadelgado>
+
+http://moodle.org/user/profile.php?id=49568
+
+== See also ==
+
+[http://moodle.org/plugins/pluginversions.php?plugin=local_ltiprovider Plugin entry]
+
+[https://github.com/jleyva/moodle-local_ltiprovider Github page]
+
+[[Category: Contributed code]]
View
10 db/access.php
@@ -29,8 +29,8 @@
'local/ltiprovider:manage' => array(
- 'riskbitmask' => RISK_SPAM,
-
+ 'riskbitmask' => RISK_SPAM,
+
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
@@ -40,8 +40,8 @@
),
'local/ltiprovider:view' => array(
- 'riskbitmask' => RISK_SPAM,
-
+ 'riskbitmask' => RISK_SPAM,
+
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
@@ -50,4 +50,4 @@
'manager' => CAP_ALLOW
)
)
-);
+);
View
56 db/install.xml
@@ -7,52 +7,52 @@
<TABLE NAME="local_ltiprovider" COMMENT="List of tools provided to the remote system" NEXT="local_ltiprovider_user">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="courseid"/>
- <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="contextid"/>
- <FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="courseid" NEXT="disabled"/>
- <FIELD NAME="disabled" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="contextid" NEXT="sendgrades"/>
+ <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="contextid"/>
+ <FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="courseid" NEXT="disabled"/>
+ <FIELD NAME="disabled" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="contextid" NEXT="sendgrades"/>
<FIELD NAME="sendgrades" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="disabled" NEXT="forcenavigation"/>
- <FIELD NAME="forcenavigation" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="sendgrades" NEXT="croleinst"/>
+ <FIELD NAME="forcenavigation" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="sendgrades" NEXT="croleinst"/>
<FIELD NAME="croleinst" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="forcenavigation" NEXT="crolelearn"/>
- <FIELD NAME="crolelearn" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="croleinst" NEXT="aroleinst"/>
- <FIELD NAME="aroleinst" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="crolelearn" NEXT="arolelearn"/>
- <FIELD NAME="arolelearn" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="aroleinst" NEXT="secret"/>
- <FIELD NAME="secret" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="arolelearn" NEXT="encoding"/>
- <FIELD NAME="encoding" TYPE="char" LENGTH="32" NOTNULL="false" SEQUENCE="false" PREVIOUS="secret" NEXT="institution"/>
- <FIELD NAME="institution" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" PREVIOUS="encoding" NEXT="lang"/>
- <FIELD NAME="lang" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="en" SEQUENCE="false" PREVIOUS="institution" NEXT="timezone"/>
- <FIELD NAME="timezone" TYPE="char" LENGTH="100" NOTNULL="true" DEFAULT="99" SEQUENCE="false" PREVIOUS="lang" NEXT="maildisplay"/>
- <FIELD NAME="maildisplay" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="2" SEQUENCE="false" PREVIOUS="timezone" NEXT="city"/>
- <FIELD NAME="city" TYPE="char" LENGTH="120" NOTNULL="true" SEQUENCE="false" PREVIOUS="maildisplay" NEXT="country"/>
- <FIELD NAME="country" TYPE="char" LENGTH="2" NOTNULL="true" SEQUENCE="false" PREVIOUS="city" NEXT="hidepageheader"/>
+ <FIELD NAME="crolelearn" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="croleinst" NEXT="aroleinst"/>
+ <FIELD NAME="aroleinst" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="crolelearn" NEXT="arolelearn"/>
+ <FIELD NAME="arolelearn" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="aroleinst" NEXT="secret"/>
+ <FIELD NAME="secret" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="arolelearn" NEXT="encoding"/>
+ <FIELD NAME="encoding" TYPE="char" LENGTH="32" NOTNULL="false" SEQUENCE="false" PREVIOUS="secret" NEXT="institution"/>
+ <FIELD NAME="institution" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" PREVIOUS="encoding" NEXT="lang"/>
+ <FIELD NAME="lang" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="en" SEQUENCE="false" PREVIOUS="institution" NEXT="timezone"/>
+ <FIELD NAME="timezone" TYPE="char" LENGTH="100" NOTNULL="true" DEFAULT="99" SEQUENCE="false" PREVIOUS="lang" NEXT="maildisplay"/>
+ <FIELD NAME="maildisplay" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="2" SEQUENCE="false" PREVIOUS="timezone" NEXT="city"/>
+ <FIELD NAME="city" TYPE="char" LENGTH="120" NOTNULL="true" SEQUENCE="false" PREVIOUS="maildisplay" NEXT="country"/>
+ <FIELD NAME="country" TYPE="char" LENGTH="2" NOTNULL="true" SEQUENCE="false" PREVIOUS="city" NEXT="hidepageheader"/>
<FIELD NAME="hidepageheader" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="country" NEXT="hidepagefooter"/>
<FIELD NAME="hidepagefooter" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="hidepageheader" NEXT="hideleftblocks"/>
<FIELD NAME="hideleftblocks" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="hidepagefooter" NEXT="hiderightblocks"/>
<FIELD NAME="hiderightblocks" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="hideleftblocks" NEXT="customcss"/>
<FIELD NAME="customcss" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="hiderightblocks" NEXT="timecreated"/>
- <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="customcss" NEXT="lastsync"/>
+ <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="customcss" NEXT="lastsync"/>
<FIELD NAME="lastsync" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="last sync timestamp" PREVIOUS="timecreated" NEXT="timemodified"/>
- <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="lastsync"/>
+ <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="lastsync"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
- <TABLE NAME="local_ltiprovider_user" COMMENT="User access log and gradeback data" PREVIOUS="local_ltiprovider">
+ <TABLE NAME="local_ltiprovider_user" COMMENT="User access log and gradeback data" PREVIOUS="local_ltiprovider">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="userid"/>
- <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="toolid"/>
- <FIELD NAME="toolid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="userid" NEXT="serviceurl"/>
- <FIELD NAME="serviceurl" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="toolid" NEXT="sourceid"/>
- <FIELD NAME="sourceid" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="serviceurl" NEXT="consumerkey"/>
- <FIELD NAME="consumerkey" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="sourceid" NEXT="consumersecret"/>
- <FIELD NAME="consumersecret" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="consumerkey" NEXT="lastgrade"/>
- <FIELD NAME="lastgrade" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="last grade" PREVIOUS="consumersecret" NEXT="lastsync"/>
- <FIELD NAME="lastsync" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="last sync timestamp" PREVIOUS="lastgrade" NEXT="lastaccess"/>
- <FIELD NAME="lastaccess" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="last access timestamp" PREVIOUS="lastsync"/>
+ <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="toolid"/>
+ <FIELD NAME="toolid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="userid" NEXT="serviceurl"/>
+ <FIELD NAME="serviceurl" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="toolid" NEXT="sourceid"/>
+ <FIELD NAME="sourceid" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="serviceurl" NEXT="consumerkey"/>
+ <FIELD NAME="consumerkey" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="sourceid" NEXT="consumersecret"/>
+ <FIELD NAME="consumersecret" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="consumerkey" NEXT="lastgrade"/>
+ <FIELD NAME="lastgrade" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="last grade" PREVIOUS="consumersecret" NEXT="lastsync"/>
+ <FIELD NAME="lastsync" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="last sync timestamp" PREVIOUS="lastgrade" NEXT="lastaccess"/>
+ <FIELD NAME="lastaccess" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="last access timestamp" PREVIOUS="lastsync"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
-</XMLDB>
+</XMLDB>
View
18 edit.php
@@ -23,10 +23,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-require_once(dirname(__FILE__) . '/../../config.php');
+require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot.'/local/ltiprovider/lib.php');
require_once($CFG->dirroot.'/local/ltiprovider/edit_form.php');
-
+
$id = optional_param('id', -1, PARAM_INT); // user id; -1 if creating new tool
$courseid = optional_param('courseid', 0, PARAM_INT); // course id (defaults to Site)
$delete = optional_param('delete', 0, PARAM_BOOL);
@@ -39,8 +39,7 @@
print_error('invalidtoolid', 'local_ltiprovider');
}
$courseid = $tool->courseid;
-}
-else {
+} else {
$tool = new stdClass();
$tool->id = -1;
$tool->courseid = $courseid;
@@ -75,10 +74,10 @@
$PAGE->navbar->add($strheading);
$PAGE->set_title($strheading);
$PAGE->set_heading($COURSE->fullname);
-
+
echo $OUTPUT->header();
echo $OUTPUT->heading($strheading);
- $yesurl = new moodle_url('/local/ltiprovider/edit.php', array('id'=>$tool->id, 'delete'=>1, 'confirm'=>1,'sesskey'=>sesskey()));
+ $yesurl = new moodle_url('/local/ltiprovider/edit.php', array('id'=>$tool->id, 'delete'=>1, 'confirm'=>1, 'sesskey'=>sesskey()));
$message = get_string('delconfirm', 'local_ltiprovider');
echo $OUTPUT->confirm($message, $yesurl, $returnurl);
echo $OUTPUT->footer();
@@ -100,19 +99,18 @@
$PAGE->set_title($strheading);
$PAGE->set_heading($course->fullname . ': '.$strheading);
-$editform = new edit_form(null, compact('context','courseid'));
+$editform = new edit_form(null, compact('context', 'courseid'));
$editform->set_data($tool);
if ($editform->is_cancelled()) {
redirect($returnurl);
-} elseif ($data = $editform->get_data()) {
+} else if ($data = $editform->get_data()) {
if ($data->id > 0) {
// Update
ltiprovider_update_tool($data);
- }
- else {
+ } else {
// Create new
ltiprovider_add_tool($data);
}
View
60 edit_form.php
@@ -32,68 +32,68 @@
class edit_form extends moodleform {
// Define the form
- function definition () {
+ public function definition () {
global $USER, $CFG, $COURSE;
$mform =& $this->_form;
$templateuser = $USER;
$context = $this->_customdata['context'];
$mform->addElement('header', 'settingsheader', get_string('toolsettings', 'local_ltiprovider'));
-
+
$tools = array();
$tools[$context->id] = get_string('course');
get_all_mods($this->_customdata['courseid'], $mods, $modnames, $modnamesplural, $modnamesused);
-
- foreach($mods as $mod){
+
+ foreach ($mods as $mod) {
$tools[$mod->context->id] = format_string($mod->name);
}
-
- $mform->addElement('select', 'contextid', get_string('tooltobeprovide','local_ltiprovider'), $tools);
+
+ $mform->addElement('select', 'contextid', get_string('tooltobeprovide', 'local_ltiprovider'), $tools);
$mform->setDefault('contextid', $context->id);
-
+
$mform->addElement('checkbox', 'sendgrades', null, get_string('sendgrades', 'local_ltiprovider'));
$mform->setDefault('sendgrades', 1);
-
+
$mform->addElement('checkbox', 'forcenavigation', null, get_string('forcenavigation', 'local_ltiprovider'));
$mform->setDefault('forcenavigation', 1);
-
+
$assignableroles = get_assignable_roles($context);
-
- $mform->addElement('select', 'croleinst', get_string('courseroleinstructor','local_ltiprovider'), $assignableroles);
+
+ $mform->addElement('select', 'croleinst', get_string('courseroleinstructor', 'local_ltiprovider'), $assignableroles);
$mform->setDefault('croleinst', '3');
$mform->setAdvanced('croleinst');
- $mform->addElement('select', 'crolelearn', get_string('courserolelearner','local_ltiprovider'), $assignableroles);
+ $mform->addElement('select', 'crolelearn', get_string('courserolelearner', 'local_ltiprovider'), $assignableroles);
$mform->setDefault('crolelearn', '5');
$mform->setAdvanced('crolelearn');
-
- $mform->addElement('select', 'aroleinst', get_string('activityroleinstructor','local_ltiprovider'), $assignableroles);
+
+ $mform->addElement('select', 'aroleinst', get_string('activityroleinstructor', 'local_ltiprovider'), $assignableroles);
$mform->disabledIf('aroleinst', 'contextid', 'eq', $context->id);
$mform->setDefault('aroleinst', '3');
$mform->setAdvanced('aroleinst');
- $mform->addElement('select', 'arolelearn', get_string('activityrolelearner','local_ltiprovider'), $assignableroles);
+ $mform->addElement('select', 'arolelearn', get_string('activityrolelearner', 'local_ltiprovider'), $assignableroles);
$mform->disabledIf('arolelearn', 'contextid', 'eq', $context->id);
$mform->setDefault('arolelearn', '5');
$mform->setAdvanced('arolelearn');
-
+
$mform->addElement('header', 'remotesystem', get_string('remotesystem', 'local_ltiprovider'));
-
+
$mform->addElement('text', 'secret', get_string('secret', 'local_ltiprovider'), 'maxlength="64" size="25"');
$mform->setType('secret', PARAM_MULTILANG);
$mform->setDefault('secret', md5(uniqid(rand(), 1)));
$mform->addRule('secret', get_string('required'), 'required');
-
+
$textlib = textlib_get_instance();
$choices = $textlib->get_encodings();
$mform->addElement('select', 'encoding', get_string('remoteencoding', 'local_ltiprovider'), $choices);
$mform->setDefault('encoding', 'UTF-8');
-
+
$mform->addElement('header', 'defaultheader', get_string('userdefaultvalues', 'local_ltiprovider'));
-
+
$choices = array(0 => get_string('emaildisplayno'), 1 => get_string('emaildisplayyes'), 2 => get_string('emaildisplaycourse'));
$mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
$mform->setDefault('maildisplay', 2);
-
+
$mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
$mform->setType('city', PARAM_MULTILANG);
if (empty($CFG->defaultcity)) {
@@ -102,7 +102,7 @@ function definition () {
$mform->setDefault('city', $CFG->defaultcity);
}
$mform->addRule('city', get_string('required'), 'required');
-
+
$mform->addElement('select', 'country', get_string('selectacountry'), get_string_manager()->get_list_of_countries());
if (empty($CFG->country)) {
$mform->setDefault('country', $templateuser->country);
@@ -124,32 +124,32 @@ function definition () {
$mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
$mform->setType('institution', PARAM_MULTILANG);
$mform->setDefault('institution', $templateuser->institution);
- $mform->setAdvanced('institution');
-
+ $mform->setAdvanced('institution');
+
$mform->addElement('header', 'layoutandcss', get_string('layoutandcss', 'local_ltiprovider'));
-
+
$mform->addElement('checkbox', 'hidepageheader', null, get_string('hidepageheader', 'local_ltiprovider'));
$mform->addElement('checkbox', 'hidepagefooter', null, get_string('hidepagefooter', 'local_ltiprovider'));
$mform->addElement('checkbox', 'hideleftblocks', null, get_string('hideleftblocks', 'local_ltiprovider'));
$mform->addElement('checkbox', 'hiderightblocks', null, get_string('hiderightblocks', 'local_ltiprovider'));
$mform->setAdvanced('hideleftblocks');
$mform->setAdvanced('hiderightblocks');
-
+
$editoroptions = array();
$displayoptions = array('rows'=>'4', 'cols'=>'');
$mform->addElement('textarea', 'customcss', get_string('customcss', 'local_ltiprovider'), $displayoptions, $editoroptions);
$mform->setAdvanced('customcss');
-
- $mform->addElement('hidden','id');
+
+ $mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
- $mform->addElement('hidden','courseid');
+ $mform->addElement('hidden', 'courseid');
$mform->setType('courseid', PARAM_INT);
$this->add_action_buttons();
}
- function validation($data, $files) {
+ public function validation($data, $files) {
global $COURSE, $DB, $CFG;
$errors = parent::validation($data, $files);
View
22 index.php
@@ -23,8 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-require_once(dirname(__FILE__) . '/../../config.php');
-
+require_once(dirname(__FILE__) . '/../../config.php');
+
$courseid = required_param('courseid', PARAM_INT);
if (! ($course = $DB->get_record('course', array('id'=>$courseid)))) {
@@ -49,37 +49,35 @@
$tools = $DB->get_records('local_ltiprovider', array('courseid' => $course->id));
$data = array();
-foreach($tools as $tool) {
+foreach ($tools as $tool) {
$line = array();
$line[] = print_context_name(get_context_instance_by_id($tool->contextid));
$line[] = $tool->secret;
$line[] = new moodle_url('/local/ltiprovider/tool.php', array('id' => $tool->id));
-
+
if (has_capability('local/ltiprovider:manage', $context)) {
$buttons = array();
-
+
$buttons[] = html_writer::link(new moodle_url('/local/ltiprovider/edit.php', array('id'=>$tool->id, 'delete'=>1, 'sesskey'=>sesskey())), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/delete'), 'alt'=>get_string('delete'), 'class'=>'iconsmall')));
$buttons[] = html_writer::link(new moodle_url('/local/ltiprovider/edit.php', array('id'=>$tool->id, 'sesskey'=>sesskey())), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/edit'), 'alt'=>get_string('edit'), 'class'=>'iconsmall')));
if ($tool->disabled) {
$buttons[] = html_writer::link(new moodle_url('/local/ltiprovider/edit.php', array('id'=>$tool->id, 'show'=>1, 'sesskey'=>sesskey())), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/show'), 'alt'=>get_string('show'), 'class'=>'iconsmall')));
- }
- else {
+ } else {
$buttons[] = html_writer::link(new moodle_url('/local/ltiprovider/edit.php', array('id'=>$tool->id, 'hide'=>1, 'sesskey'=>sesskey())), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/hide'), 'alt'=>get_string('hide'), 'class'=>'iconsmall')));
}
-
+
$line[] = implode(' ', $buttons);
- }
- else {
+ } else {
$line[] = '';
}
$data[] = $line;
}
$table = new html_table();
$table->head = array(
- get_string('name', 'local_ltiprovider'),
- get_string('secret', 'local_ltiprovider'),
+ get_string('name', 'local_ltiprovider'),
+ get_string('secret', 'local_ltiprovider'),
get_string('url', 'local_ltiprovider'),
get_string('edit'));
$table->size = array('20%', '20%', '50%', '10%');
View
92 lib.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * Version details.
+ * General plugin functions.
*
* @package local
* @subpackage ltiprovider
@@ -29,48 +29,49 @@
* Change the navigation block and bar only for external users
* Force course or activity navigation and modify CSS also
* Please note that this function is only called in pages where the navigation block is present
- *
+ *
* @global moodle_user $USER
* @global moodle_database $DB
* @param navigation_node $nav Current navigation object
*/
function ltiprovider_extends_navigation ($nav) {
global $USER, $PAGE, $SESSION;
-
+
// Check capabilities for tool providers
- if ($PAGE->course->id and $PAGE->course->id != SITEID and has_capability('local/ltiprovider:view',$PAGE->context)) {
- $ltiurl = new moodle_url('/local/ltiprovider/index.php?courseid='.$PAGE->course->id);
+ // TODO Change this for Moodle 2.3:
+ // use extend_navigation_course and extend_navigation_user
+ if ($PAGE->course->id and $PAGE->course->id != SITEID and has_capability('local/ltiprovider:view', $PAGE->context)) {
+ $ltiurl = new moodle_url('/local/ltiprovider/index.php', array('courseid' => $PAGE->course->id));
$coursenode = $nav->find($PAGE->course->id, $nav::TYPE_COURSE);
$coursenode->add(get_string('pluginname', 'local_ltiprovider'), $ltiurl, $nav::TYPE_SETTING, null, 'ltiprovider'.$PAGE->course->id);
}
-
+
if (isset($USER) and isset($USER->auth) and $USER->auth == 'nologin' and strpos($USER->username, 'ltiprovider') === 0) {
// Force course or activity navigation
if (isset($SESSION->ltiprovider) and $SESSION->ltiprovider->forcenavigation) {
$context = $SESSION->ltiprovider->context;
$urltogo = '';
if ($context->contextlevel == CONTEXT_COURSE and $PAGE->course->id != $SESSION->ltiprovider->courseid) {
$urltogo = new moodle_url('/course/view.php', array('id' => $SESSION->ltiprovider->courseid));
- }
- else if ($context->contextlevel == CONTEXT_MODULE and $PAGE->context->id != $context->id) {
+ } else if ($context->contextlevel == CONTEXT_MODULE and $PAGE->context->id != $context->id) {
$cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST);
$urltogo = new moodle_url('/mod/'.$cm->modname.'/view.php', array('id' => $cm->id));
}
-
+
if ($urltogo) {
redirect($urltogo);
}
}
-
+
// Delete all the navigation nodes except the course one
$coursenode = $nav->find($PAGE->course->id, $nav::TYPE_COURSE);
- foreach(array('myprofile', 'users', 'site', 'home', 'myhome', 'mycourses', 'courses', '1') as $nodekey) {
- if($node = $nav->get($nodekey)) {
+ foreach (array('myprofile', 'users', 'site', 'home', 'myhome', 'mycourses', 'courses', '1') as $nodekey) {
+ if ($node = $nav->get($nodekey)) {
$node->remove();
}
- }
+ }
$nav->children->add($coursenode);
-
+
// Custom CSS
if (isset($SESSION->ltiprovider)) {
$PAGE->requires->css(new moodle_url('/local/ltiprovider/styles.php', array('id' => $SESSION->ltiprovider->id)));
@@ -86,7 +87,7 @@ function ltiprovider_extends_navigation ($nav) {
*/
function ltiprovider_add_tool($tool) {
global $DB;
-
+
if (!isset($tool->disabled)) {
$tool->disabled = 0;
}
@@ -96,14 +97,14 @@ function ltiprovider_add_tool($tool) {
if (!isset($tool->timemodified)) {
$tool->timemodified = $tool->timecreated;
}
-
+
$tool->sendgrades = (isset($tool->sendgrades)) ? 1 : 0;
$tool->forcenavigation = (isset($tool->forcenavigation)) ? 1 : 0;
$tool->hidepageheader = (isset($tool->hidepageheader)) ? 1 : 0;
$tool->hidepagefooter = (isset($tool->hidepagefooter)) ? 1 : 0;
$tool->hideleftblocks = (isset($tool->hideleftblocks)) ? 1 : 0;
$tool->hiderightblocks = (isset($tool->hiderightblocks)) ? 1 : 0;
-
+
$tool->id = $DB->insert_record('local_ltiprovider', $tool);
return $tool->id;
@@ -141,7 +142,7 @@ function ltiprovider_delete_tool($tool) {
}
/**
- * Cron function
+ * Cron function for sync grades
* @return void
*/
function local_ltiprovider_cron() {
@@ -150,11 +151,11 @@ function local_ltiprovider_cron() {
require_once($CFG->dirroot."/local/ltiprovider/ims-blti/OAuthBody.php");
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/grade/querylib.php');
-
+
// TODO - Add a global setting for this
$synctime = 60*60; // Every 1 hour grades are sync
$timenow = time();
-
+
mtrace('Running cron for ltiprovider');
if ($tools = $DB->get_records_select('local_ltiprovider', 'disabled = ? AND sendgrades = ?', array(0, 1))) {
foreach ($tools as $tool) {
@@ -166,16 +167,15 @@ function local_ltiprovider_cron() {
if ($user->lastsync > $tool->lastsync) {
continue;
}
-
+
$grade = false;
if ($context = $DB->get_record('context', array('id' => $tool->contextid))) {
if ($context->contextlevel == CONTEXT_COURSE) {
- if($grade = grade_get_course_grade($user->userid, $tool->courseid)){
+ if ($grade = grade_get_course_grade($user->userid, $tool->courseid)) {
$grade = $grade->grade;
- }
- }
- else if ($context->contextlevel == CONTEXT_MODULE) {
+ }
+ } else if ($context->contextlevel == CONTEXT_MODULE) {
$cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST);
$grades = grade_get_grades($cm->course, 'mod', $cm->modname, $cm->id, $user->userid);
@@ -186,20 +186,20 @@ function local_ltiprovider_cron() {
$grade = $grade->grade;
}
}
-
+
// We sync with the external system only when the new grade differs with the previous one
// TODO - Global setting for check this
// I assume base 100 grades
if ($grade !== false and $grade != $user->lastgrade and $grade > 0 and $grade <= 100) {
$grade = $grade / 100;
-
+
$body = ltiprovider_create_service_body($user->sourceid, $grade);
-
+
$response = sendOAuthBodyPOST('POST', $user->serviceurl, $user->consumerkey, $user->consumersecret, 'application/xml', $body);
// TODO - Check for errors in $retval in a correct way (parsing xml)
-
+
if (strpos(strtolower($response), 'success') !== false) {
-
+
$DB->set_field('local_ltiprovider_user', 'lastsync', $timenow, array('id' => $user->id));
$DB->set_field('local_ltiprovider_user', 'lastgrade', $grade, array('id' => $user->id));
mtrace("User grade send to remote system. userid: $user->userid grade: $grade");
@@ -216,17 +216,23 @@ function local_ltiprovider_cron() {
}
}
+/**
+ * Create a IMS POX body request for sync grades.
+ * @param string $source Sourceid required for the request
+ * @param float $grade User final grade
+ * @return string
+ */
function ltiprovider_create_service_body($source, $grade) {
- return '<?xml version = "1.0" encoding = "UTF-8"?>
-<imsx_POXEnvelopeRequest xmlns = "http://www.imsglobal.org/lis/oms1p0/pox">
- <imsx_POXHeader>
- <imsx_POXRequestHeaderInfo>
- <imsx_version>V1.0</imsx_version>
- <imsx_messageIdentifier>'.(time()).'</imsx_messageIdentifier>
- </imsx_POXRequestHeaderInfo>
- </imsx_POXHeader>
- <imsx_POXBody>
- <replaceResultRequest>
+ return '<?xml version = "1.0" encoding = "UTF-8"?>
+<imsx_POXEnvelopeRequest xmlns = "http://www.imsglobal.org/lis/oms1p0/pox">
+ <imsx_POXHeader>
+ <imsx_POXRequestHeaderInfo>
+ <imsx_version>V1.0</imsx_version>
+ <imsx_messageIdentifier>'.(time()).'</imsx_messageIdentifier>
+ </imsx_POXRequestHeaderInfo>
+ </imsx_POXHeader>
+ <imsx_POXBody>
+ <replaceResultRequest>
<resultRecord>
<sourcedGUID>
<sourcedId>'.$source.'</sourcedId>
@@ -237,8 +243,8 @@ function ltiprovider_create_service_body($source, $grade) {
<textString>'.$grade.'</textString>
</resultScore>
</result>
- </resultRecord>
- </replaceResultRequest>
- </imsx_POXBody>
+ </resultRecord>
+ </replaceResultRequest>
+ </imsx_POXBody>
</imsx_POXEnvelopeRequest>';
}
View
4 styles.php
@@ -25,7 +25,7 @@
require_once(dirname(__FILE__) . '/../../config.php');
-$toolid = required_param('id',PARAM_INT);
+$toolid = required_param('id', PARAM_INT);
if (! ($tool = $DB->get_record('local_ltiprovider', array('id'=>$toolid)))) {
print_error('invalidtoolid', 'local_ltiprovider');
@@ -79,4 +79,4 @@
header('Content-Length: '.strlen($css));
echo $css;
-die;
+die;
View
62 tool.php
@@ -26,7 +26,7 @@
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot.'/local/ltiprovider/ims-blti/blti.php');
-$toolid = required_param('id',PARAM_INT);
+$toolid = required_param('id', PARAM_INT);
if (! ($tool = $DB->get_record('local_ltiprovider', array('id'=>$toolid)))) {
print_error('invalidtoolid', 'local_ltiprovider');
@@ -36,20 +36,20 @@
print_error('tooldisabled', 'local_ltiprovider');
}
-
+
// Do not set session, do not redirect
$context = new BLTI($tool->secret, false, false);
// Correct launch request
if ($context->valid) {
-
+
// Check that we can perform enrolments
if (enrol_is_enabled('manual')) {
$manual = enrol_get_plugin('manual');
} else {
print_error('nomanualenrol', 'local_ltiprovider');
}
-
+
// Transform to utf8 all the post and get data
$textlib = textlib_get_instance();
foreach ($_POST as $key => $value) {
@@ -58,12 +58,12 @@
foreach ($_GET as $key => $value) {
$_GET[$key] = $textlib->convert($value, $tool->encoding);
}
-
+
// We need an username without extended chars
$username = 'ltiprovider'.md5($context->getUserKey());
-
+
// Check if the user exists
- $user = $DB->get_record('user',array('username' => $username));
+ $user = $DB->get_record('user', array('username' => $username));
if (! $user) {
$user = new stdClass();
// clean_param , email username text
@@ -77,51 +77,49 @@
$user->country = $tool->country;
$user->institution = $tool->institution;
$user->timezone = $tool->timezone;
- $user->maildisplay = $tool->maildisplay;
-
+ $user->maildisplay = $tool->maildisplay;
+
$user->lang = $tool->lang;
- if(! $user->lang and isset($_POST['launch_presentation_locale'])){
+ if (! $user->lang and isset($_POST['launch_presentation_locale'])) {
$user->lang = optional_param('launch_presentation_locale', '', PARAM_LANG);
}
- if(! $user->lang){
+ if (! $user->lang) {
// TODO: This should be changed for detect the course lang
$user->lang = current_language();
}
-
+
$user->id = $DB->insert_record('user', $user);
// Reload full user
- $user = $DB->get_record('user',array('id' => $user->id));
+ $user = $DB->get_record('user', array('id' => $user->id));
}
// Enrol user in course and activity if needed
if (! $context = $DB->get_record('context', array('id' => $tool->contextid))) {
print_error("invalidcontext");
}
-
+
if ($context->contextlevel == CONTEXT_COURSE) {
$courseid = $context->instanceid;
$urltogo = $CFG->wwwroot.'/course/view.php?id='.$courseid;
- }
- else if ($context->contextlevel == CONTEXT_MODULE) {
+ } else if ($context->contextlevel == CONTEXT_MODULE) {
$cmid = $context->instanceid;
$cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST);
$courseid = $cm->course;
$urltogo = $CFG->wwwroot.'/mod/'.$cm->modname.'/view.php?id='.$cm->id;
- }
- else {
+ } else {
print_error("invalidcontext");
}
-
- $course = $DB->get_record('course', array('id' => $courseid), '*',MUST_EXIST);
-
+
+ $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+
// Enrol the user in the course
$roles = explode(',', $_POST['roles']);
$role =(in_array('Instructor', $roles))? 'Instructor' : 'Learner';
-
+
$today = time();
$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
$timeend = 0;
- if(isset($tool->enrolduration) and $tool->enrolduration){
+ if (isset($tool->enrolduration) and $tool->enrolduration) {
$duration = (int)$tool->enrolduration * 60*60*24; // convert days to seconds
if ($duration > 0) { // sanity check
$timeend = $today + $duration;
@@ -130,7 +128,7 @@
// Course role id for the Instructor or Learner
// TODO Do something with lti system admin (urn:lti:sysrole:ims/lis/Administrator)
$roleid = ($role == 'Instructor')? $tool->croleinst: $tool->crolelearn;
-
+
if ($instances = enrol_get_instances($course->id, false)) {
foreach ($instances as $instance) {
if ($instance->enrol === 'manual') {
@@ -139,22 +137,21 @@
}
}
}
-
+
if ($context->contextlevel == CONTEXT_MODULE) {
// Enrol the user in the activity
- if(($tool->aroleinst and $role == 'Instructor') or ($tool->arolelearn and $role == 'Learner')){
+ if (($tool->aroleinst and $role == 'Instructor') or ($tool->arolelearn and $role == 'Learner')) {
$roleid = ($role == 'Instructor')? $tool->aroleinst: $tool->arolelearn;
role_assign($roleid, $user->id, $tool->contextid);
}
}
-
+
// Login user
$sourceid = optional_param('lis_result_sourcedid', '', PARAM_RAW);
-
+
if ($userlog = $DB->get_record('local_ltiprovider_user', array('toolid' => $tool->id, 'userid' => $user->id)) and $userlog->sourceid == $sourceid) {
$DB->set_field('local_ltiprovider_user', 'lastaccess', time(), array('id' => $userlog->id));
- }
- else {
+ } else {
// These data is needed for sending backup outcomes (aka grades)
$userlog = new stdClass();
$userlog->userid = $user->id;
@@ -170,14 +167,13 @@
$userlog->lastaccess = time();
$DB->insert_record('local_ltiprovider_user', $userlog);
}
-
+
add_to_log(SITEID, 'user', 'login', $urltogo, "ltiprovider login", 0, $user->id);
$tool->context = $context;
$SESSION->ltiprovider = $tool;
complete_user_login($user);
redirect($urltogo);
-}
-else {
+} else {
//print_error('invalidcredentials', 'local_ltiprovider');
echo $context->message;
}
View
4 version.php
@@ -26,4 +26,6 @@
defined('MOODLE_INTERNAL') || die;
$plugin->version = 2011121701;
-$plugin->requires = 2010080300;
+$plugin->requires = 2010112400;
+$plugin->maturity = MATURITY_STABLE;
+$plugin->release = 2.0;

0 comments on commit 8c8420c

Please sign in to comment.