/**
  * Observer function to handle the assessable_submitted event in mod_assign.
  * @param \mod_assign\event\assessable_submitted $event
  */
 public static function assignsubmission_submitted(\mod_assign\event\assessable_submitted $event)
 {
     global $CFG;
     require_once $CFG->dirroot . '/plagiarism/urkund/lib.php';
     $eventdata = $event->get_data();
     $eventdata['eventtype'] = 'assignsubmission_submitted';
     $urkund = new plagiarism_plugin_urkund();
     $urkund->event_handler($eventdata);
 }
Exemple #2
0
 /**
  * Save assignment submission for the current user.
  *
  * @param  stdClass $data
  * @param  array $notices Any error messages that should be shown
  *                        to the user.
  * @return bool
  */
 public function save_submission(stdClass $data, &$notices)
 {
     global $CFG, $USER;
     require_capability('mod/assign:submit', $this->context);
     $instance = $this->get_instance();
     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);
         $addtolog = $this->add_to_log('submission statement accepted', $logmessage, '', true);
         $params = array('context' => $this->context, 'objectid' => $submission->id);
         $event = \mod_assign\event\statement_accepted::create($params);
         $event->set_legacy_logdata($addtolog);
         $event->trigger();
     }
     $addtolog = $this->add_to_log('submit', $this->format_submission_for_log($submission), '', true);
     $params = array('context' => $this->context, 'objectid' => $submission->id);
     $event = \mod_assign\event\submission_updated::create($params);
     $event->set_legacy_logdata($addtolog);
     $event->trigger();
     $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.
         $params = array('context' => context_module::instance($this->get_course_module()->id), 'objectid' => $submission->id, 'other' => array('submission_editable' => true));
         $event = \mod_assign\event\assessable_submitted::create($params);
         $event->trigger();
     }
     return true;
 }
Exemple #3
0
 /**
  * Save assignment submission for the current user.
  *
  * @param  stdClass $data
  * @param  array $notices Any error messages that should be shown
  *                        to the user.
  * @return bool
  */
 public function save_submission(stdClass $data, &$notices)
 {
     global $CFG, $USER, $DB;
     $userid = $USER->id;
     if (!empty($data->userid)) {
         $userid = $data->userid;
     }
     $user = clone $USER;
     if ($userid == $USER->id) {
         require_capability('mod/assign:submit', $this->context);
     } else {
         $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
         if (!$this->can_edit_submission($userid, $USER->id)) {
             print_error('nopermission');
         }
     }
     $instance = $this->get_instance();
     if ($instance->teamsubmission) {
         $submission = $this->get_group_submission($userid, 0, true);
     } else {
         $submission = $this->get_user_submission($userid, true);
     }
     if ($instance->submissiondrafts) {
         $submission->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
     } else {
         $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
     }
     $flags = $this->get_user_flags($userid, 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, $userid, true, $instance->teamsubmission);
     // Logging.
     if (isset($data->submissionstatement) && $userid == $USER->id) {
         \mod_assign\event\statement_accepted::create_from_submission($this, $submission)->trigger();
     }
     $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, $userid);
     }
     if (!$instance->submissiondrafts) {
         $this->notify_student_submission_receipt($submission);
         $this->notify_graders($submission);
         \mod_assign\event\assessable_submitted::create_from_submission($this, $submission, true)->trigger();
     }
     return true;
 }