Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
LLMS_Admin_Builder::update_questions( array $questions, LLMS_Quiz|LLMS_Question $parent )
Update quiz questions from heartbeat data
Parameters Parameters
- $questions
-
(array) (Required) Question data array.
- $parent
-
(LLMS_Quiz|LLMS_Question) (Required) Instance of an LLMS_Quiz or LLMS_Question (group).
Return Return
(array)
Source Source
File: includes/admin/class.llms.admin.builder.php
private static function update_questions( $questions, $parent ) { $res = array(); foreach ( $questions as $q_data ) { $ret = array_merge( $q_data, array( 'orig_id' => $q_data['id'], ) ); // Remove temp id if we have one so we'll create a new question. if ( self::is_temp_id( $q_data['id'] ) ) { unset( $q_data['id'] ); } // Remove choices because we'll add them individually after creation. $choices = ( isset( $q_data['choices'] ) && is_array( $q_data['choices'] ) ) ? $q_data['choices'] : false; unset( $q_data['choices'] ); // Remove child questions if it's a question group. $questions = ( isset( $q_data['questions'] ) && is_array( $q_data['questions'] ) ) ? $q_data['questions'] : false; unset( $q_data['questions'] ); $question_id = $parent->questions()->update_question( $q_data ); if ( ! $question_id ) { // Translators: %s = Question post id. $ret['error'] = sprintf( esc_html__( 'Unable to update question "%s". Invalid question ID.', 'lifterlms' ), $q_data['id'] ); } else { $ret['id'] = $question_id; $question = $parent->questions()->get_question( $question_id ); /** * When saving a question, make sure that it has a question type set * otherwise set it by default to `'choice'`. */ if ( ! $question->get( 'question_type', true ) ) { $question->set( 'question_type', 'choice' ); } if ( $choices ) { $ret['choices'] = array(); foreach ( $choices as $c_data ) { $choice_res = array_merge( $c_data, array( 'orig_id' => $c_data['id'], ) ); unset( $c_data['question_id'] ); // Remove the temp ID so that we create it if it's new. if ( self::is_temp_id( $c_data['id'] ) ) { unset( $c_data['id'] ); } $choice_id = $question->update_choice( $c_data ); if ( ! $choice_id ) { // Translators: %s = Question choice ID. $choice_res['error'] = sprintf( esc_html__( 'Unable to update choice "%s". Invalid choice ID.', 'lifterlms' ), $c_data['id'] ); } else { $choice_res['id'] = $choice_id; } array_push( $ret['choices'], $choice_res ); } } elseif ( $questions ) { $ret['questions'] = self::update_questions( $questions, $question ); } } array_push( $res, $ret ); } return $res; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.38.2 | Make sure that a question as a type set, otherwise set it by default to 'choice' . |
3.16.11 | Unknown. |
3.16.0 | Introduced. |