PluginProbe
WP Courses LMS – Online Courses Builder, eLearning Courses, Courses Solution, Education Courses / trunk
WP Courses LMS – Online Courses Builder, eLearning Courses, Courses Solution, Education Courses vtrunk
3.2.30 trunk 3.1.40 3.1.41 3.1.42 3.1.43 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.23 3.2.24 3.2.25 All 36 releases
wp-courses / db / db-tables.php

db-tables.php in WP Courses LMS – Online Courses Builder, eLearning Courses, Courses Solution, Education Courses trunk, at db/db-tables.php

164 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 /********** TRACKING **********/
5
6
7
8 function wpc_create_tracking_table() {
9
10 global $wpdb;
11 add_option('wpc_tracking_table_version', "1.0");
12 $table_name = $wpdb->prefix . 'wpc_tracking';
13 $charset_collate = $wpdb->get_charset_collate();
14
15 $sql = "CREATE TABLE $table_name (
16 id bigint(20) NOT NULL AUTO_INCREMENT,
17 user_id bigint(20),
18 post_id bigint(20) NOT NULL,
19 course_id bigint(20),
20 viewed_timestamp bigint(20),
21 completed_timestamp bigint(20),
22 completed tinyint(1),
23 primary key (id)
24 ) $charset_collate;";
25
26 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
27 dbDelta( $sql );
28
29 // ports old usermeta to new tracking table
30 wpc_port_postmeta_tracking_to_table();
31 }
32
33 register_activation_hook( __FILE__, 'wpc_create_tracking_table');
34
35 function wpc_update_db_tracking_table_check() {
36 $ver = get_site_option( "wpc_tracking_table_version");
37 if($ver != "1.0") {
38 wpc_create_tracking_table();
39 }
40 }
41
42 add_action( 'plugins_loaded', 'wpc_update_db_tracking_table_check' );
43
44
45
46 /********** CONNECTIONS **********/
47
48
49
50 function wpc_create_connections_table() {
51 global $wpdb;
52 add_option( "wpc_connections_table_version", "1.0");
53 $table_name = $wpdb->prefix . "wpc_connections";
54 $charset_collate = $wpdb->get_charset_collate();
55
56 $sql = "CREATE TABLE $table_name (
57 id bigint(20) NOT NULL AUTO_INCREMENT,
58 post_from bigint(20),
59 post_to bigint(20),
60 connection_type varchar(255),
61 menu_order int(11),
62 PRIMARY KEY (id)
63 ) $charset_collate";
64
65 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
66 dbDelta( $sql );
67
68 wpc_port_postmeta_to_connections_table();
69 }
70 register_activation_hook( __FILE__, 'wpc_create_connections_table' );
71
72 function wpc_update_connections_table_check() {
73 $ver = get_site_option( "wpc_connections_table_version" );
74 if ( $ver != "1.0" ) {
75 wpc_create_connections_table();
76 }
77 }
78 add_action( 'init', 'wpc_update_connections_table_check' );
79
80
81
82 /********** REQUIREMENTS **********/
83
84
85
86 function wpc_create_requirements_table() {
87 global $wpdb;
88 add_option( "wpc_db_version", "1.0" );
89 $table_name = $wpdb->prefix . 'wpc_rules';
90 $charset_collate = $wpdb->get_charset_collate();
91
92 $sql = "CREATE TABLE $table_name (
93 id bigint(20) NOT NULL AUTO_INCREMENT,
94 post_id bigint(20) NOT NULL,
95 course_id bigint(20),
96 lesson_id bigint(20),
97 module_id bigint(20),
98 action varchar(255),
99 type varchar(255),
100 percent TINYINT,
101 times bigint(20),
102 PRIMARY KEY (id)
103 ) $charset_collate;";
104
105 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
106 dbDelta( $sql );
107 }
108 register_activation_hook( __FILE__, 'wpc_create_requirements_table' );
109
110 function wpc_update_db_check() {
111 $ver = get_site_option( "wpc_db_version" );
112 if ( $ver != "1.0" ) {
113 wpc_create_requirements_table();
114 }
115 }
116 add_action( 'plugins_loaded', 'wpc_update_db_check' );
117
118
119
120
121 /********** QUIZZES **********/
122
123
124
125 function wpcq_install() {
126 global $wpdb;
127 add_option('wpc_quiz_table_version', "1.1");
128 $table_name = $wpdb->prefix . 'wpc_quiz_results';
129
130 $charset_collate = $wpdb->get_charset_collate();
131
132 $sql = "CREATE TABLE $table_name (
133 id bigint(20) NOT NULL AUTO_INCREMENT,
134 time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
135 user_ID bigint(20) NOT NULL,
136 quiz_ID bigint(20) NOT NULL,
137 quiz_result text NOT NULL,
138 score_percent mediumint(3) NOT NULL,
139 PRIMARY KEY (id)
140 ) $charset_collate;";
141
142 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
143 dbDelta( $sql );
144 }
145
146 register_activation_hook( __FILE__, 'wpcq_install' );
147
148 function wpcq_update_quiz_table_check() {
149 $ver = get_site_option( "wpc_quiz_table_version");
150 if($ver != "1.1") {
151 update_option('wpc_quiz_table_version', "1.1");
152 wpcq_install();
153 wpcq_course_id_column();
154 }
155 }
156
157 add_action( 'plugins_loaded', 'wpcq_update_quiz_table_check' );
158
159 function wpcq_course_id_column() {
160 global $wpdb;
161 $table_name = $wpdb->prefix . 'wpc_quiz_results';
162 $wpdb->query("ALTER TABLE $table_name ADD course_id bigint(20)");
163 }
164 ?>