LLMS_Quiz_Attempt::get_count( string $key )

Retrieve a count for various pieces of information related to the attempt


Parameters Parameters

$key

(string) (Required) The key of the data to count.


Top ↑

Return Return

(int)


Top ↑

Source Source

File: includes/models/model.llms.quiz.attempt.php

	public function get_count( $key ) {

		$count     = 0;
		$questions = $this->get_questions();

		switch ( $key ) {

			case 'available_points':
			case 'correct_answers':
			case 'earned':
			case 'gradeable_questions': // Like "questions" but excludes content questions.
			case 'points': // Legacy version of earned.
				foreach ( $questions as $data ) {
					// Get the total number of correct answers.
					if ( 'correct_answers' === $key ) {
						if ( 'yes' === $data['correct'] ) {
							$count++;
						}
					} elseif ( 'earned' === $key || 'points' === $key ) {
						$count += $data['earned'];
						// Get the total number of possible points.
					} elseif ( 'available_points' === $key ) {
						$count += $data['points'];
					} elseif ( 'gradeable_questions' === $key ) {
						if ( $data['points'] ) {
							$count++;
						}
					}
				}
				break;

			case 'questions':
				$count = count( $questions );
				break;

		}

		return $count;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.2.0 Ensure only one return point.
3.9.0
3.19.2 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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