Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor/restapi/REST_Topic.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + /**
3 + * REST API for course topics.
4 + *
5 + * @package Tutor\RestAPI
6 + * @author Themeum <support@themeum.com>
7 + * @link https://themeum.com
8 + * @since 1.7.1
9 + */
10 +
11 + namespace TUTOR;
12 +
13 + use WP_REST_Request;
14 +
15 + if ( ! defined( 'ABSPATH' ) ) {
16 + exit;
17 + }
18 +
19 + /**
20 + * Class REST_Topic
21 + *
22 + * @package Tutor
23 + *
24 + * @since 1.7.1
25 + */
26 + class REST_Topic {
27 + use REST_Response;
28 +
29 + /**
30 + * Post parent ID.
31 + *
32 + * @var int $post_parent The ID of the post parent.
33 + */
34 + private $post_parent;
35 +
36 + /**
37 + * Post type.
38 + *
39 + * @var string $post_type The post type for topics.
40 + */
41 + private $post_type = 'topics';
42 +
43 + /**
44 + * Retrieve topics by course ID via REST API.
45 + *
46 + * @param WP_REST_Request $request The REST request object.
47 + *
48 + * @since 1.7.1
49 + *
50 + * @return mixed
51 + */
52 + public function course_topic( WP_REST_Request $request ) {
53 + $this->post_parent = $request->get_param( 'course_id' );
54 +
55 + if ( ! isset( $this->post_parent ) ) {
56 + $response = array(
57 + 'code' => 'get_topic',
58 + 'message' => __( 'course_id is required', 'tutor' ),
59 + 'data' => array(),
60 + );
61 + return self::send( $response );
62 + }
63 +
64 + global $wpdb;
65 +
66 + $result = $wpdb->get_results(
67 + $wpdb->prepare( "SELECT ID, post_title, post_content, post_name FROM {$wpdb->posts} WHERE post_type = %s AND post_parent = %d", $this->post_type, $this->post_parent )
68 + );
69 +
70 + if ( count( $result ) > 0 ) {
71 + $response = array(
72 + 'code' => 'get_topic',
73 + 'message' => __( 'Topic retrieved successfully', 'tutor' ),
74 + 'data' => $result,
75 + );
76 +
77 + return self::send( $response );
78 + }
79 + $response = array(
80 + 'code' => 'not_found',
81 + 'message' => __( 'Topic not found for given course ID', 'tutor' ),
82 + 'data' => array(),
83 + );
84 +
85 + return self::send( $response );
86 + }
87 + }
88 +