LLMS_Quiz_Attempt::get_count( string $key )

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


Description Description


Parameters Parameters

$key

(string) (Required) 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':
				return count( $questions );
			break;

		}

		return $count;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.9.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: