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.
Return Return
(int)
Source Source
File: includes/models/model.llms.quiz.attempt.php
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | 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 ; } |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
4.2.0 | Ensure only one return point. |
3.9.0 | |
3.19.2 | Introduced. |