Skip to content

Commit

Permalink
MDL-9317 Applying Petr's second patch
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed May 29, 2007
1 parent e72be05 commit de420c1
Show file tree
Hide file tree
Showing 16 changed files with 575 additions and 271 deletions.
8 changes: 4 additions & 4 deletions admin/cron.php
Expand Up @@ -261,11 +261,11 @@
}
}

// attemps to grab grades from third party/non-stard mods, or mods with no event
// implemented for 1.9 and above.
mtrace("Grabbing grades from modules if required...");
// attemps to grab grades from third party/non-stard mods that still have xxx_grades() in lib.php
// which was obsoleted in 1.9.
mtrace("Grabbing grades from older modules if required...");
include_once($CFG->dirroot.'/lib/gradelib.php');
grades_grab_grades();
grade_grab_legacy_grades();

} // End of occasional clean-up tasks

Expand Down
2 changes: 1 addition & 1 deletion grade/import/csv/index.php
Expand Up @@ -109,7 +109,7 @@
$eventdata->idnumber = $idnumber;
$eventdata->userid = $studentid;
$eventdata->gradevalue = $studentgrade;
events_trigger('grade_added', $eventdata);
events_trigger('grade_updated_external', $eventdata);

debugging("triggering event for $idnumber... student id is $studentid and grade is $studentgrade");
}
Expand Down
2 changes: 1 addition & 1 deletion grade/import/xml/index.php
Expand Up @@ -60,7 +60,7 @@
$eventdata->userid = $result['#']['student'][0]['#'];
$eventdata->gradevalue = $result['#']['score'][0]['#'];

trigger_event('grade_added', $eventdata);
trigger_event('grade_updated_external', $eventdata);
echo "<br/>triggering event for $eventdata->idnumber... student id is $eventdata->userid and grade is $eventdata->gradevalue";
}
}
Expand Down
39 changes: 37 additions & 2 deletions lib/db/events.php
Expand Up @@ -26,8 +26,43 @@
///////////////////////////////////////////////////////////////////////////


$events = array (
'grade_added' => array ( // All new grades get processed immediately by the gradebook
$handlers = array (

/*
* Grades added by activities
*
* required parameters (object or array):
* itemid - if from grade_items table, grade item must already exist
* userid - each grade must be associated to existing user
*
* optional params:
* gradevalue - raw grade value
* feedback - graders feedback
* feedbackformat - text format of the feedback
*/
'grade_updated' => array (
'handlerfile' => '/lib/gradelib.php',
'handlerfunction' => 'grade_handler',
'schedule' => 'instant'
),

/*
* Grades created/modified outside of activities (import, gradebook overrides, etc.)
*
* required parameters (object or array):
* itemid - id from grade_items table, grade item must already exist
* userid - each grade must be associated with existing user
*
* optional params:
* gradevalue - raw grade value
* feedback - graders feedback
* feedbackformat - text format of the feedback
*
* optional params (improves performance):
* itemtype - mod, block
* itemmodule - assignment, etc.
*/
'grade_updated_external' => array (
'handlerfile' => '/lib/gradelib.php',
'handlerfunction' => 'grade_handler',
'schedule' => 'instant'
Expand Down
4 changes: 2 additions & 2 deletions lib/db/install.xml
Expand Up @@ -1189,10 +1189,10 @@
<INDEX NAME="mnethostid_username" UNIQUE="true" FIELDS="mnet_host_id, username"/>
</INDEXES>
</TABLE>
<TABLE NAME="events_handlers" COMMENT="This table is for storing which components requests what type of event, and the location of the responsible handlers. For example, the grade book can register 'grade_added' event with a function add_grade() that should be called event time an 'grade_added' event is triggered by a module." PREVIOUS="mnet_sso_access_control" NEXT="events_queue">
<TABLE NAME="events_handlers" COMMENT="This table is for storing which components requests what type of event, and the location of the responsible handlers. For example, the grade book can register 'grade_updated' event with a function grade_handler() that should be called event time an 'grade_updated' event is triggered by a module." PREVIOUS="mnet_sso_access_control" NEXT="events_queue">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="eventname"/>
<FIELD NAME="eventname" TYPE="char" LENGTH="166" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="name of the event, e.g. 'grade_added'" PREVIOUS="id" NEXT="handlermodule"/>
<FIELD NAME="eventname" TYPE="char" LENGTH="166" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="name of the event, e.g. 'grade_updated'" PREVIOUS="id" NEXT="handlermodule"/>
<FIELD NAME="handlermodule" TYPE="char" LENGTH="166" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="e.g. moodle, mod/forum, block/rss_client" PREVIOUS="eventname" NEXT="handlerfile"/>
<FIELD NAME="handlerfile" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="path to the file of the function, eg /grade/export/lib.php" PREVIOUS="handlermodule" NEXT="handlerfunction"/>
<FIELD NAME="handlerfunction" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="serialized string or array describing function, suitable to be passed to call_user_func()" PREVIOUS="handlerfile" NEXT="schedule"/>
Expand Down
4 changes: 2 additions & 2 deletions lib/eventslib.php
Expand Up @@ -53,13 +53,13 @@ function events_load_def($component) {
}
}

$events = array(); // TODO: $handlers might be better here ;-)
$handlers = array();

if (file_exists($defpath)) {
require($defpath);
}

return $events;
return $handlers;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/grade/grade_object.php
Expand Up @@ -107,7 +107,7 @@ function delete() {
function insert() {
global $USER;

if (!empty($this->id)) { // Object already exists, so let's do an update instead
if (!empty($this->id)) {
debugging("Grade object already exists!");
return false;
}
Expand All @@ -120,7 +120,7 @@ function insert() {

$clonethis = fullclone($this);

// Unset non-set fields
// Unset non-set and null fields
foreach ($clonethis as $var => $val) {
if (!isset($val)) {
unset($clonethis->$var);
Expand Down

0 comments on commit de420c1

Please sign in to comment.