REST_Author.php
5 years ago
REST_Course.php
4 years ago
REST_Course_Announcement.php
5 years ago
REST_Lesson.php
5 years ago
REST_Quiz.php
5 years ago
REST_Rating.php
5 years ago
REST_Response.php
5 years ago
REST_Topic.php
5 years ago
REST_Rating.php
61 lines
| 1 | <?php |
| 2 | /* |
| 3 | @REST API for course annoucements |
| 4 | @author : themeum |
| 5 | */ |
| 6 | |
| 7 | |
| 8 | namespace TUTOR; |
| 9 | use WP_REST_Request; |
| 10 | use WP_Comment_Query; |
| 11 | |
| 12 | if(!defined( 'ABSPATH' )) |
| 13 | exit; |
| 14 | |
| 15 | class REST_Rating { |
| 16 | use REST_Response; |
| 17 | |
| 18 | private $post_id; |
| 19 | private $post_type = "tutor_course_rating"; |
| 20 | |
| 21 | /* |
| 22 | *require course id |
| 23 | *return comment/review with meta by course id and post type |
| 24 | */ |
| 25 | public function course_rating(WP_REST_Request $request) { |
| 26 | $this->post_id = $request->get_param('id'); |
| 27 | |
| 28 | global $wpdb; |
| 29 | $t_comment = $wpdb->prefix."comments"; |
| 30 | $t_commentmeta = $wpdb->prefix."commentmeta"; |
| 31 | |
| 32 | $ratings = $wpdb->get_results( |
| 33 | $wpdb->prepare( |
| 34 | "SELECT c.comment_author,c.comment_author_email,comment_date, |
| 35 | comment_content,comment_approved, cm.meta_value as rating |
| 36 | FROM $t_comment as c JOIN $t_commentmeta as cm ON cm.comment_id = c.comment_ID |
| 37 | WHERE c.comment_post_ID = %d AND c.comment_type = %s ", |
| 38 | $this->post_id,$this->post_type |
| 39 | )); |
| 40 | |
| 41 | if (count($ratings)>0) { |
| 42 | |
| 43 | $response = array( |
| 44 | 'status_code'=> 'success', |
| 45 | 'message'=> __('Course rating retrieved successfully','tutor'), |
| 46 | 'data'=> $ratings |
| 47 | ); |
| 48 | |
| 49 | return self::send($response); |
| 50 | } |
| 51 | |
| 52 | $response = array( |
| 53 | 'status_code'=> 'not_found', |
| 54 | 'message'=> __('Rating not found for given ID','tutor'), |
| 55 | 'data'=> [] |
| 56 | ); |
| 57 | |
| 58 | return self::send($response); |
| 59 | } |
| 60 | } |
| 61 |