diff --git a/lib/accesslib.php b/lib/accesslib.php index fd2304bf783..2d0d36ea341 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2292,11 +2292,11 @@ function role_unassign($roleid=0, $userid=0, $groupid=0, $contextid=0, $enrol=NU */ function enrol_into_course($course, $user, $enrol) { + $timestart = time(); if ($course->enrolperiod) { - $timestart = time(); $timeend = time() + $course->enrolperiod; } else { - $timestart = $timeend = 0; + $timeend = 0; } if ($role = get_default_course_role($course)) { diff --git a/lib/eventslib.php b/lib/eventslib.php index 2a598d0edaa..c32bdc3fb68 100755 --- a/lib/eventslib.php +++ b/lib/eventslib.php @@ -216,7 +216,7 @@ function trigger_event($eventname, $eventdata) { // if event type is if ($handler->schedule == 'instant') { - if (dispatch_event($handler, $eventdata->eventdata)) { + if (dispatch_event($handler, $eventdata)) { continue; } else { // update the failed flag @@ -249,7 +249,7 @@ function trigger_event($eventname, $eventdata) { * @return bool - success or fail */ function dispatch_event($handler, $eventdata) { - + global $CFG; // checks for handler validity diff --git a/lib/gradelib.php b/lib/gradelib.php index f2179d0018a..6cd222931c8 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -201,7 +201,18 @@ function grades_grab_grades() { foreach ($grades->grades as $userid=>$usergrade) { // make the grade_added eventdata // missing grade event trigger - // trigger_event('grade_added', $eventdata); + // trigger_event('grade_added', $eventdata); + unset($eventdata); + $eventdata->courseid = $modinstance->course; + $eventdata->itemmodule = $mod; + $eventdata->iteminstance = $modinstance->instance; + $eventdata->gradetype = 0; + $eventdata->userid = $userid; + $eventdata->gradevalue = $usergrade; + + print_object($eventdata); + trigger_event('grade_added', $eventdata); + } } } @@ -242,8 +253,6 @@ function standardise_score($gradevalue, $source_min, $source_max, $target_min, $ /* * Handles all grade_added and grade_updated events * - * INCOMPLETE - * * @param object $eventdata contains all the data for the event * @return boolean success * @@ -252,6 +261,7 @@ function grade_handler($eventdata) { /// First let's make sure a grade_item exists for this grade $gradeitem = new grade_item($eventdata); + if (empty($gradeitem->id)) { // Doesn't exist yet if (!$gradeitem->id = $gradeitem->insert()) { // Try to create a new item... debugging('Could not create a grade_item!'); @@ -261,10 +271,9 @@ function grade_handler($eventdata) { $eventdata->itemid = $gradeitem->id; - /// Grade_item exists, now we can insert the new raw grade - $rawgrade = new grade_grade_raw($eventdata); + $rawgrade = new grade_grades_raw($eventdata); if ($rawgrade->id) { $rawgrade->update($eventdata->gradevalue, 'event'); diff --git a/lib/simpletest/testeventslib.php b/lib/simpletest/testeventslib.php index 2319a7802e5..f6ce9250ec0 100755 --- a/lib/simpletest/testeventslib.php +++ b/lib/simpletest/testeventslib.php @@ -10,6 +10,7 @@ require_once($CFG->libdir . '/dmllib.php'); // dummy test function function plusone($eventdata) { + return $eventdata+1; } @@ -59,9 +60,10 @@ class eventslib_test extends UnitTestCase { $eventdata->schedule = 'instant'; $eventid = insert_record('events_queue', $eventdata); - + $id = queue_handler($this->handler, $eventid); $storedhandler = get_record('events_queue_handlers', 'id', $id); + $retval = events_process_queued_handler($storedhandler); $this->assertEqual(2, $retval); $this->storedhandler = $storedhandler; @@ -78,9 +80,7 @@ class eventslib_test extends UnitTestCase { * tests trigger_event funtion() */ function test_trigger_event() { - $eventdata = new object; - $eventdata->eventdata = 2; - $eventdata->schedule = 'instant'; + $eventdata = 2; $this->assertEqual(0, trigger_event('testevent', $eventdata)); }