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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 1 year ago Announcements.php 1 year ago Assets.php 2 years ago Backend_Page_Trait.php 3 years ago Course.php 1 year ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 1 year 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 2 years ago Gutenberg.php 3 years ago Input.php 3 years ago Instructor.php 2 years ago Instructors_List.php 1 year ago Lesson.php 1 year ago Options_V2.php 1 year ago Permalink.php 2 years ago Post_types.php 2 years ago Private_Course_Access.php 3 years ago Q_And_A.php 1 year ago Question_Answers_List.php 3 years ago Quiz.php 1 year ago Quiz_Attempts_List.php 1 year ago RestAPI.php 2 years ago Reviews.php 3 years ago Rewrite_Rules.php 2 years ago Shortcode.php 1 year 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 2 years ago Tutor.php 2 years ago TutorEDD.php 2 years ago Tutor_Base.php 2 years ago Tutor_Setup.php 2 years ago Upgrader.php 2 years ago User.php 2 years ago Utils.php 1 year ago Video_Stream.php 3 years ago WhatsNew.php 2 years ago Withdraw.php 2 years ago Withdraw_Requests_List.php 3 years ago WooCommerce.php 1 year ago
RestAPI.php
401 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 // Course details.
170 register_rest_route(
171 $this->namespace,
172 '/courses/(?P<id>\d+)',
173 array(
174 'methods' => 'GET',
175 'callback' => array(
176 $this->course_obj,
177 'course_detail',
178 ),
179 'args' => array(
180 'id' => array(
181 'validate_callback' => function ( $param ) {
182 return is_numeric( $param );
183 },
184 ),
185 ),
186 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
187 )
188 );
189
190 // Course topic.
191 register_rest_route(
192 $this->namespace,
193 '/topics',
194 array(
195 'methods' => 'GET',
196 'callback' => array(
197 $this->topic_obj,
198 'course_topic',
199 ),
200 'args' => array(
201 'course_id' => array(
202 'validate_callback' => function ( $param ) {
203 return is_numeric( $param );
204 },
205 ),
206 ),
207 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
208 )
209 );
210
211 // Lesson by topic.
212 register_rest_route(
213 $this->namespace,
214 '/lessons',
215 array(
216 'methods' => 'GET',
217 'callback' => array(
218 $this->lesson_obj,
219 'topic_lesson',
220 ),
221 'args' => array(
222 'topic_id' => array(
223 'validate_callback' => function ( $param ) {
224 return is_numeric( $param );
225 },
226 ),
227 ),
228 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
229 )
230 );
231
232 // Course announcement by course id.
233 register_rest_route(
234 $this->namespace,
235 '/course-announcement/(?P<id>\d+)',
236 array(
237 'methods' => 'GET',
238 'callback' => array(
239 $this->announcement_obj,
240 'course_announcement',
241 ),
242 'args' => array(
243 'id' => array(
244 'validate_callback' => function ( $param ) {
245 return is_numeric( $param );
246 },
247 ),
248 ),
249 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
250 )
251 );
252
253 // Quiz by topic id.
254 register_rest_route(
255 $this->namespace,
256 '/quizzes',
257 array(
258 'methods' => 'GET',
259 'callback' => array(
260 $this->quiz_obj,
261 'quiz_with_settings',
262 ),
263 'args' => array(
264 'topic_id' => array(
265 'validate_callback' => function ( $param ) {
266 return is_numeric( $param );
267 },
268 ),
269 ),
270 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
271 )
272 );
273
274 // Quiz by quiz id.
275 register_rest_route(
276 $this->namespace,
277 '/quizzes/(?P<id>\d+)',
278 array(
279 'methods' => 'GET',
280 'callback' => array(
281 $this->quiz_obj,
282 'get_quiz',
283 ),
284 'args' => array(
285 'id' => array(
286 'validate_callback' => function ( $param ) {
287 return is_numeric( $param );
288 },
289 ),
290 ),
291 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
292 )
293 );
294
295 // Quiz question answer by quiz id.
296 register_rest_route(
297 $this->namespace,
298 '/quiz-question-answer/(?P<id>\d+)',
299 array(
300 'methods' => 'GET',
301 'callback' => array(
302 $this->quiz_obj,
303 'quiz_question_ans',
304 ),
305 'args' => array(
306 'id' => array(
307 'validate_callback' => function ( $param ) {
308 return is_numeric( $param );
309 },
310 ),
311 ),
312 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
313 )
314 );
315
316 // Quiz attempt details by quiz id.
317 register_rest_route(
318 $this->namespace,
319 '/quiz-attempt-details/(?P<id>\d+)',
320 array(
321 'methods' => 'GET',
322 'callback' => array(
323 $this->quiz_obj,
324 'quiz_attempt_details',
325 ),
326 'args' => array(
327 'id' => array(
328 'validate_callback' => function ( $param ) {
329 return is_numeric( $param );
330 },
331 ),
332 ),
333 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
334 )
335 );
336
337 // Author detail by id.
338 register_rest_route(
339 $this->namespace,
340 '/author-information/(?P<id>\d+)',
341 array(
342 'methods' => 'GET',
343 'callback' => array(
344 $this->author_obj,
345 'author_detail',
346 ),
347 'args' => array(
348 'id' => array(
349 'validate_callback' => function ( $param ) {
350 return is_numeric( $param );
351 },
352 ),
353 ),
354 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
355 )
356 );
357
358 // Reviews by course id.
359 register_rest_route(
360 $this->namespace,
361 '/course-rating/(?P<id>\d+)',
362 array(
363 'methods' => 'GET',
364 'callback' => array(
365 $this->rating_obj,
366 'course_rating',
367 ),
368 'args' => array(
369 'id' => array(
370 'validate_callback' => function ( $param ) {
371 return is_numeric( $param );
372 },
373 ),
374 ),
375 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
376 )
377 );
378
379 // Get course content by id.
380 register_rest_route(
381 $this->namespace,
382 '/course-contents/(?P<id>\d+)',
383 array(
384 'methods' => 'GET',
385 'callback' => array(
386 $this->course_obj,
387 'course_contents',
388 ),
389 'args' => array(
390 'id' => array(
391 'validate_callback' => function ( $param ) {
392 return is_numeric( $param );
393 },
394 ),
395 ),
396 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
397 )
398 );
399 }
400 }
401