public static function save_submission($assignmentid, $plugindata) {
        global $CFG, $USER;

        $params = self::validate_parameters(self::save_submission_parameters(),
                                            array('assignmentid' => $assignmentid,
                                                  'plugindata' => $plugindata));

        list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']);

        $notices = array();

        $assignment->update_effective_access($USER->id);
        if (!$assignment->submissions_open($USER->id)) {
            $notices[] = get_string('duedatereached', 'assign');
        } else {
            $submissiondata = (object)$params['plugindata'];
            $assignment->save_submission($submissiondata, $notices);
        }

        $warnings = array();
        foreach ($notices as $notice) {
            $warnings[] = self::generate_warning($params['assignmentid'],
                                                 'couldnotsavesubmission',
                                                 $notice);
        }

        return $warnings;
    }
public static function save_submission($assignmentid, $plugindata) {
        global $CFG, $USER;

        $params = self::validate_parameters(self::save_submission_parameters(),
                                            array('assignmentid' => $assignmentid,
                                                  'plugindata' => $plugindata));

        list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']);

        $notices = array();

        $assignment->update_effective_access($USER->id);
        if (!$assignment->submissions_open($USER->id)) {
            $notices[] = get_string('duedatereached', 'assign');
        } else {
            $submissiondata = (object)$params['plugindata'];
            $assignment->save_submission($submissiondata, $notices);
        }

        $warnings = array();
        foreach ($notices as $notice) {
            $warnings[] = self::generate_warning($params['assignmentid'],
                                                 'couldnotsavesubmission',
                                                 $notice);
        }

        return $warnings;
    }
public static function save_submission ( $ assignmentid , $ plugindata ) { global $ CFG , $ USER ; $ params = self :: validate_parameters ( self :: save_submission_parameters ( ) , array ( 'assignmentid' => $ assignmentid , 'plugindata' => $ plugindata ) ) ; list ( $ assignment , $ course , $ cm , $ context ) = self :: validate_assign ( $ params [ 'assignmentid' ] ) ; $ notices = array ( ) ; $ assignment -> update_effective_access ( $ USER -> id ) ; if ( ! $ assignment -> submissions_open ( $ USER -> id ) ) { $ notices [ ] = get_string ( 'duedatereached' , 'assign' ) ; } else { $ submissiondata = ( object ) $ params [ 'plugindata' ] ; $ assignment -> save_submission ( $ submissiondata , $ notices ) ; } $ warnings = array ( ) ; foreach ( $ notices as $ notice ) { $ warnings [ ] = self :: generate_warning ( $ params [ 'assignmentid' ] , 'couldnotsavesubmission' , $ notice ) ; } return $ warnings ; }
Save a student submission for a single assignment

@param int $assignmentid The id of the assignment
@param array $plugindata - The submitted data for plugins
@return array of warnings to indicate any errors
@since Moodle 2.6
Save a student submission for a single assignment