dozent_get_quiz_answers( array $args = array(), false $first = false )
Get the answers placed by a user on the quiz attempt
Description
Example usage:
$attempts = dozent_get_quiz_answers( array(
'quiz_id' => null,
'user_id' => null,
'attempt_id' => null
));
Parameters
- $args
-
(array) (Optional)
Default value: array()
- $first
-
(false) (Optional)
Default value: false
Return
(DozentDBResponse) Default response if the database query
Source
File: includes/quiz-functions.php
function dozent_get_quiz_answers( $args = [], $first = false ) { global $wpdb; $response = new DozentDBResponse(); $defaults = apply_filters( 'dozent_get_quiz_answers_default_args', [ 'quiz_id' => null, 'user_id' => null, 'attempt_id' => null, 'where' => [], ] ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $quiz_sql = ""; if ( ! empty( $quiz_id ) ) { $quiz_sql = " AND quiz_id = {$quiz_id} "; } $user_sql = ""; if ( ! empty( $user_id ) ) { $user_sql = " AND user_id = {$user_id} "; } $attempt_sql = ""; if ( ! empty( $attempt_id ) ) { $attempt_sql = " AND attempt_id = {$attempt_id} "; } if ( empty( $where_sql ) ){ $where_sql = ""; } $sql = "SELECT * FROM {$wpdb->dozent_quiz_answers} WHERE 1 = 1 {$quiz_sql} {$user_sql} {$attempt_sql} {$where_sql} ;"; if ( $first ) { $results = $wpdb->get_row( $sql ); if ( $results ) { $response->count = 1; } } else { $results = $wpdb->get_results( $sql ); $response->count = dozent_count( $results ); } $response->results = $results; return $response; }
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |