Gradebook

 
 
Picture of Stephen Hooley
Re: Grade mirrored in assign_grades and grade_grades
 

Hi again

 

The following code does the job creates the grade in both assign_grades and grade_grades.

global $DB, $USER;
require_once($CFG->dirroot.'/mod/assign/lib.php');
$grade = new stdClass();
$grade->assignment = 'assignment';
$grade->userid = 'userid';
$grade->timecreated = time();
$grade->timemodified = $grade->timecreated;
$grade->grader = $USER->id;
$grade->grade = '100';
$grade->locked = 0;
$grade->mailed = 0;   
//check if grade exists if so overwrite instead of adding a new one 
$checkIfGraded = $DB->get_record('assign_grades', array('userid'=>$grade->userid, 'assignment'=>$grade->assignment));

if($checkIfGraded){
         $result = $DB->update_record('assign_grades', $grade);
} else {
         $result = $DB->insert_record('assign_grades', $grade);
}
   
if ($result) {
         $grade2 = new stdClass();
         $grade2->userid   = $grade->userid; $grade2->rawgrade = $grade->grade;
$grade2->usermodified = $grade->grader;
         $grade2->datesubmitted = NULL;
         $grade2->dategraded = $grade->timemodified;
         //$grade2->feedbackformat = '';
         //$grade2->feedback = '';

         assign_grade_item_update('assignment', $grade2);
}

 

If anyone has any observation they would be appreciated?


Regards

 

Steve