/** * Copy a students previous attempt to a new attempt. * * @param int $setaskmentid * @return array of warnings to indicate any errors. * @since Moodle 2.6 */ public static function copy_previous_attempt($setaskmentid) { global $CFG, $USER; require_once "{$CFG->dirroot}/mod/setask/locallib.php"; $params = self::validate_parameters(self::copy_previous_attempt_parameters(), array('setaskmentid' => $setaskmentid)); $cm = get_coursemodule_from_instance('setask', $setaskmentid, 0, false, MUST_EXIST); $context = context_module::instance($cm->id); self::validate_context($context); $setaskment = new setask($context, $cm, null); $notices = array(); $setaskment->copy_previous_attempt($submissiondata, $notices); $warnings = array(); foreach ($notices as $notice) { $warnings[] = self::generate_warning($setaskmentid, 'couldnotcopyprevioussubmission', $notice); } return $warnings; }