Merge branch 'MDL-67132-LTI-Adv-TriggerCalc' of https://github.com/cengage/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2020-02-26 17:15:50 +01:00
commit bc418341fe
3 changed files with 20 additions and 20 deletions

View File

@ -1732,9 +1732,13 @@ class grade_item extends grade_object {
* @param string $feedback Optional teacher feedback
* @param int $feedbackformat A format like FORMAT_PLAIN or FORMAT_HTML
* @param int $usermodified The ID of the user making the modification
* @param int $timemodified Optional parameter to set the time modified, if not present current time.
* @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;
@ -1800,8 +1804,8 @@ class grade_item extends grade_object {
$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.
@ -1825,7 +1829,7 @@ class grade_item extends grade_object {
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.

View File

@ -33,6 +33,7 @@ information provided here is intended especially for developers.
They have to implement fetch_columns instead.
* Added function cleanup_after_drop to the database_manager class to take care of all the cleanups that need to be done after a table is dropped.
* The 'xxxx_check_password_policy' callback now only fires if $CFG->passwordpolicy is true
* grade_item::update_final_grade() can now take an optional parameter to set the grade->timemodified. If not present the current time will carry on being used.
=== 3.8 ===
* Add CLI option to notify all cron tasks to stop: admin/cli/cron.php --stop

View File

@ -381,25 +381,20 @@ class gradebookservices extends service_base {
$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,
$status = grade_update($source, $gradeitem->courseid,
$gradeitem->itemtype, $gradeitem->itemmodule,
$gradeitem->iteminstance, $gradeitem->itemnumber,
$grade);