LLMS_Quiz_Legacy::get_best_quiz_attempt( int $user_id )

Get Id of quiz with best grade


Description Description


Parameters Parameters

$user_id

(int) (Required) [ID of user]


Top ↑

Return Return

(int) [ID of quiz attempt]


Top ↑

Source Source

File: includes/class.llms.quiz.legacy.php

	public function get_best_quiz_attempt( $user_id ) {
		$quiz = get_user_meta( $user_id, 'llms_quiz_data', true );
		$grades = array();
		$unique_id = '';

		if ( $quiz ) {

			foreach ( $quiz as $key => $value ) {
				if ( $value['id'] == $this->id ) {
					if ( $value['grade'] ) {
						array_push( $grades, $value['grade'] );
					}
				}
			}
			$highest_grade = ( empty( $grades ) ? 0 : max( $grades ) );

			foreach ( $quiz as $key => $value ) {
				if ( $value['id'] == $this->id && $highest_grade == $value['grade'] ) {
					$unique_id = $value['wpnonce'];
				}
			}
		}

		return $unique_id;
	}

Top ↑

User Contributed Notes User Contributed Notes

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