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_quiz( array $quiz_data, LLMS_Lesson $lesson )

Update quizzes during heartbeats


Parameters Parameters

$quiz_data

(array) (Required) Array of quiz updates.

$lesson

(LLMS_Lesson) (Required) Instance of the parent LLMS_Lesson.


Top ↑

Return Return

(array)


Top ↑

Source Source

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

1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
                }
            } elseif ( $questions ) {
 
                $ret['questions'] = self::update_questions( $questions, $question );
 
            }
        }
 
        array_push( $res, $ret );
 
    }
 
    return $res;
 
}
 
/**
 * Update quizzes during heartbeats
 *
 * @since 3.16.0
 * @since 3.17.6 Unknown.
 *
 * @param array       $quiz_data Array of quiz updates.
 * @param LLMS_Lesson $lesson    Instance of the parent LLMS_Lesson.
 * @return array
 */
private static function update_quiz( $quiz_data, $lesson ) {
 
    $res = array_merge(
        $quiz_data,
        array(
            'orig_id' => $quiz_data['id'],
        )
    );
 
    // Create a quiz.
    if ( self::is_temp_id( $quiz_data['id'] ) ) {
 
        $quiz = new LLMS_Quiz( 'new' );
 
        // Update existing quiz.
    } else {
 
        $quiz = llms_get_post( $quiz_data['id'] );
 
    }
 
    $lesson->set( 'quiz', $quiz->get( 'id' ) );
    $lesson->set( 'quiz_enabled', 'yes' );
 
    // We don't have a proper quiz to work with...
    if ( empty( $quiz ) || ! is_a( $quiz, 'LLMS_Quiz' ) ) {
 
        // Translators: %s = Quiz post id.
        $res['error'] = sprintf( esc_html__( 'Unable to update quiz "%s". Invalid quiz ID.', 'lifterlms' ), $quiz_data['id'] );
 
    } else {
 
        // Return the real ID (important when creating a new quiz).
        $res['id'] = $quiz->get( 'id' );
 
        /**
         * If the parent lesson was just created the lesson will have a temp id
         * replace it with the newly created lessons's real ID.
         */
        if ( ! isset( $quiz_data['lesson_id'] ) || self::is_temp_id( $quiz_data['lesson_id'] ) ) {
            $quiz_data['lesson_id'] = $lesson->get( 'id' );
        }
 
        $properties = array_merge(
            array_keys( $quiz->get_properties() ),


Top ↑

Changelog Changelog

Changelog
Version Description
3.17.6 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.