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, obj $lesson )

Update quizzes during heartbeats


Description Description


Parameters Parameters

$quiz_data

(array) (Required) array of quiz updates

$lesson

(obj) (Required) instance of the parent LLMS_Lesson


Top ↑

Return Return

(array)


Top ↑

Source Source

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

	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' ) ) {

			$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() ), array(
				// 'content',
				'status',
				'title',
			) );

			// update all updatable properties
			foreach ( $properties as $prop ) {
				if ( isset( $quiz_data[ $prop ] ) ) {
					$quiz->set( $prop, $quiz_data[ $prop ] );
				}
			}

			if ( isset( $quiz_data['questions'] ) && is_array( $quiz_data['questions'] ) ) {
				$res['questions'] = self::update_questions( $quiz_data['questions'], $quiz );
			}

			// update all custom fields
			self::update_custom_schemas( 'quiz', $quiz, $quiz_data );

		}// End if().

		return $res;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.16.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: