mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
some changes to events to make grade_added work
This commit is contained in:
parent
3b98c475cd
commit
9492291c82
@ -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)) {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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');
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user