/** * Save assignment submission. * * @param moodleform $mform * @param array $notices Any error messages that should be shown * to the user at the top of the edit submission form. * @return bool */ protected function process_save_submission(&$mform, &$notices) { global $CFG; // Include submission form. require_once $CFG->dirroot . '/mod/assign/submission_form.php'; // Need submit permission to submit an assignment. require_sesskey(); if (!$this->submissions_open()) { $notices[] = get_string('duedatereached', 'assign'); return false; } $instance = $this->get_instance(); $data = new stdClass(); $mform = new mod_assign_submission_form(null, array($this, $data)); if ($mform->is_cancelled()) { return true; } if ($data = $mform->get_data()) { return $this->save_submission($data, $notices); } return false; }
/** * save assignment submission * * @param moodleform $mform * @return bool */ private function process_save_submission(&$mform) { global $USER, $CFG; // Include submission form require_once($CFG->dirroot . '/mod/assign/submission_form.php'); // Need submit permission to submit an assignment require_capability('mod/assign:submit', $this->context); require_sesskey(); $data = new stdClass(); $mform = new mod_assign_submission_form(null, array($this, $data)); if ($mform->is_cancelled()) { return true; } if ($data = $mform->get_data()) { if ($this->get_instance()->teamsubmission) { $submission = $this->get_group_submission($USER->id, 0, true); } else { $submission = $this->get_user_submission($USER->id, true); } if ($this->get_instance()->submissiondrafts) { $submission->status = ASSIGN_SUBMISSION_STATUS_DRAFT; } else { $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; } $grade = $this->get_user_grade($USER->id, false); // get the grade to check if it is locked if ($grade && $grade->locked) { print_error('submissionslocked', 'assign'); return true; } foreach ($this->submissionplugins as $plugin) { if ($plugin->is_enabled()) { if (!$plugin->save($submission, $data)) { print_error($plugin->get_error()); } } } $this->update_submission($submission, $USER->id, true, $this->get_instance()->teamsubmission); // Logging if (isset($data->submissionstatement)) { $this->add_to_log('submission statement accepted', get_string('submissionstatementacceptedlog', 'mod_assign', fullname($USER))); } $this->add_to_log('submit', $this->format_submission_for_log($submission)); $complete = COMPLETION_INCOMPLETE; if ($submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) { $complete = COMPLETION_COMPLETE; } $completion = new completion_info($this->get_course()); if ($completion->is_enabled($this->get_course_module()) && $this->get_instance()->completionsubmit) { $completion->update_state($this->get_course_module(), $complete, $USER->id); } if (!$this->get_instance()->submissiondrafts) { $this->notify_student_submission_receipt($submission); $this->notify_graders($submission); } return true; } return false; }
/** * save assignment submission * * @param moodleform $mform * @param array $notices Any error messages that should be shown to the user at the top of the edit submission form. * @return bool */ private function process_save_submission(&$mform, &$notices) { global $USER, $CFG; // Include submission form. require_once $CFG->dirroot . '/mod/assign/submission_form.php'; // Need submit permission to submit an assignment. require_capability('mod/assign:submit', $this->context); require_sesskey(); $data = new stdClass(); $mform = new mod_assign_submission_form(null, array($this, $data)); if ($mform->is_cancelled()) { return true; } if ($data = $mform->get_data()) { $submission = $this->get_user_submission($USER->id, true); //create the submission if needed & its id if ($this->get_instance()->submissiondrafts) { $submission->status = ASSIGN_SUBMISSION_STATUS_DRAFT; } else { $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; } $grade = $this->get_user_grade($USER->id, false); // get the grade to check if it is locked if ($grade && $grade->locked) { print_error('submissionslocked', 'assign'); return true; } $allempty = true; $pluginerror = false; foreach ($this->submissionplugins as $plugin) { if ($plugin->is_enabled()) { if (!$plugin->save($submission, $data)) { $notices[] = $plugin->get_error(); $pluginerror = true; } if (!$allempty || !$plugin->is_empty($submission)) { $allempty = false; } } } if ($pluginerror || $allempty) { if ($allempty) { $notices[] = get_string('submissionempty', 'mod_assign'); } return false; } $this->update_submission($submission); // Logging $this->add_to_log('submit', $this->format_submission_for_log($submission)); if (!$this->get_instance()->submissiondrafts) { $this->notify_student_submission_receipt($submission); $this->notify_graders($submission); } return true; } return false; }
/** * Save assignment submission. * * @param moodleform $mform * @param array $notices Any error messages that should be shown * to the user at the top of the edit submission form. * @return bool */ protected function process_save_submission(&$mform, &$notices) { global $USER, $CFG; // Include submission form. require_once($CFG->dirroot . '/mod/assign/submission_form.php'); // Need submit permission to submit an assignment. require_capability('mod/assign:submit', $this->context); require_sesskey(); if (!$this->submissions_open()) { $notices[] = get_string('duedatereached', 'assign'); return false; } $instance = $this->get_instance(); $data = new stdClass(); $mform = new mod_assign_submission_form(null, array($this, $data)); if ($mform->is_cancelled()) { return true; } if ($data = $mform->get_data()) { if ($instance->teamsubmission) { $submission = $this->get_group_submission($USER->id, 0, true); } else { $submission = $this->get_user_submission($USER->id, true); } if ($instance->submissiondrafts) { $submission->status = ASSIGN_SUBMISSION_STATUS_DRAFT; } else { $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; } $flags = $this->get_user_flags($USER->id, false); // Get the flags to check if it is locked. if ($flags && $flags->locked) { print_error('submissionslocked', 'assign'); return true; } $pluginerror = false; foreach ($this->submissionplugins as $plugin) { if ($plugin->is_enabled() && $plugin->is_visible()) { if (!$plugin->save($submission, $data)) { $notices[] = $plugin->get_error(); $pluginerror = true; } } } $allempty = $this->submission_empty($submission); if ($pluginerror || $allempty) { if ($allempty) { $notices[] = get_string('submissionempty', 'mod_assign'); } return false; } $this->update_submission($submission, $USER->id, true, $instance->teamsubmission); // Logging. if (isset($data->submissionstatement)) { $logmessage = get_string('submissionstatementacceptedlog', 'mod_assign', fullname($USER)); $this->add_to_log('submission statement accepted', $logmessage); } $this->add_to_log('submit', $this->format_submission_for_log($submission)); $complete = COMPLETION_INCOMPLETE; if ($submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) { $complete = COMPLETION_COMPLETE; } $completion = new completion_info($this->get_course()); if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) { $completion->update_state($this->get_course_module(), $complete, $USER->id); } if (!$instance->submissiondrafts) { $this->notify_student_submission_receipt($submission); $this->notify_graders($submission); // Trigger assessable_submitted event on submission. $eventdata = new stdClass(); $eventdata->modulename = 'assign'; $eventdata->cmid = $this->get_course_module()->id; $eventdata->itemid = $submission->id; $eventdata->courseid = $this->get_course()->id; $eventdata->userid = $USER->id; $eventdata->params = array( 'submission_editable' => true, ); events_trigger('assessable_submitted', $eventdata); } return true; } return false; }
/** * save assignment submission * * @param moodleform $mform * @return bool */ private function process_save_submission(&$mform) { global $USER, $CFG; // Include submission form require_once $CFG->dirroot . '/mod/assign/submission_form.php'; // Need submit permission to submit an assignment require_capability('mod/assign:submit', $this->context); require_sesskey(); $data = new stdClass(); $mform = new mod_assign_submission_form(null, array($this, $data)); if ($mform->is_cancelled()) { return true; } if ($data = $mform->get_data()) { $submission = $this->get_user_submission($USER->id, true); //create the submission if needed & its id $grade = $this->get_user_grade($USER->id, false); // get the grade to check if it is locked if ($grade && $grade->locked) { print_error('submissionslocked', 'assign'); return true; } foreach ($this->submissionplugins as $plugin) { if ($plugin->is_enabled()) { if (!$plugin->save($submission, $data)) { print_error($plugin->get_error()); } } } $this->update_submission($submission); // Logging $this->add_to_log('submit', $this->format_submission_for_log($submission)); if (!$this->get_instance()->submissiondrafts) { $this->email_student_submission_receipt($submission); $this->email_graders($submission); } return true; } return false; }