PluginProbe
Tutor LMS – eLearning and online course solution / 1.9.4
Tutor LMS – eLearning and online course solution v1.9.4
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 191 releases
← All changes | classes/RestAPI.php +169 -254 3.9.151.9.4 View file →
@@ -1,400 +1,315 @@
1 -<?php //phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
1 +<?php
2 2 /**
3 3 * RestAPI class
4 4 *
5 - * @package Tutor\API
6 - * @author Themeum <support@themeum.com>
7 - * @link https://themeum.com
8 - * @since 1.5.0
5 + * @author: themeum
6 + * @author_uri: https://themeum.com
7 + * @package Tutor
8 + * @since v.1.5.0
9 9 */
10 10
11 11 namespace TUTOR;
12 12
13 -if ( ! defined( 'ABSPATH' ) ) {
13 +if (!defined('ABSPATH'))
14 14 exit;
15 -}
16 15
17 -/**
18 - * Initialize REST API
19 - *
20 - * @since 1.5.0
21 - */
22 16 class RestAPI {
23 17
24 - /**
25 - * Custom validation trait
26 - */
27 18 use Custom_Validation;
28 19
29 - /**
30 - * API namespace
31 - *
32 - * @var string
33 - */
34 20 private $namespace = 'tutor/v1';
35 21
36 - /**
37 - * Course post type
38 - *
39 - * @var string
40 - */
41 22 protected $course_post_type;
42 23
43 - /**
44 - * Plugin dir Path
45 - *
46 - * @var string
47 - */
48 24 private $path;
49 25
50 - /**
51 - * Course Object
52 - *
53 - * @var object
54 - */
55 - private $course_obj;
26 + private $courseObj;
56 27
57 - /**
58 - * Topic Object
59 - *
60 - * @var object
61 - */
62 - private $topic_obj;
28 + private $topicObj;
63 29
64 - /**
65 - * Lesson Object
66 - *
67 - * @var object
68 - */
69 - private $lesson_obj;
30 + private $lessonObj;
70 31
71 - /**
72 - * Announcement Object
73 - *
74 - * @var object
75 - */
76 - private $announcement_obj;
32 + private $annoucementObj;
77 33
78 - /**
79 - * Quiz Object
80 - *
81 - * @var object
82 - */
83 - private $quiz_obj;
34 + private $quizObj;
84 35
85 - /**
86 - * Author Object
87 - *
88 - * @var object
89 - */
90 - private $author_obj;
36 + private $authorObj;
91 37
92 - /**
93 - * Rating Object
94 - *
95 - * @var object
96 - */
97 - private $rating_obj;
38 + private $ratingObj;
98 39
99 - /**
100 - * Manage dependencies
101 - *
102 - * @since 1.5.0
103 - */
104 40 public function __construct() {
105 41
106 - $this->path = plugin_dir_path( TUTOR_FILE );
42 + $this->path = plugin_dir_path(TUTOR_FILE);
43 + //autoloading clases
44 + if (function_exists('__autoload')) {
45 + spl_autoload_register('__autoload');
46 + }
47 + spl_autoload_register(array($this, 'loader'));
107 48
108 - spl_autoload_register( array( $this, 'loader' ) );
109 49
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();
50 + $this->courseObj = new REST_Course;
51 + $this->topicObj = new REST_Topic;
52 + $this->lessonObj = new REST_Lesson;
53 + $this->annoucementObj = new REST_Course_Announcement;
54 + $this->quizObj = new REST_Quiz;
55 + $this->authorObj = new REST_Author;
56 + $this->ratingObj = new REST_Rating;
117 57
118 - add_action( 'rest_api_init', array( $this, 'init_routes' ) );
58 + add_action('rest_api_init', array($this, 'init_routes'));
119 59 }
120 60
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
61 +
62 + private function loader($className) {
63 + if (!class_exists($className)) {
64 + $className = preg_replace(
65 + array('/([a-z])([A-Z])/', '/\\\/'),
66 + array('$1$2', DIRECTORY_SEPARATOR),
67 + $className
136 68 );
137 69
138 - $class_name = str_replace( 'TUTOR' . DIRECTORY_SEPARATOR, 'restapi' . DIRECTORY_SEPARATOR, $class_name );
139 - $file_name = $this->path . $class_name . '.php';
70 + $className = str_replace('TUTOR' . DIRECTORY_SEPARATOR, 'restapi' . DIRECTORY_SEPARATOR, $className);
71 + $file_name = $this->path . $className . '.php';
140 72
141 - if ( file_exists( $file_name ) ) {
73 + if (file_exists($file_name)) {
142 74 require_once $file_name;
143 75 }
144 76 }
145 77 }
146 78
147 - /**
148 - * Initialize routes
149 - *
150 - * @since 1.5.0
151 - *
152 - * @return void
153 - */
79 + /*
80 + init all routes for api
81 + */
154 82 public function init_routes() {
155 - // Courses.
83 + //courses
156 84 register_rest_route(
157 85 $this->namespace,
158 86 '/courses',
159 87 array(
160 - 'methods' => 'GET',
161 - 'callback' => array(
162 - $this->course_obj,
163 - 'course',
88 + 'methods' => "GET",
89 + 'callback' => array(
90 + $this->courseObj, 'course'
164 91 ),
165 - 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
92 + 'permission_callback' => '__return_true'
166 93 )
167 94 );
168 95
169 - // Course details.
96 + //courses by terms cat and tag
170 97 register_rest_route(
171 98 $this->namespace,
172 - '/courses/(?P<id>\d+)',
99 + '/course-by-terms',
173 100 array(
174 - 'methods' => 'GET',
175 - 'callback' => array(
176 - $this->course_obj,
177 - 'course_detail',
101 + 'methods' => "POST",
102 + 'callback' => array(
103 + $this->courseObj, 'course_by_terms'
178 104 ),
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' ),
105 + 'permission_callback' => '__return_true'
187 106 )
188 107 );
189 108
190 - // Course topic.
109 + //courses by terms cat and tag
191 110 register_rest_route(
192 111 $this->namespace,
193 - '/topics',
112 + '/course-sorting-by-price',
194 113 array(
195 - 'methods' => 'GET',
196 - 'callback' => array(
197 - $this->topic_obj,
198 - 'course_topic',
114 + 'methods' => "GET",
115 + 'callback' => array(
116 + $this->courseObj, 'course_sort_by_price'
199 117 ),
200 - 'args' => array(
201 - 'course_id' => array(
202 - 'validate_callback' => function ( $param ) {
203 - return is_numeric( $param );
204 - },
118 + 'args' => array(
119 + 'order' => array(
120 + 'required' => true,
121 + 'type' => 'string',
122 + 'validate_callback' => function ($order) {
123 + return $this->validate_order($order);
124 + }
205 125 ),
126 + 'page' => array(
127 + 'required' => false,
128 + 'type' => 'number'
129 + )
206 130 ),
207 - 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
131 + 'permission_callback' => '__return_true'
208 132 )
209 133 );
210 134
211 - // Lesson by topic.
135 + //course details
212 136 register_rest_route(
213 137 $this->namespace,
214 - '/lessons',
138 + '/course-detail/(?P<id>\d+)',
215 139 array(
216 - 'methods' => 'GET',
217 - 'callback' => array(
218 - $this->lesson_obj,
219 - 'topic_lesson',
140 + 'methods' => 'GET',
141 + 'callback' => array(
142 + $this->courseObj, 'course_detail'
220 143 ),
221 - 'args' => array(
222 - 'topic_id' => array(
223 - 'validate_callback' => function ( $param ) {
224 - return is_numeric( $param );
225 - },
226 - ),
144 + 'args' => array(
145 + 'id' => array(
146 + 'validate_callback' => function ($param) {
147 + return is_numeric($param);
148 + }
149 + )
227 150 ),
228 - 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
151 + 'permission_callback' => '__return_true'
229 152 )
230 153 );
231 154
232 - // Course announcement by course id.
155 + //course topic
233 156 register_rest_route(
234 157 $this->namespace,
235 - '/course-announcement/(?P<id>\d+)',
158 + '/course-topic/(?P<id>\d+)',
236 159 array(
237 - 'methods' => 'GET',
238 - 'callback' => array(
239 - $this->announcement_obj,
240 - 'course_announcement',
160 + 'methods' => 'GET',
161 + 'callback' => array(
162 + $this->topicObj, 'course_topic'
241 163 ),
242 - 'args' => array(
164 + 'args' => array(
243 165 'id' => array(
244 - 'validate_callback' => function ( $param ) {
245 - return is_numeric( $param );
246 - },
247 - ),
166 + 'validate_callback' => function ($param) {
167 + return is_numeric($param);
168 + }
169 + )
248 170 ),
249 - 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
171 + 'permission_callback' => '__return_true'
250 172 )
251 173 );
252 174
253 - // Quiz by topic id.
175 + //lesson by topic
254 176 register_rest_route(
255 177 $this->namespace,
256 - '/quizzes',
178 + '/lesson/(?P<id>\d+)',
257 179 array(
258 - 'methods' => 'GET',
259 - 'callback' => array(
260 - $this->quiz_obj,
261 - 'quiz_with_settings',
180 + 'methods' => 'GET',
181 + 'callback' => array(
182 + $this->lessonObj, 'topic_lesson'
262 183 ),
263 - 'args' => array(
264 - 'topic_id' => array(
265 - 'validate_callback' => function ( $param ) {
266 - return is_numeric( $param );
267 - },
268 - ),
184 + 'args' => array(
185 + 'id' => array(
186 + 'validate_callback' => function ($param) {
187 + return is_numeric($param);
188 + }
189 + )
269 190 ),
270 - 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
191 + 'permission_callback' => '__return_true'
271 192 )
272 193 );
273 194
274 - // Quiz by quiz id.
195 + //course annoucement by course id
275 196 register_rest_route(
276 197 $this->namespace,
277 - '/quizzes/(?P<id>\d+)',
198 + '/course-annoucement/(?P<id>\d+)',
278 199 array(
279 - 'methods' => 'GET',
280 - 'callback' => array(
281 - $this->quiz_obj,
282 - 'get_quiz',
200 + 'methods' => 'GET',
201 + 'callback' => array(
202 + $this->annoucementObj, 'course_annoucement'
283 203 ),
284 - 'args' => array(
204 + 'args' => array(
285 205 'id' => array(
286 - 'validate_callback' => function ( $param ) {
287 - return is_numeric( $param );
288 - },
289 - ),
206 + 'validate_callback' => function ($param) {
207 + return is_numeric($param);
208 + }
209 + )
290 210 ),
291 - 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
211 + 'permission_callback' => '__return_true'
292 212 )
293 213 );
294 214
295 - // Quiz question answer by quiz id.
215 + //quiz by topic id
296 216 register_rest_route(
297 217 $this->namespace,
298 - '/quiz-question-answer/(?P<id>\d+)',
218 + '/quiz/(?P<id>\d+)',
299 219 array(
300 - 'methods' => 'GET',
301 - 'callback' => array(
302 - $this->quiz_obj,
303 - 'quiz_question_ans',
220 + 'methods' => 'GET',
221 + 'callback' => array(
222 + $this->quizObj, 'quiz_with_settings'
304 223 ),
305 - 'args' => array(
224 + 'args' => array(
306 225 'id' => array(
307 - 'validate_callback' => function ( $param ) {
308 - return is_numeric( $param );
309 - },
310 - ),
226 + 'validate_callback' => function ($param) {
227 + return is_numeric($param);
228 + }
229 + )
311 230 ),
312 - 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
231 + 'permission_callback' => '__return_true'
313 232 )
314 233 );
315 234
316 - // Quiz attempt details by quiz id.
235 + //quiz question answer by quiz id
317 236 register_rest_route(
318 237 $this->namespace,
319 - '/quiz-attempt-details/(?P<id>\d+)',
238 + '/quiz-question-answer/(?P<id>\d+)',
320 239 array(
321 - 'methods' => 'GET',
322 - 'callback' => array(
323 - $this->quiz_obj,
324 - 'quiz_attempt_details',
240 + 'methods' => 'GET',
241 + 'callback' => array(
242 + $this->quizObj, 'quiz_question_ans'
325 243 ),
326 - 'args' => array(
244 + 'args' => array(
327 245 'id' => array(
328 - 'validate_callback' => function ( $param ) {
329 - return is_numeric( $param );
330 - },
331 - ),
246 + 'validate_callback' => function ($param) {
247 + return is_numeric($param);
248 + }
249 + )
332 250 ),
333 - 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
251 + 'permission_callback' => '__return_true'
334 252 )
335 253 );
336 254
337 - // Author detail by id.
255 + //quiz attempt details by quiz id
338 256 register_rest_route(
339 257 $this->namespace,
340 - '/author-information/(?P<id>\d+)',
258 + '/quiz-attempt-details/(?P<id>\d+)',
341 259 array(
342 - 'methods' => 'GET',
343 - 'callback' => array(
344 - $this->author_obj,
345 - 'author_detail',
260 + 'methods' => 'GET',
261 + 'callback' => array(
262 + $this->quizObj, 'quiz_attempt_details'
346 263 ),
347 - 'args' => array(
264 + 'args' => array(
348 265 'id' => array(
349 - 'validate_callback' => function ( $param ) {
350 - return is_numeric( $param );
351 - },
352 - ),
266 + 'validate_callback' => function ($param) {
267 + return is_numeric($param);
268 + }
269 + )
353 270 ),
354 - 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
271 + 'permission_callback' => '__return_true'
355 272 )
356 273 );
357 274
358 - // Reviews by course id.
275 + //author detail by id
359 276 register_rest_route(
360 277 $this->namespace,
361 - '/course-rating/(?P<id>\d+)',
278 + '/author-information/(?P<id>\d+)',
362 279 array(
363 - 'methods' => 'GET',
364 - 'callback' => array(
365 - $this->rating_obj,
366 - 'course_rating',
280 + 'methods' => 'GET',
281 + 'callback' => array(
282 + $this->authorObj, 'author_detail'
367 283 ),
368 - 'args' => array(
284 + 'args' => array(
369 285 'id' => array(
370 - 'validate_callback' => function ( $param ) {
371 - return is_numeric( $param );
372 - },
373 - ),
286 + 'validate_callback' => function ($param) {
287 + return is_numeric($param);
288 + }
289 + )
374 290 ),
375 - 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
291 + 'permission_callback' => '__return_true'
376 292 )
377 293 );
378 294
379 - // Get course content by id.
295 + //reviews by course id
380 296 register_rest_route(
381 297 $this->namespace,
382 - '/course-contents/(?P<id>\d+)',
298 + '/course-rating/(?P<id>\d+)',
383 299 array(
384 - 'methods' => 'GET',
385 - 'callback' => array(
386 - $this->course_obj,
387 - 'course_contents',
300 + 'methods' => 'GET',
301 + 'callback' => array(
302 + $this->ratingObj, 'course_rating'
388 303 ),
389 - 'args' => array(
304 + 'args' => array(
390 305 'id' => array(
391 - 'validate_callback' => function ( $param ) {
392 - return is_numeric( $param );
393 - },
394 - ),
306 + 'validate_callback' => function ($param) {
307 + return is_numeric($param);
308 + }
309 + )
395 310 ),
396 - 'permission_callback' => array( RestAuth::class, 'process_api_request' ),
311 + 'permission_callback' => '__return_true'
397 312 )
398 313 );
399 314 }
400 315 }