Is there a problem with re-purposing grade_grades 'feedbackformat' for some activities?

Is there a problem with re-purposing grade_grades 'feedbackformat' for some activities?

by Matt Bury -
Number of replies: 0
Picture of Plugin developers
Hi,

I'm working with Flash activities that push grades into the grade book via the SWF Activity Module. One thing that Flash can do very well, is monitor the time that users are actively using a learning application, i.e. if the user doesn't touch the mouse for a while, we can assume that they've gone for a tea-break or something else.

I'm look for a place to store this and show user time, in seconds, on each activity on an accumulative basis and showing it as weeks, days, hourse, minutes and seconds on a grade report. What I've done is to push the elapsed time into grade_grades 'feedbackformat' for such activities. This gives up to 9,999,999,999 seconds for each activity, or over 16,500 weeks, which I think is ample. I have this system up and running quite nicely so far without any hacks or changes to Moodle's code.

My question is, will this adversely affect the grade book in some way? Do numbers stored in the feedbackformat column have to conform to some kind of protocol?

Here's the code in moodle/lib/amfphp/services/Grades.php::swf_update_grade(). I'm still playing with it so it's a bit messy and by no means finished:

/**
*
* @param obj->instance int course instance ID
* @param obj->swfid int swf instance ID
* @param obj->feedback int/text feedback for user either elapsed time in seconds or text
* @param obj->feedbackformat int format of feedback
* @param obj->rawgrade int grade before calculation as a percentage, scale, etc.
* @return array of grade information objects (scaleid, name, grade and locked status, etc.) indexed with itemnumbers
*/
public function amf_grade_update($obj)
{
// Dummy values for testing in service browser
$obj['instance'] = 3;
$obj['swfid'] = 2;
$obj['feedback'] = '

Some more feedback... I think this can get pretty long and include whatever someone really wants to send to the server to be stored in the grade_grades table. I\'m really not sure how useful this\'ll be but I\'ll include it anyway: '.rand().'

';
$obj['feedbackformat'] = rand(29,3800);
$obj['rawgrade'] = rand(0,100);

// Get current user's capabilities
$capabilities = $this->access->get_capabilities($obj['instance'],$obj['swfid']);
// Make sure they have permission to call this function
if ($capabilities->is_logged_in && $capabilities->view_own_grades)
{
global $CFG;
global $USER;

require_once($CFG->libdir.'/gradelib.php');

// Get grade item for grademax and grademin values
// If SWF mod instance gradetype is set to none, no grade item is created
if(!$record = get_record('grade_items','iteminstance',$obj['swfid']))
{
// Send error string back to Flash client
return 'Grade item '.$obj['swfid'].' does not exist.';
}

$obj['rawgrademax'] = $record->grademax;
$obj['rawgrademin'] = $record->grademin;
$obj['timemodified'] = time();
$obj['userid'] = $USER->id;
$obj['usermodified'] = $USER->id;

// Get previous grade if it exists
$result = grade_get_grades($capabilities->course, 'mod', 'swf', $obj['swfid'], $obj['userid']);

// We're using feebackformat to record users' elapsed time on SWF activities
$feedbackformat = $result->items[0]->grades[$obj['userid']]->feedbackformat;
$obj['feedbackformat'] += $feedbackformat;
//$obj['feedbackformat'] = 9999999999;

// Insert or update grade
grade_update('mod/swf', $capabilities->course, 'mod', 'swf', $obj['swfid'], 0, $obj, NULL);

// Return updated grade item
return grade_get_grades($capabilities->course, 'mod', 'swf', $obj['swfid'], $obj['userid']);
}
}