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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / RestAPI.php
tutor / classes Last commit date
Addons.php 2 years ago Admin.php 2 years ago Ajax.php 2 years ago Announcements.php 3 years ago Assets.php 2 years ago Backend_Page_Trait.php 3 years ago Course.php 2 years ago Course_Embed.php 3 years ago Course_Filter.php 3 years ago Course_List.php 2 years ago Course_Settings_Tabs.php 3 years ago Course_Widget.php 3 years ago Custom_Validation.php 3 years ago Dashboard.php 3 years ago FormHandler.php 2 years ago Frontend.php 3 years ago Gutenberg.php 3 years ago Input.php 3 years ago Instructor.php 2 years ago Instructors_List.php 3 years ago Lesson.php 2 years ago Options_V2.php 2 years ago Post_types.php 2 years ago Private_Course_Access.php 3 years ago Q_and_A.php 3 years ago Question_Answers_List.php 3 years ago Quiz.php 2 years ago Quiz_Attempts_List.php 2 years ago RestAPI.php 3 years ago Reviews.php 3 years ago Rewrite_Rules.php 3 years ago Shortcode.php 2 years ago Student.php 2 years ago Students_List.php 3 years ago Taxonomies.php 3 years ago Template.php 2 years ago Theme_Compatibility.php 3 years ago Tools.php 3 years ago Tools_V2.php 3 years ago Tutor.php 3 years ago TutorEDD.php 2 years ago Tutor_Base.php 3 years ago Tutor_Setup.php 3 years ago Upgrader.php 3 years ago User.php 3 years ago Utils.php 2 years ago Video_Stream.php 3 years ago Withdraw.php 2 years ago Withdraw_Requests_List.php 3 years ago WooCommerce.php 2 years ago
RestAPI.php
400 lines
1 <?php //phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
2 /**
3 * RestAPI class
4 *
5 * @package Tutor\API
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 1.5.0
9 */
10
11 namespace TUTOR;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Initialize REST API
19 *
20 * @since 1.5.0
21 */
22 class RestAPI {
23
24 /**
25 * Custom validation trait
26 */
27 use Custom_Validation;
28
29 /**
30 * API namespace
31 *
32 * @var string
33 */
34 private $namespace = 'tutor/v1';
35
36 /**
37 * Course post type
38 *
39 * @var string
40 */
41 protected $course_post_type;
42
43 /**
44 * Plugin dir Path
45 *
46 * @var string
47 */
48 private $path;
49
50 /**
51 * Course Object
52 *
53 * @var object
54 */
55 private $course_obj;
56
57 /**
58 * Topic Object
59 *
60 * @var object
61 */
62 private $topic_obj;
63
64 /**
65 * Lesson Object
66 *
67 * @var object
68 */
69 private $lesson_obj;
70
71 /**
72 * Announcement Object
73 *
74 * @var object
75 */
76 private $announcement_obj;
77
78 /**
79 * Quiz Object
80 *
81 * @var object
82 */
83 private $quiz_obj;
84
85 /**
86 * Author Object
87 *
88 * @var object
89 */
90 private $author_obj;
91
92 /**
93 * Rating Object
94 *
95 * @var object
96 */
97 private $rating_obj;
98
99 /**
100 * Manage dependencies
101 *
102 * @since 1.5.0
103 */
104 public function __construct() {
105
106 $this->path = plugin_dir_path( TUTOR_FILE );
107
108 spl_autoload_register( array( $this, 'loader' ) );
109
110 $this->course_obj = new REST_Course();
111 $this->topic_obj = new REST_Topic();
112 $this->lesson_obj = new REST_Lesson();
113 $this->announcement_obj = new REST_Course_Announcement();
114 $this->quiz_obj = new REST_Quiz();
115 $this->author_obj = new REST_Author();
116 $this->rating_obj = new REST_Rating();
117
118 add_action( 'rest_api_init', array( $this, 'init_routes' ) );
119 }
120
121 /**
122 * Class loading
123 *
124 * @since 1.5.0
125 *
126 * @param string $class_name class name to load.
127 *
128 * @return void
129 */
130 private function loader( $class_name ) {
131 if ( ! class_exists( $class_name ) ) {
132 $class_name = preg_replace(
133 array( '/([a-z])([A-Z])/', '/\\\/' ),
134 array( '$1$2', DIRECTORY_SEPARATOR ),
135 $class_name
136 );
137
138 $class_name = str_replace( 'TUTOR' . DIRECTORY_SEPARATOR, 'restapi' . DIRECTORY_SEPARATOR, $class_name );
139 $file_name = $this->path . $class_name . '.php';
140
141 if ( file_exists( $file_name ) ) {
142 require_once $file_name;
143 }
144 }
145 }
146
147 /**
148 * Initialize routes
149 *
150 * @since 1.5.0
151 *
152 * @return void
153 */
154 public function init_routes() {
155 // Courses.
156 register_rest_route(
157 $this->namespace,
158 '/courses',
159 array(
160 'methods' => 'GET',
161 'callback' => array(
162 $this->course_obj,
163 'course',
164 ),
165 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
166 )
167 );
168
169 // Courses by terms cat and tag.
170 register_rest_route(
171 $this->namespace,
172 '/course-by-terms',
173 array(
174 'methods' => 'POST',
175 'callback' => array(
176 $this->course_obj,
177 'course_by_terms',
178 ),
179 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
180 )
181 );
182
183 // Courses by terms cat and tag.
184 register_rest_route(
185 $this->namespace,
186 '/course-sorting-by-price',
187 array(
188 'methods' => 'GET',
189 'callback' => array(
190 $this->course_obj,
191 'course_sort_by_price',
192 ),
193 'args' => array(
194 'order' => array(
195 'required' => true,
196 'type' => 'string',
197 'validate_callback' => function ( $order ) {
198 return $this->validate_order( $order );
199 },
200 ),
201 'page' => array(
202 'required' => false,
203 'type' => 'number',
204 ),
205 ),
206 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
207 )
208 );
209
210 // Course details.
211 register_rest_route(
212 $this->namespace,
213 '/course-detail/(?P<id>\d+)',
214 array(
215 'methods' => 'GET',
216 'callback' => array(
217 $this->course_obj,
218 'course_detail',
219 ),
220 'args' => array(
221 'id' => array(
222 'validate_callback' => function ( $param ) {
223 return is_numeric( $param );
224 },
225 ),
226 ),
227 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
228 )
229 );
230
231 // Course topic.
232 register_rest_route(
233 $this->namespace,
234 '/course-topic/(?P<id>\d+)',
235 array(
236 'methods' => 'GET',
237 'callback' => array(
238 $this->topic_obj,
239 'course_topic',
240 ),
241 'args' => array(
242 'id' => array(
243 'validate_callback' => function ( $param ) {
244 return is_numeric( $param );
245 },
246 ),
247 ),
248 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
249 )
250 );
251
252 // Lesson by topic.
253 register_rest_route(
254 $this->namespace,
255 '/lesson/(?P<id>\d+)',
256 array(
257 'methods' => 'GET',
258 'callback' => array(
259 $this->lesson_obj,
260 'topic_lesson',
261 ),
262 'args' => array(
263 'id' => array(
264 'validate_callback' => function ( $param ) {
265 return is_numeric( $param );
266 },
267 ),
268 ),
269 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
270 )
271 );
272
273 // Course announcement by course id.
274 register_rest_route(
275 $this->namespace,
276 '/course-announcement/(?P<id>\d+)',
277 array(
278 'methods' => 'GET',
279 'callback' => array(
280 $this->announcement_obj,
281 'course_annoucement',
282 ),
283 'args' => array(
284 'id' => array(
285 'validate_callback' => function ( $param ) {
286 return is_numeric( $param );
287 },
288 ),
289 ),
290 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
291 )
292 );
293
294 // Quiz by topic id.
295 register_rest_route(
296 $this->namespace,
297 '/quiz/(?P<id>\d+)',
298 array(
299 'methods' => 'GET',
300 'callback' => array(
301 $this->quiz_obj,
302 'quiz_with_settings',
303 ),
304 'args' => array(
305 'id' => array(
306 'validate_callback' => function ( $param ) {
307 return is_numeric( $param );
308 },
309 ),
310 ),
311 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
312 )
313 );
314
315 // Quiz question answer by quiz id.
316 register_rest_route(
317 $this->namespace,
318 '/quiz-question-answer/(?P<id>\d+)',
319 array(
320 'methods' => 'GET',
321 'callback' => array(
322 $this->quiz_obj,
323 'quiz_question_ans',
324 ),
325 'args' => array(
326 'id' => array(
327 'validate_callback' => function ( $param ) {
328 return is_numeric( $param );
329 },
330 ),
331 ),
332 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
333 )
334 );
335
336 // Quiz attempt details by quiz id.
337 register_rest_route(
338 $this->namespace,
339 '/quiz-attempt-details/(?P<id>\d+)',
340 array(
341 'methods' => 'GET',
342 'callback' => array(
343 $this->quiz_obj,
344 'quiz_attempt_details',
345 ),
346 'args' => array(
347 'id' => array(
348 'validate_callback' => function ( $param ) {
349 return is_numeric( $param );
350 },
351 ),
352 ),
353 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
354 )
355 );
356
357 // Author detail by id.
358 register_rest_route(
359 $this->namespace,
360 '/author-information/(?P<id>\d+)',
361 array(
362 'methods' => 'GET',
363 'callback' => array(
364 $this->author_obj,
365 'author_detail',
366 ),
367 'args' => array(
368 'id' => array(
369 'validate_callback' => function ( $param ) {
370 return is_numeric( $param );
371 },
372 ),
373 ),
374 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
375 )
376 );
377
378 // Reviews by course id.
379 register_rest_route(
380 $this->namespace,
381 '/course-rating/(?P<id>\d+)',
382 array(
383 'methods' => 'GET',
384 'callback' => array(
385 $this->rating_obj,
386 'course_rating',
387 ),
388 'args' => array(
389 'id' => array(
390 'validate_callback' => function ( $param ) {
391 return is_numeric( $param );
392 },
393 ),
394 ),
395 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
396 )
397 );
398 }
399 }
400