Gradebook

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

Hi Mitchell

Did you ever get to the bottom of this?

I'm having exactly the same problem, I use the following code to create a grade in the gradebook.

$grade = new stdClass();

$grade->userid   = 'userid';

$grade->rawgrade = '100';
   

assign_grade_item_update('assignment', $grade);

It appears in the gradebook fine, but when a teacher goes to manually grade the assignment through the assignment link the grade doesn't appear.

As you have highlighted there is no submission for the grade in the 'assign_grades' table which I assume is the problem. I haven't yet found a method for adding the grade to both the gradebook and the assign_grades. You would assume the function 'assign_grade_item' would grade the assignment not just the gradebook.

Does anyone have any ideas?

Steve

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