Skip to content

Commit

Permalink
Merge pull request #34 from spvickers/MOODLE_27_STABLE
Browse files Browse the repository at this point in the history
Added options to disable auto-enrol
  • Loading branch information
jleyva committed Feb 1, 2016
2 parents 081d0c0 + ee1ebbe commit 5dc58df
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 23 deletions.
4 changes: 3 additions & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" PREVIOUS="syncperiod" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" PREVIOUS="timemodified" NEXT="lastsync"/>
<FIELD NAME="lastsync" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="last sync timestamp" PREVIOUS="timecreated" NEXT="requirecompletion"/>
<FIELD NAME="requirecompletion" TYPE="int" LENGTH="2" NOTNULL="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="lastsync"/>
<FIELD NAME="requirecompletion" TYPE="int" LENGTH="2" NOTNULL="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="lastsync" NEXT="enrolinst"/>
<FIELD NAME="enrolinst" TYPE="int" LENGTH="2" NOTNULL="false" DEFAULT="1" SEQUENCE="false" PREVIOUS="requirecompletion" NEXT="enrollearn"/>
<FIELD NAME="enrollearn" TYPE="int" LENGTH="2" NOTNULL="false" DEFAULT="1" SEQUENCE="false" PREVIOUS="enrolinst"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
16 changes: 16 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,21 @@ function xmldb_local_ltiprovider_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2014080102, 'local', 'ltiprovider');
}

if ($oldversion < 2014080103) {

$table = new xmldb_table('local_ltiprovider');

$field = new xmldb_field('enrolinst', XMLDB_TYPE_INTEGER, 2, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 1, 'requirecompletion');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('enrollearn', XMLDB_TYPE_INTEGER, 2, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 1, 'enrolinst');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

upgrade_plugin_savepoint(true, 2014080103, 'local', 'ltiprovider');
}

return true;
}
9 changes: 9 additions & 0 deletions edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public function definition () {

$assignableroles = get_assignable_roles($context);

$mform->addElement('checkbox', 'enrolinst', null, get_string('enrolinst', 'local_ltiprovider'));
$mform->setDefault('enrolinst', 1);
$mform->addHelpButton('enrolinst', 'enrolinst', 'local_ltiprovider');
$mform->setAdvanced('enrolinst');
$mform->addElement('checkbox', 'enrollearn', null, get_string('enrollearn', 'local_ltiprovider'));
$mform->setDefault('enrollearn', 1);
$mform->addHelpButton('enrollearn', 'enrollearn', 'local_ltiprovider');
$mform->setAdvanced('enrollearn');

$mform->addElement('select', 'croleinst', get_string('courseroleinstructor', 'local_ltiprovider'), $assignableroles);
$mform->setDefault('croleinst', '3');
$mform->setAdvanced('croleinst');
Expand Down
5 changes: 5 additions & 0 deletions lang/en/local_ltiprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,8 @@

$string['requirecompletion'] = 'Require course or activity completed before sending the grades';
$string['errorcompletionenabled'] = 'Completion should be enabled for the course or the activity';

$string['enrolinst'] = 'Automatically enrol Instructors';
$string['enrolinst_help'] = 'Uncheck this box to redirect instructors to the course page so they can select a self-enrolment option';
$string['enrollearn'] = 'Automatically enrol Learners';
$string['enrollearn_help'] = 'Uncheck this box to redirect learners to the course page so they can select a self-enrolment option';
12 changes: 12 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ function local_ltiprovider_add_tool($tool) {
if (!isset($tool->forcenavigation)) {
$tool->forcenavigation = 0;
}
if (!isset($tool->enrolinst)) {
$tool->enrolinst = 0;
}
if (!isset($tool->enrollearn)) {
$tool->enrollearn = 0;
}
if (!isset($tool->hidepageheader)) {
$tool->hidepageheader = 0;
}
Expand Down Expand Up @@ -163,6 +169,12 @@ function local_ltiprovider_update_tool($tool) {
if (!isset($tool->forcenavigation)) {
$tool->forcenavigation = 0;
}
if (!isset($tool->enrolinst)) {
$tool->enrolinst = 0;
}
if (!isset($tool->enrollearn)) {
$tool->enrollearn = 0;
}
if (!isset($tool->hidepageheader)) {
$tool->hidepageheader = 0;
}
Expand Down
48 changes: 27 additions & 21 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@
function local_ltiprovider_create_service_body($source, $grade) {
return '<?xml version = "1.0" encoding = "UTF-8"?>
<imsx_POXEnvelopeRequest xmlns = "http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
<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>
</sourcedGUID>
<result>
<resultScore>
<language>en-us</language>
<textString>'.$grade.'</textString>
</resultScore>
</result>
</resultRecord>
</replaceResultRequest>
</imsx_POXBody>
<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>
</sourcedGUID>
<result>
<resultScore>
<language>en-us</language>
<textString>'.$grade.'</textString>
</resultScore>
</result>
</resultRecord>
</replaceResultRequest>
</imsx_POXBody>
</imsx_POXEnvelopeRequest>';
}

Expand Down Expand Up @@ -113,6 +113,10 @@ function local_ltiprovider_unenrol_user($tool, $user) {
function local_ltiprovider_enrol_user($tool, $user, $isinstructor, $return = false) {
global $DB;

if (($isinstructor && !$tool->enrolinst) || (!$isinstructor && !$tool->enrollearn)) {
return $return;
}

$course = $DB->get_record('course', array('id' => $tool->courseid), '*', MUST_EXIST);

$manual = enrol_get_plugin('manual');
Expand Down Expand Up @@ -342,6 +346,8 @@ function local_ltiprovider_create_tool($courseid, $contextid, $lticontext) {
$tool->timemodified = time();
$tool->timecreated = time();
$tool->lastsync = 0;
$tool->enrolinst = 1;
$tool->enrollearn = 1;
$tool->sendgrades = (!empty($lticontext->info['lis_outcome_service_url'])) ? 1 : 0;
$tool->syncmembers = (!empty($lticontext->info['ext_ims_lis_memberships_url'])) ? 1 : 0;
$tool->syncmode = (!empty($lticontext->info['ext_ims_lis_memberships_url'])) ? 1 : 0;
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2014080102;
$plugin->version = 2014080103;
$plugin->requires = 2014051200; // Require Moodle version (2.7).
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '2.7.1';

0 comments on commit 5dc58df

Please sign in to comment.