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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
541 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 $administrator_cap = array (
396 'manage_tutor',
397 );
398 $administrator_cap = array_merge($administrator_cap, $custom_post_type_permission);
399 $administrator_cap[] = 'publish_tutor_courses';
400
401 foreach ($administrator_cap as $cap){
402 $administrator->add_cap( $cap );
403 }
404 }
405 }
406
407 /**
408 * Save data like page
409 */
410 public static function save_data(){
411 $student_dashboard_args = array(
412 'post_title' => __('Dashboard', 'tutor'),
413 'post_content' => '',
414 'post_type' => 'page',
415 'post_status' => 'publish',
416 );
417 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
418 tutor_utils()->update_option('tutor_dashboard_page_id', $student_dashboard_page_id);
419
420 $student_registration_args = array(
421 'post_title' => __('Student Registration', 'tutor'),
422 'post_content' => '[tutor_student_registration_form]',
423 'post_type' => 'page',
424 'post_status' => 'publish',
425 );
426 $student_register_page_id = wp_insert_post( $student_registration_args );
427 tutor_utils()->update_option('student_register_page', $student_register_page_id);
428
429 $instructor_registration_args = array(
430 'post_title' => __('Instructor Registration', 'tutor'),
431 'post_content' => '[tutor_instructor_registration_form]',
432 'post_type' => 'page',
433 'post_status' => 'publish',
434 );
435 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
436 tutor_utils()->update_option('instructor_register_page', $instructor_registration_id);
437 }
438
439 public static function default_options(){
440 $options = array (
441 'load_tutor_css' => '1',
442 'load_tutor_js' => '1',
443 'course_allow_upload_private_files' => '1',
444 'display_course_instructors' => '1',
445 'enable_q_and_a_on_course' => '1',
446 'courses_col_per_row' => '3',
447 'courses_per_page' => '3',
448 'lesson_permalink_base' => 'lesson',
449 'quiz_time_limit' =>
450 array (
451 'value' => '0',
452 'time' => 'minutes',
453 ),
454 'quiz_when_time_expires' => 'autosubmit',
455 'quiz_attempts_allowed' => '10',
456 'quiz_grade_method' => 'highest_grade',
457 'enable_public_profile' => '1',
458 'email_to_students' =>
459 array (
460 'quiz_completed' => '1',
461 'completed_course' => '1',
462 ),
463 'email_to_instructors' =>
464 array (
465 'a_student_enrolled_in_course' => '1',
466 'a_student_completed_course' => '1',
467 'a_student_completed_lesson' => '1',
468 'a_student_placed_question' => '1',
469 ),
470 'email_from_name' => get_option('blogname'),
471 'email_from_address' => get_option('admin_email'),
472 'email_footer_text' => '',
473 );
474 return $options;
475 }
476
477
478 /**
479 * Create withdraw database
480 *
481 * @since v.1.2.0
482 */
483 public function create_withdraw_database(){
484 global $wpdb;
485
486 $charset_collate = $wpdb->get_charset_collate();
487
488 /**
489 * Table SQL
490 *
491 * {$wpdb->prefix}tutor_earnings
492 * {$wpdb->prefix}tutor_withdraws
493 *
494 * @since v.1.2.0
495 */
496
497 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
498 earning_id int(11) NOT NULL AUTO_INCREMENT,
499 user_id int(11) DEFAULT NULL,
500 course_id int(11) DEFAULT NULL,
501 order_id int(11) DEFAULT NULL,
502 order_status varchar(50) DEFAULT NULL,
503 course_price_total decimal(16,2) DEFAULT NULL,
504 course_price_grand_total decimal(16,2) DEFAULT NULL,
505 instructor_amount decimal(16,2) DEFAULT NULL,
506 instructor_rate decimal(16,2) DEFAULT NULL,
507 admin_amount decimal(16,2) DEFAULT NULL,
508 admin_rate decimal(16,2) DEFAULT NULL,
509 commission_type varchar(20) DEFAULT NULL,
510 deduct_fees_amount decimal(16,2) DEFAULT NULL,
511 deduct_fees_name varchar(250) DEFAULT NULL,
512 deduct_fees_type varchar(20) DEFAULT NULL,
513 process_by varchar(20) DEFAULT NULL,
514 created_at datetime DEFAULT NULL,
515 PRIMARY KEY (earning_id)
516 ) $charset_collate;";
517
518 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
519 withdraw_id int(11) NOT NULL AUTO_INCREMENT,
520 user_id int(11) DEFAULT NULL,
521 amount decimal(16,2) DEFAULT NULL,
522 method_data text DEFAULT NULL,
523 status varchar(50) DEFAULT NULL,
524 updated_at datetime DEFAULT NULL,
525 created_at datetime DEFAULT NULL,
526 PRIMARY KEY (withdraw_id)
527 ) $charset_collate;";
528
529 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
530 dbDelta( $earning_table );
531 dbDelta( $withdraw_table );
532
533 /**
534 * Setting previous dashboard to new dashboard
535 */
536 $previous_dashboard_page_id = (int) tutor_utils()->get_option('student_dashboard');
537 tutor_utils()->update_option('tutor_dashboard_page_id', $previous_dashboard_page_id);
538 }
539
540
541 }