public function testable_process_set_batch_marking_workflow_state($selectedusers, $state) { global $CFG; require_once $CFG->dirroot . '/mod/sepl/batchsetmarkingworkflowstateform.php'; // Simulate the form submission. $data = array(); $data['id'] = $this->get_course_module()->id; $data['selectedusers'] = $selectedusers; $data['markingworkflowstate'] = $state; $data['action'] = 'setbatchmarkingworkflowstate'; mod_sepl_batch_set_marking_workflow_state_form::mock_submit($data); return parent::process_set_batch_marking_workflow_state(); }
/** * Set the workflow state for multiple users * * @return void */ protected function process_set_batch_marking_workflow_state() { global $CFG, $DB; // Include batch marking workflow form. require_once $CFG->dirroot . '/mod/sepl/batchsetmarkingworkflowstateform.php'; $formparams = array('userscount' => 0, 'usershtml' => '', 'markingworkflowstates' => $this->get_marking_workflow_states_for_current_user()); $mform = new mod_sepl_batch_set_marking_workflow_state_form(null, $formparams); if ($mform->is_cancelled()) { return true; } if ($formdata = $mform->get_data()) { $useridlist = explode(',', $formdata->selectedusers); $state = $formdata->markingworkflowstate; foreach ($useridlist as $userid) { $flags = $this->get_user_flags($userid, true); $flags->workflowstate = $state; // Clear the mailed flag if notification is requested, the student hasn't been // notified previously, the student can access the seplment, and the state // is "Released". $modinfo = get_fast_modinfo($this->course, $userid); $cm = $modinfo->get_cm($this->get_course_module()->id); if ($formdata->sendstudentnotifications && $cm->uservisible && $state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { $flags->mailed = 0; } $gradingdisabled = $this->grading_disabled($userid); // Will not apply update if user does not have permission to sepl this workflow state. if (!$gradingdisabled && $this->update_user_flags($flags)) { if ($state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { // Update Gradebook. $sepl = clone $this->get_instance(); $sepl->cmidnumber = $this->get_course_module()->idnumber; // Set sepl gradebook feedback plugin status. $sepl->gradefeedbackenabled = $this->is_gradebook_feedback_enabled(); sepl_update_grades($sepl, $userid); } $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); \mod_sepl\event\workflow_state_updated::create_from_user($this, $user, $state)->trigger(); } } } }