Skip to content

Commit

Permalink
Bug #8, Implement _grade_update() method [iet:10314222][ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
nfreear committed Mar 9, 2018
1 parent f5db8ed commit c315dd8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
24 changes: 20 additions & 4 deletions classes/local/conditional_embedded_survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function make_complete() {
}
$b_ok = $this->course_modules_complete();

$this->set_grade_grades();
$this->_grade_update();

return $b_ok;
}
Expand Down Expand Up @@ -182,10 +182,10 @@ protected function course_modules_complete() {
$data->overrideby = $this->userid;
$completion->internal_set_data($cminfo, $data);

self::debug([ __FUNCTION__, 'completion->internal_set_data() (update_state)', $result ]);
self::debug([ __FUNCTION__, 'completion->internal_set_data() (update_state)' ]);
}

protected function course_modules_complete_OLD() {
protected function _X_OLD_course_modules_complete() {
global $DB; // Moodle global.

$lastinsertid = $DB->insert_record('course_modules_completion', (object) [
Expand All @@ -207,7 +207,7 @@ protected function course_modules_un_complete() {
]);
}

protected function set_grade_grades() {
protected function _X_OLD_set_grade_grades() {
global $DB;
$grade = $DB->get_record('grade_grades', [
'itemid' => $this->grade_items_id,
Expand All @@ -225,6 +225,22 @@ protected function set_grade_grades() {
}
}

// https://github.com/moodle/moodle/blob/master/lib/gradelib.php#L61
protected function _grade_update() {
$gradestructure = [
'userid' => $this->userid,
'rawgrade' => 100.00,
'finalgrade' => 100.00,
'feedback' => '[auto-submit]' . __CLASS__,
'feedbackformat' => FORMAT_MOODLE, // '1'.
'datesubmitted' => time(),
'dategraded' => time(),
];
$result = \grade_update('mod/assign', $this->course_id, 'mod', 'assign', $this->activity_id, 0, $gradestructure, null); // Not: 'grade_items_id'

self::debug([ __FUNCTION__, 'mod/assign', $this->activity_id, $result, GRADE_UPDATE_OK == $result ? 'OK' : 'FAIL' ]);
}

public function get_course_modules_completion() {
global $DB;
return $DB->get_record('course_modules_completion', [
Expand Down
4 changes: 4 additions & 0 deletions classes/user_event_observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

class user_event_observer extends base {

public static function core_module_completed($event) {
self::debug(__METHOD__);
}

public static function core_user_created($event) {

// TODO: Enroll the user on course!
Expand Down
4 changes: 4 additions & 0 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
'eventname' => '\mod_quiz\event\attempt_submitted',
'callback' => '\auth_ouopenid\user_event_observer::embed_event_data',
],
[
'eventname' => '\core\event\course_module_completion_updated',
'callback' => '\auth_ouopenid\user_event_observer::core_module_completed',
],
];

//End.
1 change: 1 addition & 0 deletions survey-end/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

require_once($CFG->dirroot . '/lib/completionlib.php');
require_once($CFG->dirroot . '/lib/modinfolib.php');
require_once($CFG->dirroot . '/lib/gradelib.php');

use auth_ouopenid\local\conditional_embedded_survey;
use auth_ouopenid\local\tesla_consent;
Expand Down

0 comments on commit c315dd8

Please sign in to comment.