/** * Process workflow state update called by event trigger (see db/events.php). * It unlocks pages on Mahara when grades are released to students. * * @param object $event Event data object passed over by mod_assign * @return void */ public static function workflow_state_updated(\mod_assign\event\workflow_state_updated $event) { global $DB; $eventdata = $event->get_data(); $assign = $event->get_assign(); $maharasubmissionplugin = $assign->get_submission_plugin_by_type('mahara'); // See if need to unlock anything at all. if ((int) $maharasubmissionplugin->get_config('lock') !== ASSIGNSUBMISSION_MAHARA_SETTING_UNLOCK) { return; } // Get submission if it exists. if (!($submission = $assign->get_user_submission($eventdata['relateduserid'], false))) { return; } // Get Mahara submission. $maharasubmission = $DB->get_record('assignsubmission_mahara', array('submission' => $submission->id)); // Process further only if we are dealing with mahara submission that is locked. if ($maharasubmission && $maharasubmission->viewstatus == assign_submission_mahara::STATUS_SUBMITTED) { // Check marking workflow state, only unlock page if marks are released. if ($eventdata['other']['newstate'] !== ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { return; } self::release_submited_view($maharasubmissionplugin, $maharasubmission); } }
/** * Set the workflow state for multiple users * * @return void */ protected function process_set_batch_marking_workflow_state() { global $DB; require_sesskey(); $batchusers = required_param('selectedusers', PARAM_TEXT); $state = required_param('markingworkflowstate', PARAM_ALPHA); $useridlist = explode(',', $batchusers); foreach ($useridlist as $userid) { $flags = $this->get_user_flags($userid, true); $flags->workflowstate = $state; $gradingdisabled = $this->grading_disabled($userid); // Will not apply update if user does not have permission to assign this workflow state. if (!$gradingdisabled && $this->update_user_flags($flags)) { if ($state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { // Update Gradebook. $assign = clone $this->get_instance(); $assign->cmidnumber = $this->get_course_module()->idnumber; assign_update_grades($assign, $userid); } $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); $params = array('id' => $user->id, 'fullname' => fullname($user), 'state' => $state); $message = get_string('setmarkingworkflowstateforlog', 'assign', $params); $addtolog = $this->add_to_log('set marking workflow state', $message, '', true); $params = array('context' => $this->context, 'objectid' => $this->get_instance()->id, 'relateduserid' => $userid, 'other' => array('newstate' => $state)); $event = \mod_assign\event\workflow_state_updated::create($params); $event->set_legacy_logdata($addtolog); $event->trigger(); } } }
/** * Apply a grade from a grading form to a user (may be called multiple times for a group submission). * * @param stdClass $formdata - the data from the form * @param int $userid - the user to apply the grade to * @param int $attemptnumber - The attempt number to apply the grade to. * @return void */ protected function apply_grade_to_user($formdata, $userid, $attemptnumber) { global $USER, $CFG, $DB; $grade = $this->get_user_grade($userid, true, $attemptnumber); $originalgrade = $grade->grade; $gradingdisabled = $this->grading_disabled($userid); $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled); if (!$gradingdisabled) { if ($gradinginstance) { $grade->grade = $gradinginstance->submit_and_get_grade($formdata->advancedgrading, $grade->id); } else { // Handle the case when grade is set to No Grade. if (isset($formdata->grade)) { $grade->grade = grade_floatval(unformat_float($formdata->grade)); } } 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; 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; $adminconfig = $this->get_admin_config(); $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook; // Call save in plugins. foreach ($this->feedbackplugins as $plugin) { if ($plugin->is_enabled() && $plugin->is_visible()) { if (!$plugin->save($grade, $formdata)) { $result = false; print_error($plugin->get_error()); } if ('assignfeedback_' . $plugin->get_type() == $gradebookplugin) { // This is the feedback plugin chose to push comments to the gradebook. $grade->feedbacktext = $plugin->text_for_gradebook($grade); $grade->feedbackformat = $plugin->format_for_gradebook($grade); } } } // We do not want to update the timemodified if no grade was added. if (!empty($formdata->addattempt) || $originalgrade !== null && $originalgrade != -1 || $grade->grade !== null && $grade->grade != -1) { $this->update_grade($grade, !empty($formdata->addattempt)); } // Note the default if not provided for this option is true (e.g. webservices). // This is for backwards compatibility. if (!isset($formdata->sendstudentnotifications) || $formdata->sendstudentnotifications) { $this->notify_grade_modified($grade, true); } }
/** * 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/assign/batchsetmarkingworkflowstateform.php'; $formparams = array('userscount' => 0, 'usershtml' => '', 'markingworkflowstates' => $this->get_marking_workflow_states_for_current_user()); $mform = new mod_assign_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; $gradingdisabled = $this->grading_disabled($userid); // Will not apply update if user does not have permission to assign this workflow state. if (!$gradingdisabled && $this->update_user_flags($flags)) { if ($state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { // Update Gradebook. $assign = clone $this->get_instance(); $assign->cmidnumber = $this->get_course_module()->idnumber; // Set assign gradebook feedback plugin status. $assign->gradefeedbackenabled = $this->is_gradebook_feedback_enabled(); assign_update_grades($assign, $userid); } $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); $params = array('id' => $user->id, 'fullname' => fullname($user), 'state' => $state); $message = get_string('setmarkingworkflowstateforlog', 'assign', $params); $addtolog = $this->add_to_log('set marking workflow state', $message, '', true); $params = array('context' => $this->context, 'objectid' => $this->get_instance()->id, 'relateduserid' => $userid, 'other' => array('newstate' => $state)); $event = \mod_assign\event\workflow_state_updated::create($params); $event->set_legacy_logdata($addtolog); $event->trigger(); } } } }
/** * 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/assign/batchsetmarkingworkflowstateform.php'; $formparams = array('userscount' => 0, 'usershtml' => '', 'markingworkflowstates' => $this->get_marking_workflow_states_for_current_user()); $mform = new mod_assign_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 assignment, 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 assign this workflow state. if (!$gradingdisabled && $this->update_user_flags($flags)) { if ($state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { // Update Gradebook. $assign = clone $this->get_instance(); $assign->cmidnumber = $this->get_course_module()->idnumber; // Set assign gradebook feedback plugin status. $assign->gradefeedbackenabled = $this->is_gradebook_feedback_enabled(); assign_update_grades($assign, $userid); } $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); \mod_assign\event\workflow_state_updated::create_from_user($this, $user, $state)->trigger(); } } } }
/** * 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/assign/batchsetmarkingworkflowstateform.php'); $formparams = array( 'userscount' => 0, // This form is never re-displayed, so we don't need to 'usershtml' => '', // initialise these parameters with real information. 'markingworkflowstates' => $this->get_marking_workflow_states_for_current_user() ); $mform = new mod_assign_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; $gradingdisabled = $this->grading_disabled($userid); // Will not apply update if user does not have permission to assign this workflow state. if (!$gradingdisabled && $this->update_user_flags($flags)) { if ($state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { // Update Gradebook. $assign = clone $this->get_instance(); $assign->cmidnumber = $this->get_course_module()->idnumber; // Set assign gradebook feedback plugin status. $assign->gradefeedbackenabled = $this->is_gradebook_feedback_enabled(); assign_update_grades($assign, $userid); } $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); \mod_assign\event\workflow_state_updated::create_from_user($this, $user, $state)->trigger(); } } } }