dozent_get_discussion_questions( array $args = array() )
Get discussion questions
Description
Query discussion which asked by students to instructor from the lecture page.
Example usage:
dozent_get_discussion_questions();
dozent_get_discussion_questions( aray( 'lecture_ID' => 0,
‘start’ => 0, ‘limit’ => ‘-1’, ‘instructor_ID’ => 0, ‘only_parent’ => true, ) );
See also
Parameters
- $args
-
(array) (Optional)
Default value: array()
Return
(object)
Source
File: includes/core-functions.php
function dozent_get_discussion_questions( $args = [] ) { global $wpdb; /** * Filter the default value of dozent_get_discussion_questions(); * * @since DozentLMS 1.0.0 * * @param array Default Array * */ $defaults = apply_filters( 'dozent_get_discussion_questions_args', [ 'lecture_ID' => 0, 'start' => 0, 'limit' => '-1', 'instructor_ID' => 0, 'only_parent' => true, ] ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $instructor_join_sql = ''; if ( ! empty( $instructor_ID ) ){ $instructor_join_sql = " INNER JOIN {$wpdb->dozent_instructor_courses} instructor_courses ON instructor_courses.course_id = course.ID AND instructor_courses.instructor_id = {$instructor_ID} "; } $where = ""; if ( $only_parent ){ $where .= " AND comments.comment_parent = 0 "; } if ($lecture_ID) { $where .= " AND comments.comment_post_ID = {$lecture_ID} "; } $limit_query = ''; if ($limit != '-1') { $limit_query = " LIMIT {$start}, {$limit} "; } $where = apply_filters('dozent_get_discussion_questions_where', $where); $count = $wpdb->get_var("SELECT COUNT(comments.comment_ID) FROM {$wpdb->comments} comments LEFT JOIN {$wpdb->postmeta} course_id_meta ON comments.comment_post_ID = course_id_meta.post_id AND course_id_meta.meta_key = '_dozent_course_id' LEFT JOIN {$wpdb->posts} course ON course_id_meta.meta_value = course.ID LEFT JOIN {$wpdb->posts} lecture ON comments.comment_post_ID = lecture.ID LEFT JOIN {$wpdb->users} comment_user ON user_id = comment_user.ID {$instructor_join_sql} WHERE 1 = 1 {$where} AND comments.comment_type = 'dozent_discussion' ;"); $query = $wpdb->get_results("SELECT comments.comment_ID, comments.comment_post_ID, comments.comment_author, comments.comment_date, comments.comment_date_gmt, comments.comment_content, comments.comment_approved as comment_status, comments.comment_parent, comments.user_id, course_id_meta.meta_value as course_ID, course.post_title as course_title, lecture.ID as lecture_ID, lecture.post_title as lecture_title, comment_user.display_name as user_display_name, comment_user.user_nicename as user_nicename, (SELECT COUNT(replies.comment_ID) FROM {$wpdb->comments} replies WHERE replies.comment_parent = comments.comment_ID ) reply_count FROM {$wpdb->comments} comments LEFT JOIN {$wpdb->postmeta} course_id_meta ON comments.comment_post_ID = course_id_meta.post_id AND course_id_meta.meta_key = '_dozent_course_id' LEFT JOIN {$wpdb->posts} course ON course_id_meta.meta_value = course.ID LEFT JOIN {$wpdb->posts} lecture ON comments.comment_post_ID = lecture.ID LEFT JOIN {$wpdb->users} comment_user ON user_id = comment_user.ID {$instructor_join_sql} WHERE 1 = 1 {$where} AND comments.comment_type = 'dozent_discussion' ORDER BY comments.comment_date DESC {$limit_query} ;"); return (object) [ 'count' => (int) $count, 'results' => $query ]; }
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |