dozent_get_quizzes_by_course( null|int|object $course = null, array $args = array() )
Get quizzes by course
Description
This function will return all of the quizzes under specific course.
Pass $limit parameter value = "-1" to get no limit at the query
Example usage:
$args = array(
'not_in_ids' => [],
'start' => 0,
'per_page' => 10,
)
$instructors = dozent_get_quizzes_by_course( $course_id, $args );
Check the default arguments
See also
Parameters
- $course
-
(null|int|object) (Optional) WP_Post instance or post id
Default value: null
- $args
-
(array) (Optional) default query arguments
Default value: array()
Return
(DozentDBResponse)
Source
File: includes/quiz-functions.php
function dozent_get_quizzes_by_course( $course = null, $args = [] ) { global $wpdb; $default_per_page = dozent_show_per_page(); $current_page = (int) dozent_input_text( 'current_page' ); $page = max( 1, $current_page ); $start = ( $page - 1 ) * $default_per_page; $defaults = apply_filters( 'dozent_get_quizzes_by_course_default_args', [ 'not_in_ids' => [], 'start' => $start, 'per_page' => $default_per_page, ] ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $course = get_post( $course ); if ( empty( $course->ID ) ) { return new DozentDBResponse(); } $not_in_ids_query = ''; if ( ! empty( $not_in_ids ) && dozent_count( $not_in_ids ) ) { $not_in_ids_string = implode( ",", $not_in_ids ); $not_in_ids_query = " AND quizzes.ID NOT IN( $not_in_ids_string ) "; } /** * Filter the default quizzes status for Count course including {post_status} * * @since DozentLMS 1.0.0 * * @param array [] $array */ $course_status = apply_filters( 'dozent_get_quizzes_status', [ 'publish' ] ); $in_sql = ""; $where_in_sql = dozent_array_to_in_sql( $course_status ); if ( $where_in_sql ) { $in_sql = " AND quizzes.post_status IN($where_in_sql) "; } $limit_query = ''; if ( $per_page !== '-1' ) { $limit_query = " LIMIT {$start}, {$per_page} "; } $from_sql = "FROM {$wpdb->posts} course INNER JOIN {$wpdb->posts} course_sections ON course.ID = course_sections.post_parent INNER JOIN {$wpdb->posts} quizzes ON course_sections.ID = quizzes.post_parent AND quizzes.post_type = 'dozent_quiz'"; $quizzes_count = (int) $wpdb->get_var( "SELECT COUNT(quizzes.ID) {$from_sql} WHERE 1 = 1 AND course.ID = {$course->ID} {$in_sql} {$not_in_ids_query} ;" ); $quizzes_results = $wpdb->get_results( "SELECT quizzes.* {$from_sql} WHERE 1 = 1 AND course.ID = {$course->ID} {$in_sql} {$not_in_ids_query} {$limit_query} ;" ); $response = new DozentDBResponse(); $response->count = $quizzes_count; $response->results = $quizzes_results; /** * Filter the return of dozent_get_courses_by_instructor() function * * @since Dozent LMS v.1.0.0 * * @param DozentDBResponse $response Query Results with * @param WP_Post $course Course Object */ return apply_filters( 'dozent_get_quizzes_by_course', $response, $course ); }
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |