Quiz::start_quiz()

Start Quiz


Source

File: classes/Quiz.php

	public function start_quiz() {
		dozent_checking_nonce();

		global $wpdb;

		$quiz_id   = (int) dozent_input_text( 'quiz_id' );
		$user_id   = get_current_user_id();
		$course_id = dozent_get_course_id_by_content( $quiz_id );

		$has_started_attempt = dozent_get_attempts( [
			'quiz_id' => $quiz_id,
			'user_id' => $user_id,
			'status'  => 'started',
		] );

		if ( ! $has_started_attempt->count ) {
			$quiz_option     = dozent_get_quiz_option( $quiz_id );
			$passing_percent = (int) dozent_array_get( 'passing_score', $quiz_option );

			$attempt_data = [
				'course_id'       => $course_id,
				'quiz_id'         => $quiz_id,
				'user_id'         => $user_id,
				'questions_limit' => dozent_array_get( 'questions_limit', $quiz_option ),
				'status'          => 'started',
				'quiz_gradable'   => dozent_array_get( 'gradable', $quiz_option ),
				'passing_percent' => $passing_percent,
				'quiz_option'     => json_encode( $quiz_option ),
				'created_at'      => dozent_mysql_time(),
				'updated_at'      => dozent_mysql_time(),
			];

			$wpdb->insert( $wpdb->dozent_quiz_attempts, $attempt_data );
		}

		dozent_redirect( get_permalink( $quiz_id ) );
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.