Skip to content

Commit

Permalink
Support send completion status instead grades
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Aug 23, 2017
1 parent 033698c commit c806947
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 20 deletions.
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<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"/>
<FIELD NAME="addtogroup" TYPE="char" LENGTH="64" NOTNULL="false" DEFAULT="" SEQUENCE="false"/>
<FIELD NAME="sendcompletion" TYPE="int" LENGTH="2" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
13 changes: 13 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,18 @@ function xmldb_local_ltiprovider_upgrade($oldversion) {
}
upgrade_plugin_savepoint(true, 2016020101, 'local', 'ltiprovider');
}

if ($oldversion < 2016020103) {

$table = new xmldb_table('local_ltiprovider');

$field = new xmldb_field('sendcompletion', XMLDB_TYPE_INTEGER, 2, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'addtogroup');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

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

return true;
}
29 changes: 20 additions & 9 deletions edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ public function definition () {
$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('advcheckbox', 'requirecompletion', null, get_string('requirecompletion', 'local_ltiprovider'));
$mform->setDefault('requirecompletion', 0);
$mform->disabledIf('requirecompletion', 'sendgrades');

$mform->addElement('checkbox', 'forcenavigation', null, get_string('forcenavigation', 'local_ltiprovider'));
$mform->setDefault('forcenavigation', 1);

Expand Down Expand Up @@ -174,6 +167,19 @@ public function definition () {
$mform->setDefault('institution', $templateuser->institution);
$mform->setAdvanced('institution');

$mform->addElement('header', 'outcomes', get_string('outcomessettings', 'local_ltiprovider'));
$mform->addElement('checkbox', 'sendgrades', null, get_string('sendgrades', 'local_ltiprovider'));
$mform->setDefault('sendgrades', 1);

$mform->addElement('advcheckbox', 'requirecompletion', null, get_string('requirecompletion', 'local_ltiprovider'));
$mform->setDefault('requirecompletion', 0);
$mform->disabledIf('requirecompletion', 'sendgrades');

$mform->addElement('advcheckbox', 'sendcompletion', null, get_string('sendcompletion', 'local_ltiprovider'));
$mform->setDefault('sendcompletion', 0);
$mform->disabledIf('sendcompletion', 'sendgrades');
$mform->addHelpButton('sendcompletion', 'sendcompletion', 'local_ltiprovider');

$mform->addElement('header', 'memberships', get_string('membershipsettings', 'local_ltiprovider'));
$mform->addElement('checkbox', 'syncmembers', null, get_string('enablememberssync', 'local_ltiprovider'));
$mform->disabledIf('syncmembers', 'contextid', 'neq', $context->id);
Expand Down Expand Up @@ -234,7 +240,7 @@ public function validation($data, $files) {
$errors['enrolenddate'] = get_string('enrolenddaterror', 'local_ltiprovider');
}

if (!empty($data['requirecompletion'])) {
if (!empty($data['requirecompletion']) || !empty($data['sendcompletion'])) {
$completion = new completion_info($COURSE);
$moodlecontext = $DB->get_record('context', array('id' => $data['contextid']));
if ($moodlecontext->contextlevel == CONTEXT_MODULE) {
Expand All @@ -244,7 +250,12 @@ public function validation($data, $files) {
}

if (! $completion->is_enabled($cm)) {
$errors['requirecompletion'] = get_string('errorcompletionenabled', 'local_ltiprovider');
if (!empty($data['requirecompletion'])) {
$errors['requirecompletion'] = get_string('errorcompletionenabled', 'local_ltiprovider');
}
if (!empty($data['sendcompletion'])) {
$errors['sendcompletion'] = get_string('errorcompletionenabled', 'local_ltiprovider');
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion lang/en/local_ltiprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,11 @@
$string['addtogroup'] = 'Add users to group (idnumber or request based)';
$string['addtogroup_help'] = 'Add new users to the indicated group (use the group idnumber). If you want to use or create groups based on a parameter from the request, you must add "request:" before parameter name in the setting field, for example, request:myrememotegroup';
$string['forcesendgradesselectedusers'] = 'Force sned grades for selected users';
$string['youhavetoselectauser'] = 'Must select at least one user';
$string['youhavetoselectauser'] = 'Must select at least one user';

$string['outcomessettings'] = 'Outcomes service settings';
$string['sendcompletion'] = 'Send completion status instead grades';
$string['sendcompletion_help'] = 'If this setting is checked, instead the course grade the completion status will be returned:<br/>
1: When the course or activity is completed<br/>
0: When the course or activity is not completed yet';

33 changes: 24 additions & 9 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,10 @@ function local_ltiprovider_cron() {
continue;
}

if ($grade = grade_get_course_grade($user->userid, $tool->courseid)) {
if ($tool->sendcompletion) {
$grade = $completion->is_course_complete($user->userid) ? 1 : 0;
$grademax = 1;
} else if ($grade = grade_get_course_grade($user->userid, $tool->courseid)) {
$grademax = floatval($grade->item->grademax);
$grade = $grade->grade;
}
Expand All @@ -315,17 +318,29 @@ function local_ltiprovider_cron() {
}
}

$grades = grade_get_grades($cm->course, 'mod', $cm->modname, $cm->instance, $user->userid);
if (empty($grades->items[0]->grades)) {
$grade = false;
if ($tool->sendcompletion) {
$data = $completion->get_data($cm, false, $user->userid);
if ($data->completionstate == COMPLETION_COMPLETE_PASS ||
$data->completionstate == COMPLETION_COMPLETE ||
$data->completionstate == COMPLETION_COMPLETE_FAIL) {
$grade = 1;
} else {
$grade = 0;
}
$grademax = 1;
} else {
$grade = reset($grades->items[0]->grades);
if (!empty($grade->item)) {
$grademax = floatval($grade->item->grademax);
$grades = grade_get_grades($cm->course, 'mod', $cm->modname, $cm->instance, $user->userid);
if (empty($grades->items[0]->grades)) {
$grade = false;
} else {
$grademax = floatval($grades->items[0]->grademax);
$grade = reset($grades->items[0]->grades);
if (!empty($grade->item)) {
$grademax = floatval($grade->item->grademax);
} else {
$grademax = floatval($grades->items[0]->grademax);
}
$grade = $grade->grade;
}
$grade = $grade->grade;
}
}

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 = 2016020102;
$plugin->version = 2016020103;
$plugin->requires = 2015051100; // Require Moodle version (2.9).
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '2.9.1';
Expand Down

0 comments on commit c806947

Please sign in to comment.