PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.3.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.3.2
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / admin / sub-menus / class-lp-submenu-statistics.php

class-lp-submenu-statistics.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7.3.2, at inc/admin/sub-menus/class-lp-submenu-statistics.php

235 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class LP_Submenu_Statistics
5 *
6 * @since 3.0.0
7 */
8 class LP_Submenu_Statistics extends LP_Abstract_Submenu {
9 /**
10 * LP_Submenu_Statistics constructor.
11 */
12 public function __construct() {
13 $this->id = 'learn-press-statistics';
14 $this->menu_title = __( 'Statistics', 'learnpress' );
15 $this->page_title = __( 'LearnPress Statistics', 'learnpress' );
16 $this->priority = 10;
17 $this->callback = [ $this, 'display' ];
18
19 if ( current_user_can( LP_TEACHER_ROLE ) ) {
20 $tabs = array(
21 'courses' => __( 'Courses', 'learnpress' ),
22 'orders' => __( 'Orders', 'learnpress' ),
23 );
24 } else {
25 $tabs = array(
26 'general' => __( 'General', 'learnpress' ),
27 'users' => __( 'Users', 'learnpress' ),
28 'courses' => __( 'Courses', 'learnpress' ),
29 'orders' => __( 'Orders', 'learnpress' ),
30 );
31 }
32
33 $this->tabs = apply_filters(
34 'learn-press/admin/page-statistic-tabs',
35 $tabs
36 );
37
38 //add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
39
40 parent::__construct();
41 }
42
43 public function load_chart() {
44 $type = learn_press_get_request( 'type' );
45 $response = null;
46 switch ( $type ) {
47 case 'user-last-7-days':
48 $response = learn_press_get_chart_users( null, 'days', 7 );
49 break;
50 case 'user-last-30-days':
51 $response = learn_press_get_chart_users( null, 'days', 30 );
52 break;
53 case 'user-last-12-months':
54 $response = learn_press_get_chart_users( null, 'months', 12 );
55 break;
56 case 'user-custom-time':
57 $range = learn_press_get_request( 'range' );
58 $from_time = strtotime( $range[0] );
59 $to_time = strtotime( $range[1] );
60 list( $from_d, $from_m, $from_y ) = explode( ' ', gmdate( 'd m Y', $from_time ) );
61 list( $to_d, $to_m, $to_y ) = explode( ' ', gmdate( 'd m Y', $to_time ) );
62
63 if ( $from_y != $to_y ) {
64 $response = learn_press_get_chart_users( $to_time, 'years', $to_y - $from_y + 1 );
65 } else {
66 if ( $from_m != $to_m ) {
67 $response = learn_press_get_chart_users( $to_time, 'months', $to_m - $from_m + 1 );
68 } else {
69 $response = learn_press_get_chart_users( $to_time, 'days', $to_d - $from_d + 1 );
70 }
71 }
72 break;
73 case 'user-all':
74 global $wpdb;
75 $results = $wpdb->get_row(
76 "
77 SELECT min(u.user_registered) as `from`, max(u.user_registered) as `to`
78 FROM {$wpdb->users} u
79 "
80 );
81
82 if ( $results ) {
83 $_POST['range'] = array(
84 gmdate( 'Y/m/d', strtotime( $results->from ) ),
85 gmdate( 'Y/m/d', strtotime( $results->to ) ),
86 );
87 $_POST['type'] = 'user-custom-time';
88 $this->load_chart();
89
90 return;
91 }
92 break;
93
94 case 'course-last-7-days':
95 $response = learn_press_get_chart_courses( null, 'days', 7 );
96 break;
97 case 'course-last-30-days':
98 $response = learn_press_get_chart_courses( null, 'days', 30 );
99 break;
100 case 'course-last-12-months':
101 $response = learn_press_get_chart_courses( null, 'months', 12 );
102 break;
103 case 'course-custom-time':
104 $range = learn_press_get_request( 'range' );
105 $from_time = strtotime( $range[0] );
106 $to_time = strtotime( $range[1] );
107 list( $from_d, $from_m, $from_y ) = explode( ' ', gmdate( 'd m Y', $from_time ) );
108 list( $to_d, $to_m, $to_y ) = explode( ' ', gmdate( 'd m Y', $to_time ) );
109
110 if ( $from_y != $to_y ) {
111 $months = abs( ( gmdate( 'Y', $to_time ) - gmdate( 'Y', $from_time ) ) * 12 + ( gmdate( 'm', $to_time ) - gmdate( 'm', $from_time ) ) ) + 1;
112 if ( $months > 12 ) {
113 $response = learn_press_get_chart_courses( $to_time, 'years', $to_y - $from_y + 1 );
114 } else {
115 $response = learn_press_get_chart_courses( $to_time, 'months', $months );
116 }
117 } else {
118 if ( $from_m != $to_m ) {
119 $response = learn_press_get_chart_courses( $to_time, 'months', $to_m - $from_m + 1 );
120 } else {
121 $response = learn_press_get_chart_courses( $to_time, 'days', $to_d - $from_d + 1 );
122 }
123 }
124
125 break;
126 case 'course-all':
127 global $wpdb;
128 $results = $wpdb->get_row(
129 $wpdb->prepare(
130 "
131 SELECT min(c.post_date) as `from`, max(c.post_date) as `to`
132 FROM {$wpdb->posts} c
133 WHERE c.post_date <> %s
134 AND c.post_type = %s
135 ",
136 '0000-00-00 00:00:00',
137 'lp_course'
138 )
139 );
140
141 if ( $results ) {
142 $_POST['range'] = array(
143 gmdate( 'Y/m/d', strtotime( $results->from ) ),
144 gmdate( 'Y/m/d', strtotime( $results->to ) ),
145 );
146 $_POST['type'] = 'course-custom-time';
147 $this->load_chart();
148
149 return;
150 }
151 break;
152
153 case 'order-last-7-days':
154 $response = learn_press_get_chart_orders( null, 'days', 7 );
155 break;
156 case 'order-last-30-days':
157 $response = learn_press_get_chart_orders( null, 'days', 30 );
158 break;
159 case 'order-last-12-months':
160 $response = learn_press_get_chart_orders( null, 'months', 12 );
161 break;
162 case 'order-custom-time':
163 $range = learn_press_get_request( 'range' );
164 $from_time = strtotime( $range[0] );
165 $to_time = strtotime( $range[1] );
166 list( $from_d, $from_m, $from_y ) = explode( ' ', gmdate( 'd m Y', $from_time ) );
167 list( $to_d, $to_m, $to_y ) = explode( ' ', gmdate( 'd m Y', $to_time ) );
168
169 if ( $from_y != $to_y ) {
170 $months = abs( ( gmdate( 'Y', $to_time ) - gmdate( 'Y', $from_time ) ) * 12 + ( gmdate( 'm', $to_time ) - gmdate( 'm', $from_time ) ) ) + 1;
171 if ( $months > 12 ) {
172 $response = learn_press_get_chart_orders( $to_time, 'years', $to_y - $from_y + 1 );
173 } else {
174 $response = learn_press_get_chart_orders( $to_time, 'months', $months );
175 }
176 } else {
177 if ( $from_m != $to_m ) {
178 $response = learn_press_get_chart_orders( $to_time, 'months', $to_m - $from_m + 1 );
179 } else {
180 $response = learn_press_get_chart_orders( $to_time, 'days', $to_d - $from_d + 1 );
181 }
182 }
183
184 break;
185 case 'order-all':
186 global $wpdb;
187
188 $results = $wpdb->get_row(
189 $wpdb->prepare(
190 "
191 SELECT min(c.post_date) as `from`, max(c.post_date) as `to`
192 FROM {$wpdb->posts} c
193 WHERE c.post_date <> %s
194 AND c.post_type = %s
195 ",
196 '0000-00-00 00:00:00',
197 'lp_order'
198 )
199 );
200
201 if ( $results ) {
202 $_POST['range'] = array(
203 gmdate( 'Y/m/d', strtotime( $results->from ) ),
204 gmdate( 'Y/m/d', strtotime( $results->to ) ),
205 );
206 $_POST['type'] = 'order-custom-time';
207 $this->load_chart();
208
209 return;
210 }
211 }
212
213 learn_press_send_json( $response );
214 }
215
216 public function page_content_courses() {
217 learn_press_admin_view( 'statistics/courses' );
218 }
219
220 public function page_content_general() {
221 learn_press_admin_view( 'statistics/general' );
222 }
223
224 public function page_content_users() {
225 learn_press_admin_view( 'statistics/users' );
226 }
227
228 public function page_content_orders() {
229 learn_press_admin_view( 'statistics/orders' );
230 }
231
232 }
233
234 return new LP_Submenu_Statistics();
235