REST_Author.php
5 years ago
REST_Course.php
5 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_Lesson.php
69 lines
| 1 | <?php |
| 2 | /* |
| 3 | @REST API Lesson |
| 4 | @author : themeum |
| 5 | */ |
| 6 | |
| 7 | |
| 8 | namespace TUTOR; |
| 9 | use WP_REST_Request; |
| 10 | |
| 11 | if(!defined('ABSPATH')) |
| 12 | exit; |
| 13 | |
| 14 | class REST_Lesson { |
| 15 | |
| 16 | use REST_Response; |
| 17 | |
| 18 | private $post_type; |
| 19 | private $post_parent; |
| 20 | |
| 21 | public function __construct() { |
| 22 | $this->post_type = tutor()->lesson_post_type; |
| 23 | } |
| 24 | |
| 25 | public function topic_lesson(WP_REST_Request $request) { |
| 26 | $this->post_parent = $request->get_param('id'); |
| 27 | global $wpdb; |
| 28 | |
| 29 | $table = $wpdb->prefix."posts"; |
| 30 | |
| 31 | $lessons = $wpdb->get_results( |
| 32 | $wpdb->prepare("SELECT ID, post_title, post_content, post_name, (SELECT post_parent from {$table} WHERE ID = {$this->post_parent} ) as course_id FROM $table WHERE post_type = %s AND post_parent = %d", $this->post_type, $this->post_parent) |
| 33 | ); |
| 34 | |
| 35 | $data = array(); |
| 36 | |
| 37 | if(count($lessons)>0) { |
| 38 | foreach ($lessons as $lesson) { |
| 39 | $attachments = []; |
| 40 | $attachments_id = get_post_meta($lesson->ID,'_tutor_attachments',false); |
| 41 | $attachments_id = $attachments_id[0]; |
| 42 | foreach($attachments_id as $id) { |
| 43 | $guid = get_the_guid($id); |
| 44 | array_push($attachments, $guid); |
| 45 | } |
| 46 | |
| 47 | $lesson->attachments = $attachments; |
| 48 | $lesson->thumbnail = get_the_post_thumbnail_url($lesson->ID); |
| 49 | $lesson->video = get_post_meta($lesson->ID, '_video',false); |
| 50 | array_push($data, $lesson); |
| 51 | } |
| 52 | |
| 53 | $response = array( |
| 54 | 'status_code'=> "success", |
| 55 | "message"=> __('Lesson retrieved successfully','tutor'), |
| 56 | 'data'=> $data |
| 57 | ); |
| 58 | |
| 59 | return self::send($response); |
| 60 | } |
| 61 | $response = array( |
| 62 | 'status_code'=> "not_found", |
| 63 | "message"=> __('Lesson not found for given topic ID','tutor'), |
| 64 | 'data'=> [] |
| 65 | ); |
| 66 | return self::send($response); |
| 67 | } |
| 68 | } |
| 69 |