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