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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 / Tutor.php
tutor / classes Last commit date
Addons.php 7 years ago Admin.php 7 years ago Ajax.php 7 years ago Assets.php 7 years ago Course.php 7 years ago Gutenberg.php 7 years ago Instructor.php 7 years ago Instructors_List.php 7 years ago Lesson.php 7 years ago Options.php 7 years ago Post_types.php 7 years ago Q_and_A.php 7 years ago Question.php 7 years ago Question_Answers_List.php 7 years ago Quiz.php 7 years ago Quiz_Attempts_List.php 7 years ago Rewrite_Rules.php 7 years ago Shortcode.php 7 years ago Student.php 7 years ago Students_List.php 7 years ago Template.php 7 years ago Theme_Compatibility.php 7 years ago Tools.php 7 years ago Tutor.php 7 years ago TutorEDD.php 7 years ago Tutor_Base.php 7 years ago Tutor_List_Table.php 7 years ago User.php 7 years ago Utils.php 7 years ago Video_Stream.php 7 years ago Withdraw.php 7 years ago Withdraw_Requests_List.php 7 years ago WooCommerce.php 7 years ago
Tutor.php
550 lines
1 <?php
2 namespace TUTOR;
3
4 if ( ! defined( 'ABSPATH' ) )
5 exit;
6
7 final class Tutor{
8 public $version = TUTOR_VERSION;
9 public $path;
10 public $url;
11 public $basename;
12
13 /**
14 * The single instance of the class.
15 *
16 * @since v.1.2.0
17 */
18 protected static $_instance = null;
19
20 //Components
21 public $utils;
22 public $admin;
23 public $ajax;
24 public $options;
25 public $shortcode;
26
27 private $addons;
28 private $post_types;
29 private $assets;
30 private $course;
31 private $lesson;
32 private $rewrite_rules;
33 private $template;
34 private $instructor;
35 private $student;
36 private $q_and_a;
37 private $quiz;
38 private $question;
39 private $tools;
40 private $user;
41 private $theme_compatibility;
42 private $gutenberg;
43
44 private $woocommerce;
45 private $edd;
46 private $withdraw;
47
48 /**
49 * @return null|Tutor
50 *
51 * Run the TUTOR
52 *
53 * @since 1.2.0
54 */
55 public static function instance() {
56 if ( is_null( self::$_instance ) ) {
57 self::$_instance = new self();
58 }
59 return self::$_instance;
60 }
61
62 function __construct() {
63
64 $this->path = plugin_dir_path(TUTOR_FILE);
65 $this->url = plugin_dir_url(TUTOR_FILE);
66 $this->basename = plugin_basename(TUTOR_FILE);
67
68 /**
69 * Include Files
70 */
71 //add_action( 'init', array( $this, 'includes' ), 11 );
72 $this->includes();
73
74 /**
75 * Loading Autoloader
76 */
77
78 if ( function_exists( '__autoload' ) ) {
79 spl_autoload_register( '__autoload' );
80 }
81 spl_autoload_register(array($this, 'loader'));
82
83 do_action('tutor_before_load');
84
85 $this->addons = new Addons();
86 $this->post_types = new Post_types();
87 $this->assets = new Assets();
88 $this->admin = new Admin();
89 $this->ajax = new Ajax();
90 $this->options = new Options();
91 $this->shortcode = new Shortcode();
92 $this->course = new Course();
93 $this->lesson = new Lesson();
94 $this->rewrite_rules = new Rewrite_Rules();
95 $this->template = new Template();
96 $this->instructor = new Instructor();
97 $this->student = new Student();
98 $this->q_and_a = new Q_and_A();
99 $this->quiz = new Quiz();
100 $this->question = new Question();
101 $this->tools = new Tools();
102 $this->user = new User();
103 $this->theme_compatibility = new Theme_Compatibility();
104 $this->gutenberg = new Gutenberg();
105 $this->woocommerce = new WooCommerce();
106 $this->edd = new TutorEDD();
107 $this->withdraw = new Withdraw();
108
109 /**
110 * Run Method
111 * @since v.1.2.0
112 */
113 $this->run();
114
115 do_action('tutor_loaded');
116 }
117 /**
118 * @param $className
119 *
120 * Auto Load class and the files
121 */
122 private function loader($className) {
123 if ( ! class_exists($className)){
124 $className = preg_replace(
125 array('/([a-z])([A-Z])/', '/\\\/'),
126 array('$1$2', DIRECTORY_SEPARATOR),
127 $className
128 );
129
130 $className = str_replace('TUTOR'.DIRECTORY_SEPARATOR, 'classes'.DIRECTORY_SEPARATOR, $className);
131 $file_name = $this->path.$className.'.php';
132
133 if (file_exists($file_name) ) {
134 require_once $file_name;
135 }
136 }
137 }
138
139 public function includes(){
140 include tutor()->path.'includes/tutor-general-functions.php';
141 include tutor()->path.'includes/tutor-template-functions.php';
142 include tutor()->path.'includes/tutor-template-hook.php';
143 }
144
145 //Run the TUTOR right now
146 public function run(){
147 do_action('tutor_before_run');
148
149 register_activation_hook( TUTOR_FILE, array($this, 'tutor_activate' ) );
150 register_deactivation_hook(TUTOR_FILE, array($this, 'tutor_deactivation'));
151
152 do_action('tutor_after_run');
153 }
154
155 /**
156 * Do some task during plugin activation
157 */
158 public function tutor_activate(){
159 $version = get_option('tutor_version');
160 //Save Option
161 if ( ! $version){
162 //Create Database
163 $this->create_database();
164
165 $options = self::default_options();
166 update_option('tutor_option', $options);
167
168 //Rewrite Flush
169 update_option('required_rewrite_flush', time());
170 self::manage_tutor_roles_and_permissions();
171
172 self::save_data();//Save initial Page
173 update_option('tutor_version', TUTOR_VERSION);
174 }
175
176 //Set Schedule
177 if (! wp_next_scheduled ( 'tutor_once_in_day_run_schedule' )) {
178 wp_schedule_event(time(), 'twicedaily', 'tutor_once_in_day_run_schedule');
179 }
180
181 /**
182 * Backward Compatibility for version < 1.2.0
183 */
184 if (version_compare(get_option('TUTOR_VERSION'), '1.2.0', '<')){
185 /**
186 * Creating New Database
187 */
188 $this->create_withdraw_database();
189 //Update the tutor version
190 update_option('tutor_version', '1.2.0');
191 //Rewrite Flush
192 update_option('required_rewrite_flush', time());
193 }
194
195 }
196
197 //Run task on deactivation
198 public function tutor_deactivation() {
199 wp_clear_scheduled_hook('tutor_once_in_day_run_schedule');
200 }
201
202 public function create_database(){
203 global $wpdb;
204
205 $charset_collate = $wpdb->get_charset_collate();
206
207 /**
208 * Table SQL
209 *
210 * {$wpdb->prefix}tutor_quiz_attempts
211 * {$wpdb->prefix}tutor_quiz_attempt_answers
212 * {$wpdb->prefix}tutor_quiz_questions
213 * {$wpdb->prefix}tutor_quiz_question_answers
214 * {$wpdb->prefix}tutor_earnings
215 * {$wpdb->prefix}tutor_withdraws
216 *
217 * @since v.1.0.0
218 */
219 $quiz_attempts_sql = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempts (
220 attempt_id int(11) NOT NULL AUTO_INCREMENT,
221 course_id int(11) DEFAULT NULL,
222 quiz_id int(11) DEFAULT NULL,
223 user_id int(11) DEFAULT NULL,
224 total_questions int(11) DEFAULT NULL,
225 total_answered_questions int(11) DEFAULT NULL,
226 total_marks decimal(9,2) DEFAULT NULL,
227 earned_marks decimal(9,2) DEFAULT NULL,
228 attempt_info text,
229 attempt_status varchar(50) DEFAULT NULL,
230 attempt_ip varchar(250) DEFAULT NULL,
231 attempt_started_at datetime DEFAULT NULL,
232 attempt_ended_at datetime DEFAULT NULL,
233 is_manually_reviewed int(1) DEFAULT NULL,
234 manually_reviewed_at datetime DEFAULT NULL,
235 PRIMARY KEY (attempt_id)
236 ) $charset_collate;";
237
238 $quiz_attempt_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempt_answers (
239 attempt_answer_id int(11) NOT NULL AUTO_INCREMENT,
240 user_id int(11) DEFAULT NULL,
241 quiz_id int(11) DEFAULT NULL,
242 question_id int(11) DEFAULT NULL,
243 quiz_attempt_id int(11) DEFAULT NULL,
244 given_answer longtext,
245 question_mark decimal(8,2) DEFAULT NULL,
246 achieved_mark decimal(8,2) DEFAULT NULL,
247 minus_mark decimal(8,2) DEFAULT NULL,
248 is_correct tinyint(4) DEFAULT NULL,
249 PRIMARY KEY (attempt_answer_id)
250 ) $charset_collate;";
251
252 $tutor_quiz_questions = "CREATE TABLE {$wpdb->prefix}tutor_quiz_questions (
253 question_id int(11) NOT NULL AUTO_INCREMENT,
254 quiz_id int(11) DEFAULT NULL,
255 question_title text,
256 question_description longtext,
257 question_type varchar(50) DEFAULT NULL,
258 question_mark decimal(9,2) DEFAULT NULL,
259 question_settings longtext,
260 question_order int(11) DEFAULT NULL,
261 PRIMARY KEY (question_id)
262 ) $charset_collate;";
263
264 $tutor_quiz_question_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_question_answers (
265 answer_id int(11) NOT NULL AUTO_INCREMENT,
266 belongs_question_id int(11) DEFAULT NULL,
267 belongs_question_type varchar(250) DEFAULT NULL,
268 answer_title text,
269 is_correct tinyint(4) DEFAULT NULL,
270 image_id int(11) DEFAULT NULL,
271 answer_two_gap_match text,
272 answer_view_format varchar(250) DEFAULT NULL,
273 answer_settings text,
274 answer_order int(11) DEFAULT '0',
275 PRIMARY KEY (answer_id)
276 ) $charset_collate;";
277
278 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
279 earning_id int(11) NOT NULL AUTO_INCREMENT,
280 user_id int(11) DEFAULT NULL,
281 course_id int(11) DEFAULT NULL,
282 order_id int(11) DEFAULT NULL,
283 order_status varchar(50) DEFAULT NULL,
284 course_price_total decimal(16,2) DEFAULT NULL,
285 course_price_grand_total decimal(16,2) DEFAULT NULL,
286 instructor_amount decimal(16,2) DEFAULT NULL,
287 instructor_rate decimal(16,2) DEFAULT NULL,
288 admin_amount decimal(16,2) DEFAULT NULL,
289 admin_rate decimal(16,2) DEFAULT NULL,
290 commission_type varchar(20) DEFAULT NULL,
291 deduct_fees_amount decimal(16,2) DEFAULT NULL,
292 deduct_fees_name varchar(250) DEFAULT NULL,
293 deduct_fees_type varchar(20) DEFAULT NULL,
294 process_by varchar(20) DEFAULT NULL,
295 created_at datetime DEFAULT NULL,
296 PRIMARY KEY (earning_id)
297 ) $charset_collate;";
298
299 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
300 withdraw_id int(11) NOT NULL AUTO_INCREMENT,
301 user_id int(11) DEFAULT NULL,
302 amount decimal(16,2) DEFAULT NULL,
303 method_data text DEFAULT NULL,
304 status varchar(50) DEFAULT NULL,
305 updated_at datetime DEFAULT NULL,
306 created_at datetime DEFAULT NULL,
307 PRIMARY KEY (withdraw_id)
308 ) $charset_collate;";
309
310 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
311 dbDelta( $quiz_attempts_sql );
312 dbDelta( $quiz_attempt_answers );
313 dbDelta( $tutor_quiz_questions );
314 dbDelta( $tutor_quiz_question_answers );
315 dbDelta( $earning_table );
316 dbDelta( $withdraw_table );
317 }
318
319 public static function manage_tutor_roles_and_permissions(){
320 /**
321 * Add role for instructor
322 */
323 $instructor_role = tutor()->instructor_role;
324
325 remove_role($instructor_role);
326 add_role( $instructor_role, __('Tutor Instructor', 'tutor'), array() );
327
328 $custom_post_type_permission = array(
329 //Manage Instructor
330 'manage_tutor_instructor',
331
332 //Tutor Posts Type Permission
333 'edit_tutor_course',
334 'read_tutor_course',
335 'delete_tutor_course',
336 'delete_tutor_courses',
337 'edit_tutor_courses',
338 'edit_others_tutor_courses',
339 'read_private_tutor_courses',
340 'edit_tutor_courses',
341
342 'edit_tutor_lesson',
343 'read_tutor_lesson',
344 'delete_tutor_lesson',
345 'delete_tutor_lessons',
346 'edit_tutor_lessons',
347 'edit_others_tutor_lessons',
348 'read_private_tutor_lessons',
349 'edit_tutor_lessons',
350 'publish_tutor_lessons',
351
352 'edit_tutor_quiz',
353 'read_tutor_quiz',
354 'delete_tutor_quiz',
355 'delete_tutor_quizzes',
356 'edit_tutor_quizzes',
357 'edit_others_tutor_quizzes',
358 'read_private_tutor_quizzes',
359 'edit_tutor_quizzes',
360 'publish_tutor_quizzes',
361
362 'edit_tutor_question',
363 'read_tutor_question',
364 'delete_tutor_question',
365 'delete_tutor_questions',
366 'edit_tutor_questions',
367 'edit_others_tutor_questions',
368 'publish_tutor_questions',
369 'read_private_tutor_questions',
370 'edit_tutor_questions',
371 );
372
373 $instructor = get_role( $instructor_role );
374 if ( $instructor ) {
375 $instructor_cap = array (
376 'edit_posts',
377 'read',
378 'upload_files',
379 );
380
381 $instructor_cap = array_merge($instructor_cap, $custom_post_type_permission);
382
383 $can_publish_course = (bool) tutor_utils()->get_option('instructor_can_publish_course');
384 if ($can_publish_course){
385 $instructor_cap[] = 'publish_tutor_courses';
386 }
387
388 foreach ($instructor_cap as $cap){
389 $instructor->add_cap( $cap );
390 }
391 }
392
393 $administrator = get_role( 'administrator' );
394 if ( $administrator ) {
395
396 $administrator_cap = array (
397 'manage_tutor',
398 );
399 $administrator_cap = array_merge($administrator_cap, $custom_post_type_permission);
400 $administrator_cap[] = 'publish_tutor_courses';
401
402 foreach ($administrator_cap as $cap){
403 $administrator->add_cap( $cap );
404 }
405 }
406
407 /**
408 * Add Instructor role to administrator
409 */
410 if (current_user_can('administrator')){
411 tutor_utils()->add_instructor_role(get_current_user_id());
412 }
413
414 }
415
416 /**
417 * Save data like page
418 */
419 public static function save_data(){
420 $student_dashboard_args = array(
421 'post_title' => __('Dashboard', 'tutor'),
422 'post_content' => '',
423 'post_type' => 'page',
424 'post_status' => 'publish',
425 );
426 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
427 tutor_utils()->update_option('tutor_dashboard_page_id', $student_dashboard_page_id);
428
429 $student_registration_args = array(
430 'post_title' => __('Student Registration', 'tutor'),
431 'post_content' => '[tutor_student_registration_form]',
432 'post_type' => 'page',
433 'post_status' => 'publish',
434 );
435 $student_register_page_id = wp_insert_post( $student_registration_args );
436 tutor_utils()->update_option('student_register_page', $student_register_page_id);
437
438 $instructor_registration_args = array(
439 'post_title' => __('Instructor Registration', 'tutor'),
440 'post_content' => '[tutor_instructor_registration_form]',
441 'post_type' => 'page',
442 'post_status' => 'publish',
443 );
444 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
445 tutor_utils()->update_option('instructor_register_page', $instructor_registration_id);
446 }
447
448 public static function default_options(){
449 $options = array (
450 'load_tutor_css' => '1',
451 'load_tutor_js' => '1',
452 'course_allow_upload_private_files' => '1',
453 'display_course_instructors' => '1',
454 'enable_q_and_a_on_course' => '1',
455 'courses_col_per_row' => '3',
456 'courses_per_page' => '3',
457 'lesson_permalink_base' => 'lesson',
458 'quiz_time_limit' =>
459 array (
460 'value' => '0',
461 'time' => 'minutes',
462 ),
463 'quiz_when_time_expires' => 'autosubmit',
464 'quiz_attempts_allowed' => '10',
465 'quiz_grade_method' => 'highest_grade',
466 'enable_public_profile' => '1',
467 'email_to_students' =>
468 array (
469 'quiz_completed' => '1',
470 'completed_course' => '1',
471 ),
472 'email_to_instructors' =>
473 array (
474 'a_student_enrolled_in_course' => '1',
475 'a_student_completed_course' => '1',
476 'a_student_completed_lesson' => '1',
477 'a_student_placed_question' => '1',
478 ),
479 'email_from_name' => get_option('blogname'),
480 'email_from_address' => get_option('admin_email'),
481 'email_footer_text' => '',
482 );
483 return $options;
484 }
485
486
487 /**
488 * Create withdraw database
489 *
490 * @since v.1.2.0
491 */
492 public function create_withdraw_database(){
493 global $wpdb;
494
495 $charset_collate = $wpdb->get_charset_collate();
496
497 /**
498 * Table SQL
499 *
500 * {$wpdb->prefix}tutor_earnings
501 * {$wpdb->prefix}tutor_withdraws
502 *
503 * @since v.1.2.0
504 */
505
506 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
507 earning_id int(11) NOT NULL AUTO_INCREMENT,
508 user_id int(11) DEFAULT NULL,
509 course_id int(11) DEFAULT NULL,
510 order_id int(11) DEFAULT NULL,
511 order_status varchar(50) DEFAULT NULL,
512 course_price_total decimal(16,2) DEFAULT NULL,
513 course_price_grand_total decimal(16,2) DEFAULT NULL,
514 instructor_amount decimal(16,2) DEFAULT NULL,
515 instructor_rate decimal(16,2) DEFAULT NULL,
516 admin_amount decimal(16,2) DEFAULT NULL,
517 admin_rate decimal(16,2) DEFAULT NULL,
518 commission_type varchar(20) DEFAULT NULL,
519 deduct_fees_amount decimal(16,2) DEFAULT NULL,
520 deduct_fees_name varchar(250) DEFAULT NULL,
521 deduct_fees_type varchar(20) DEFAULT NULL,
522 process_by varchar(20) DEFAULT NULL,
523 created_at datetime DEFAULT NULL,
524 PRIMARY KEY (earning_id)
525 ) $charset_collate;";
526
527 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
528 withdraw_id int(11) NOT NULL AUTO_INCREMENT,
529 user_id int(11) DEFAULT NULL,
530 amount decimal(16,2) DEFAULT NULL,
531 method_data text DEFAULT NULL,
532 status varchar(50) DEFAULT NULL,
533 updated_at datetime DEFAULT NULL,
534 created_at datetime DEFAULT NULL,
535 PRIMARY KEY (withdraw_id)
536 ) $charset_collate;";
537
538 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
539 dbDelta( $earning_table );
540 dbDelta( $withdraw_table );
541
542 /**
543 * Setting previous dashboard to new dashboard
544 */
545 $previous_dashboard_page_id = (int) tutor_utils()->get_option('student_dashboard');
546 tutor_utils()->update_option('tutor_dashboard_page_id', $previous_dashboard_page_id);
547 }
548
549
550 }