public static function submit_answers($surveyid, $answers) {
        global $DB, $USER;

        $params = self::validate_parameters(self::submit_answers_parameters(),
                                            array(
                                                'surveyid' => $surveyid,
                                                'answers' => $answers
                                            ));
        $warnings = array();

        // Request and permission validation.
        $survey = $DB->get_record('survey', array('id' => $params['surveyid']), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($survey, 'survey');

        $context = context_module::instance($cm->id);
        self::validate_context($context);
        require_capability('mod/survey:participate', $context);

        if (survey_already_done($survey->id, $USER->id)) {
            throw new moodle_exception("alreadysubmitted", "survey");
        }

        // Build the answers array. Data is cleaned inside the survey_save_answers function.
        $answers = array();
        foreach ($params['answers'] as $answer) {
            $key = $answer['key'];
            $answers[$key] = $answer['value'];
        }

        survey_save_answers($survey, $answers, $course, $context);

        $result = array();
        $result['status'] = true;
        $result['warnings'] = $warnings;
        return $result;
    }
public static function submit_answers($surveyid, $answers) {
        global $DB, $USER;

        $params = self::validate_parameters(self::submit_answers_parameters(),
                                            array(
                                                'surveyid' => $surveyid,
                                                'answers' => $answers
                                            ));
        $warnings = array();

        // Request and permission validation.
        $survey = $DB->get_record('survey', array('id' => $params['surveyid']), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($survey, 'survey');

        $context = context_module::instance($cm->id);
        self::validate_context($context);
        require_capability('mod/survey:participate', $context);

        if (survey_already_done($survey->id, $USER->id)) {
            throw new moodle_exception("alreadysubmitted", "survey");
        }

        // Build the answers array. Data is cleaned inside the survey_save_answers function.
        $answers = array();
        foreach ($params['answers'] as $answer) {
            $key = $answer['key'];
            $answers[$key] = $answer['value'];
        }

        survey_save_answers($survey, $answers, $course, $context);

        $result = array();
        $result['status'] = true;
        $result['warnings'] = $warnings;
        return $result;
    }
public static function submit_answers ( $ surveyid , $ answers ) { global $ DB , $ USER ; $ params = self :: validate_parameters ( self :: submit_answers_parameters ( ) , array ( 'surveyid' => $ surveyid , 'answers' => $ answers ) ) ; $ warnings = array ( ) ; // Request and permission validation. $ survey = $ DB -> get_record ( 'survey' , array ( 'id' => $ params [ 'surveyid' ] ) , '*' , MUST_EXIST ) ; list ( $ course , $ cm ) = get_course_and_cm_from_instance ( $ survey , 'survey' ) ; $ context = context_module :: instance ( $ cm -> id ) ; self :: validate_context ( $ context ) ; require_capability ( 'mod/survey:participate' , $ context ) ; if ( survey_already_done ( $ survey -> id , $ USER -> id ) ) { throw new moodle_exception ( "alreadysubmitted" , "survey" ) ; } // Build the answers array. Data is cleaned inside the survey_save_answers function. $ answers = array ( ) ; foreach ( $ params [ 'answers' ] as $ answer ) { $ key = $ answer [ 'key' ] ; $ answers [ $ key ] = $ answer [ 'value' ] ; } survey_save_answers ( $ survey , $ answers , $ course , $ context ) ; $ result = array ( ) ; $ result [ 'status' ] = true ; $ result [ 'warnings' ] = $ warnings ; return $ result ; }
Submit the answers for a given survey.

@param int $surveyid the survey instance id
@param array $answers the survey answers
@return array of warnings and status result
@since Moodle 3.0
@throws moodle_exception
Submit the answers for a given survey .