MDL-48574 assign: Fire workflow_state_updated event on batch and single.
authorDavid Balch <david.balch@conted.ox.ac.uk>
Thu, 11 Dec 2014 12:21:50 +0000 (12:21 +0000)
committerDavid Balch <david.balch@conted.ox.ac.uk>
Wed, 7 Jan 2015 13:57:03 +0000 (13:57 +0000)
This change adds the workflow_state_updated event when changing workflow
state using the single grading page and the quick grading mechanisms.
Previously, it only fired for batch updates using
process_set_batch_marking_workflow_state().

mod/assign/locallib.php

index 4a6aa93..8c7f0e6 100644 (file)
@@ -5380,7 +5380,10 @@ class assign {
                 $flags->allocatedmarker = $modified->allocatedmarker;
             }
             if ($workflowstatemodified || $allocatedmarkermodified) {
-                $this->update_user_flags($flags);
+                if ($this->update_user_flags($flags) && $workflowstatemodified) {
+                    $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
+                    \mod_assign\event\workflow_state_updated::create_from_user($this, $user, $flags->workflowstate)->trigger();
+                }
             }
             $this->update_grade($grade);
 
@@ -6625,9 +6628,15 @@ class assign {
             }
             if (isset($formdata->workflowstate) || isset($formdata->allocatedmarker)) {
                 $flags = $this->get_user_flags($userid, true);
+                $oldworkflowstate = $flags->workflowstate;
                 $flags->workflowstate = isset($formdata->workflowstate) ? $formdata->workflowstate : $flags->workflowstate;
                 $flags->allocatedmarker = isset($formdata->allocatedmarker) ? $formdata->allocatedmarker : $flags->allocatedmarker;
-                $this->update_user_flags($flags);
+                if ($this->update_user_flags($flags) &&
+                        isset($formdata->workflowstate) &&
+                        $formdata->workflowstate !== $oldworkflowstate) {
+                    $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
+                    \mod_assign\event\workflow_state_updated::create_from_user($this, $user, $formdata->workflowstate)->trigger();
+                }
             }
         }
         $grade->grader= $USER->id;