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).


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/admin/class.llms.admin.builder.php

1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
            if ( ! empty( $lesson_data['quiz'] ) && is_array( $lesson_data['quiz'] ) ) {
                $res['quiz'] = self::update_quiz( $lesson_data['quiz'], $lesson );
            }
        }
 
        // Allow 3rd parties to update custom data.
        $res = apply_filters( 'llms_builder_update_lesson', $res, $lesson_data, $lesson, $created );
 
        array_push( $ret, $res );
 
    }
 
    return $ret;
 
}
 
/**
 * Update quiz questions from heartbeat data
 *
 * @since 3.16.0
 * @since 3.16.11 Unknown.
 * @since 3.38.2 Make sure that a question as a type set, otherwise set it by default to `'choice'`.
 *
 * @param array                   $questions Question data array.
 * @param LLMS_Quiz|LLMS_Question $parent    Instance of an LLMS_Quiz or LLMS_Question (group).
 * @return array
 */
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'] );


Top ↑

Changelog 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.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.