MDL-41101 mod_assign: replaced 'grade submission' add_to_log call with an event
authorMark Nelson <markn@moodle.com>
Thu, 3 Apr 2014 04:25:06 +0000 (21:25 -0700)
committerPetr Skoda <skodak@mujMac.local>
Thu, 17 Apr 2014 01:51:11 +0000 (09:51 +0800)
mod/assign/feedback/offline/locallib.php
mod/assign/locallib.php
mod/assign/tests/events_test.php

index c47d036..d2ead7c 100644 (file)
@@ -166,7 +166,6 @@ class assign_feedback_offline extends assign_feedback_plugin {
                 $grade->grader = $USER->id;
                 if ($this->assignment->update_grade($grade)) {
                     $this->assignment->notify_grade_modified($grade);
-                    $this->assignment->add_to_log('grade submission', $this->assignment->format_grade_for_log($grade));
                     $updatecount += 1;
                 }
             }
index 42b6b5e..48fbd93 100644 (file)
@@ -1837,6 +1837,15 @@ class assign {
 
         if ($result) {
             $this->gradebook_item_update(null, $grade);
+
+            $params = array(
+                'context' => $this->context,
+                'objectid' => $grade->id,
+                'relateduserid' => $grade->userid
+            );
+            $event = \mod_assign\event\submission_graded::create($params);
+            $event->set_legacy_logdata('grade submission', $this->format_grade_for_log($grade));
+            $event->trigger();
         }
         return $result;
     }
@@ -5248,15 +5257,6 @@ class assign {
                                           $data);
                 }
             }
-
-            $params = array(
-                'context' => $this->context,
-                'objectid' => $grade->id,
-                'relateduserid' => $userid
-            );
-            $event = \mod_assign\event\submission_graded::create($params);
-            $event->set_legacy_logdata('grade submission', $this->format_grade_for_log($grade));
-            $event->trigger();
         }
 
         return get_string('quickgradingchangessaved', 'assign');
@@ -6528,15 +6528,6 @@ class assign {
         if (!isset($formdata->sendstudentnotifications) || $formdata->sendstudentnotifications) {
             $this->notify_grade_modified($grade);
         }
-
-        $params = array(
-            'context' => $this->context,
-            'objectid' => $grade->id,
-            'relateduserid' => $userid
-        );
-        $event = \mod_assign\event\submission_graded::create($params);
-        $event->set_legacy_logdata('grade submission', $this->format_grade_for_log($grade));
-        $event->trigger();
     }
 
 
index e73cb8e..efdc027 100644 (file)
@@ -291,8 +291,8 @@ class assign_events_testcase extends mod_assign_base_testcase {
         $assign->revert_to_draft($this->students[0]->id);
 
         $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
+        $this->assertCount(2, $events);
+        $event = $events[1];
         $this->assertInstanceOf('\mod_assign\event\submission_status_updated', $event);
         $this->assertEquals($assign->get_context(), $event->get_context());
         $this->assertEquals($submission->id, $event->objectid);
@@ -505,6 +505,32 @@ class assign_events_testcase extends mod_assign_base_testcase {
         );
         $this->assertEventLegacyLogData($expected, $event);
         $sink->close();
+
+        // Test update_grade.
+        $sink = $this->redirectEvents();
+        $data = clone($grade);
+        $data->grade = '50.0';
+        $assign->update_grade($data);
+        $grade = $assign->get_user_grade($this->students[0]->id, false, 0);
+        $this->assertEquals('50.0', $grade->grade);
+        $events = $sink->get_events();
+
+        $this->assertCount(1, $events);
+        $event = reset($events);
+        $this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEquals($grade->id, $event->objectid);
+        $this->assertEquals($this->students[0]->id, $event->relateduserid);
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'grade submission',
+            'view.php?id=' . $assign->get_course_module()->id,
+            $assign->format_grade_for_log($grade),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $sink->close();
     }
 
     /**