dozent_get_attempts( array $args = array(), bool $first = false )
Get quiz attempts
Description
Quiz attempts results can be filter by passing arguments.
Example usage:
$attempts = dozent_get_attempts( array( 'quiz_id' => null,
'id' => null,
'quiz_id' => null,
'user_id' => null,
'status' => 'started,in_review,finished',
'order_by' => 'ASC',
));
Note: If pass id via argument array, this function returns a single row of result matching by ID.
Parameters
- $args
-
(array) (Optional) Arguments of this function
Default value: array()
- $first
-
(bool) (Optional) Weather return only first result or not
Default value: false
Return
(DozentDBResponse) Results of query attempts.
Source
File: includes/quiz-functions.php
function dozent_get_attempts( $args = [], $first = false ) { global $wpdb; $response = new DozentDBResponse(); $defaults = apply_filters( 'dozent_get_attempts_default_args', [ 'id' => null, 'course_id' => null, 'quiz_id' => null, 'user_id' => null, 'status' => 'started,in_review,finished', 'order_by' => 'ASC', ] ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $course_sql = ""; if ( ! empty( $course_id ) ) { $course_sql = " AND course_id = {$course_id} "; } $quiz_sql = ""; if ( ! empty( $quiz_id ) ) { $quiz_sql = " AND quiz_id = {$quiz_id} "; } $id_sql = ""; if ( ! empty( $id ) ) { $id_sql = " AND id = {$id} "; $first = true; } $user_sql = ""; if ( ! empty( $user_id ) ) { $user_sql = " AND user_id = {$user_id} "; } $status_sql = ""; if ( ! empty( $status ) ) { $status_arr = is_array( $status ) ? $status : explode( ',', $status ); $status_arr = (array) $status_arr; $status_in_sql = dozent_array_to_in_sql( $status_arr ); $status_sql = " AND status IN( {$status_in_sql} ) "; } $order_by_sql = " ORDER BY created_at ASC "; if ( ! empty( $order_by ) ) { $order_by_sql = " ORDER BY created_at {$order_by} "; } $sql = "SELECT * FROM {$wpdb->dozent_quiz_attempts} WHERE 1 = 1 {$id_sql} {$course_sql} {$quiz_sql} {$user_sql} {$status_sql} {$order_by_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. |