Skip to content

Commit

Permalink
MDL-67132 mod_lti: call grade api to trigger course total computation
Browse files Browse the repository at this point in the history
  • Loading branch information
claudevervoort authored and stronk7 committed Feb 26, 2020
1 parent f05ff7a commit dc39cee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
11 changes: 7 additions & 4 deletions lib/grade/grade_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,10 @@ public function refresh_grades($userid=0) {
* @param int $usermodified The ID of the user making the modification
* @return bool success
*/
public function update_final_grade($userid, $finalgrade=false, $source=NULL, $feedback=false, $feedbackformat=FORMAT_MOODLE, $usermodified=null) {
public function update_final_grade($userid, $finalgrade = false,
$source = null, $feedback = false,
$feedbackformat = FORMAT_MOODLE,
$usermodified = null, $timemodified = null) {
global $USER, $CFG;

$result = true;
Expand Down Expand Up @@ -1789,8 +1792,8 @@ public function update_final_grade($userid, $finalgrade=false, $source=NULL, $fe

$gradechanged = false;
if (empty($grade->id)) {
$grade->timecreated = null; // hack alert - date submitted - no submission yet
$grade->timemodified = time(); // hack alert - date graded
$grade->timecreated = null; // Hack alert - date submitted - no submission yet.
$grade->timemodified = $timemodified ?: time(); // Hack alert - date graded.
$result = (bool)$grade->insert($source);

// If the grade insert was successful and the final grade was not null then trigger a user_graded event.
Expand All @@ -1814,7 +1817,7 @@ public function update_final_grade($userid, $finalgrade=false, $source=NULL, $fe
return $result;
}

$grade->timemodified = time(); // hack alert - date graded
$grade->timemodified = $timemodified?:time(); // Hack alert - date graded.
$result = $grade->update($source);

// If the grade update was successful and the actual grade has changed then trigger a user_graded event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,23 +381,18 @@ public function save_grade_item($gradeitem, $score, $userid) {
$feedbackformat = FORMAT_PLAIN;
}

if (!$grade = \grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $userid))) {
$grade = new \grade_grade();
$grade->userid = $userid;
$grade->itemid = $gradeitem->id;
}
$grade->rawgrademax = $score->scoreMaximum;
$grade->timemodified = $timemodified;
$grade->feedbackformat = $feedbackformat;
$grade->feedback = $feedback;
if ($gradeitem->is_manual_item()) {
$grade->finalgrade = $finalgrade;
if (empty($grade->id)) {
$result = (bool)$grade->insert($source);
} else {
$result = $grade->update($source);
}
$result = $gradeitem->update_final_grade($userid, $finalgrade, null, $feedback, FORMAT_PLAIN, null, $timemodified);
} else {
if (!$grade = \grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $userid))) {
$grade = new \grade_grade();
$grade->userid = $userid;
$grade->itemid = $gradeitem->id;
}
$grade->rawgrademax = $score->scoreMaximum;
$grade->timemodified = $timemodified;
$grade->feedbackformat = $feedbackformat;
$grade->feedback = $feedback;
$grade->rawgrade = $finalgrade;
$status = \grade_update($source, $gradeitem->courseid,
$gradeitem->itemtype, $gradeitem->itemmodule,
Expand Down

0 comments on commit dc39cee

Please sign in to comment.