Completed
Push — master ( e0e7fb...5987fc )
by
unknown
19:20
created
wps_statistics/templates/backend/wps_statistics_most_viewed_products.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,27 +1,27 @@
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
2
-	$products = $this->wps_stats_mdl->wps_most_viewed_products_datas( $main_stats_count );
3
-	if ( !empty( $products ) ) :
1
+<?php if (!defined('ABSPATH')) exit;
2
+	$products = $this->wps_stats_mdl->wps_most_viewed_products_datas($main_stats_count);
3
+	if (!empty($products)) :
4 4
 ?>
5 5
 <div class="wps-table">
6 6
 	<?php
7
-		foreach( $products as $item_id => $product ) :
8
-			$product_type = get_post_type( $product->post_id );
9
-			if ( $product_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) :
10
-				$product_name = get_the_title( $product->post_id );
7
+		foreach ($products as $item_id => $product) :
8
+			$product_type = get_post_type($product->post_id);
9
+			if ($product_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) :
10
+				$product_name = get_the_title($product->post_id);
11 11
 			else :
12
-				$parent_def = wpshop_products::get_parent_variation( $product->post_id );
13
-				if ( !empty($parent_def) && !empty($parent_def['parent_post']) ) :
12
+				$parent_def = wpshop_products::get_parent_variation($product->post_id);
13
+				if (!empty($parent_def) && !empty($parent_def['parent_post'])) :
14 14
 					$parent_post = $parent_def['parent_post'];
15 15
 					$product_name = $parent_post->post_title;
16 16
 				endif;
17 17
 			endif;
18 18
 	?>
19 19
 	<div class="wps-table wps-table-row">
20
-		<div class="wps-table-cell textleft" ><a href="<?php echo admin_url('post.php?post=' .$product->post_id. '&action=edit'); ?>"><?php echo $product_name; ?></a></div>
21
-		<div class="wps-table-cell" ><?php printf( __('%s views', 'wpshop'), $product->meta_value); ?></div>
20
+		<div class="wps-table-cell textleft" ><a href="<?php echo admin_url('post.php?post=' . $product->post_id . '&action=edit'); ?>"><?php echo $product_name; ?></a></div>
21
+		<div class="wps-table-cell" ><?php printf(__('%s views', 'wpshop'), $product->meta_value); ?></div>
22 22
 	</div>
23 23
 	<?php endforeach; ?>
24 24
 </div>
25 25
 <?php else : ?>
26
-<div class="wps-alert-info"><?php _e( 'No product have been seen', 'wpshop'); ?></div>
26
+<div class="wps-alert-info"><?php _e('No product have been seen', 'wpshop'); ?></div>
27 27
 <?php endif; ?>
Please login to merge, or discard this patch.
Braces   +11 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 	$products = $this->wps_stats_mdl->wps_most_viewed_products_datas( $main_stats_count );
3 5
 	if ( !empty( $products ) ) :
4 6
 ?>
@@ -8,8 +10,10 @@  discard block
 block discarded – undo
8 10
 			$product_type = get_post_type( $product->post_id );
9 11
 			if ( $product_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) :
10 12
 				$product_name = get_the_title( $product->post_id );
11
-			else :
13
+			else {
14
+				:
12 15
 				$parent_def = wpshop_products::get_parent_variation( $product->post_id );
16
+			}
13 17
 				if ( !empty($parent_def) && !empty($parent_def['parent_post']) ) :
14 18
 					$parent_post = $parent_def['parent_post'];
15 19
 					$product_name = $parent_post->post_title;
@@ -22,6 +26,9 @@  discard block
 block discarded – undo
22 26
 	</div>
23 27
 	<?php endforeach; ?>
24 28
 </div>
25
-<?php else : ?>
26
-<div class="wps-alert-info"><?php _e( 'No product have been seen', 'wpshop'); ?></div>
29
+<?php else {
30
+	: ?>
31
+<div class="wps-alert-info"><?php _e( 'No product have been seen', 'wpshop');
32
+}
33
+?></div>
27 34
 <?php endif; ?>
Please login to merge, or discard this patch.
modules/wps_statistics/templates/backend/wps_statistics_last_orders.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -2,28 +2,28 @@
 block discarded – undo
2 2
 /**
3 3
  * Display the last order list
4 4
  */
5
-if ( ! defined( 'ABSPATH' ) ) {
5
+if (!defined('ABSPATH')) {
6 6
 	exit;
7 7
 }
8 8
 
9
-$payment_status = unserialize( WPSHOP_ORDER_STATUS );
10
-$last_orders = array_slice( $shop_orders, 0, $main_stats_count );
11
-if ( !empty( $last_orders ) ) :
9
+$payment_status = unserialize(WPSHOP_ORDER_STATUS);
10
+$last_orders = array_slice($shop_orders, 0, $main_stats_count);
11
+if (!empty($last_orders)) :
12 12
 ?>
13 13
 <div class="wps-table">
14
-<?php foreach( $last_orders as $order ) : ?>
14
+<?php foreach ($last_orders as $order) : ?>
15 15
 	<?php
16
-		$order_key = ( !empty($order['order_postmeta']['order_key']) ) ? $order['order_postmeta']['order_key'] : ( ( !empty($order['order_postmeta']['order_temporary_key']) ) ? $order['order_postmeta']['order_temporary_key'] : '' );
16
+		$order_key = (!empty($order['order_postmeta']['order_key'])) ? $order['order_postmeta']['order_key'] : ((!empty($order['order_postmeta']['order_temporary_key'])) ? $order['order_postmeta']['order_temporary_key'] : '');
17 17
 	?>
18 18
 	<div class="wps-table-row">
19
-		<div class="wps-table-cell"><?php echo ( !empty($order['order_postmeta']['order_date']) ) ? mysql2date('d F Y', $order['order_postmeta']['order_date'], true) : ''; ?></div>
20
-		<div class="wps-table-cell"><a href="<?php echo admin_url( 'post.php?post=' .$order['post']->ID. '&action=edit' ); ?>" ><?php echo esc_html( $order_key ); ?></a></div>
21
-		<div class="wps-table-cell"><?php echo ( !empty($order['order_info']) && !empty($order['order_info']['billing']) && !empty($order['order_info']['billing']['address']) && !empty($order['order_info']['billing']['address']['address_last_name']) && !empty($order['order_info']['billing']['address']['address_first_name']) ) ? $order['order_info']['billing']['address']['address_first_name'].' '.$order['order_info']['billing']['address']['address_last_name'] : ''; ?></div>
22
-		<div class="wps-table-cell"><?php echo ( !empty($order['order_postmeta']['order_grand_total']) ) ? number_format( $order['order_postmeta']['order_grand_total'], 2, '.', '' ).' '.wpshop_tools::wpshop_get_currency( false ) : ''; ?></div>
23
-		<div class="wps-table-cell wps_dashboard_<?php echo $order['order_postmeta']['order_status']; ?>"><?php _e($payment_status[ $order['order_postmeta']['order_status'] ], 'wpshop' ) ?></div>
19
+		<div class="wps-table-cell"><?php echo (!empty($order['order_postmeta']['order_date'])) ? mysql2date('d F Y', $order['order_postmeta']['order_date'], true) : ''; ?></div>
20
+		<div class="wps-table-cell"><a href="<?php echo admin_url('post.php?post=' . $order['post']->ID . '&action=edit'); ?>" ><?php echo esc_html($order_key); ?></a></div>
21
+		<div class="wps-table-cell"><?php echo (!empty($order['order_info']) && !empty($order['order_info']['billing']) && !empty($order['order_info']['billing']['address']) && !empty($order['order_info']['billing']['address']['address_last_name']) && !empty($order['order_info']['billing']['address']['address_first_name'])) ? $order['order_info']['billing']['address']['address_first_name'] . ' ' . $order['order_info']['billing']['address']['address_last_name'] : ''; ?></div>
22
+		<div class="wps-table-cell"><?php echo (!empty($order['order_postmeta']['order_grand_total'])) ? number_format($order['order_postmeta']['order_grand_total'], 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency(false) : ''; ?></div>
23
+		<div class="wps-table-cell wps_dashboard_<?php echo $order['order_postmeta']['order_status']; ?>"><?php _e($payment_status[$order['order_postmeta']['order_status']], 'wpshop') ?></div>
24 24
 	</div>
25 25
 <?php endforeach; ?>
26 26
 </div>
27 27
 <?php else : ?>
28
-<div class="wps-alert-info"><?php _e( 'No orders have been placed for the moment', 'wpshop'); ?></div>
28
+<div class="wps-alert-info"><?php _e('No orders have been placed for the moment', 'wpshop'); ?></div>
29 29
 <?php endif; ?>
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,6 +24,9 @@
 block discarded – undo
24 24
 	</div>
25 25
 <?php endforeach; ?>
26 26
 </div>
27
-<?php else : ?>
28
-<div class="wps-alert-info"><?php _e( 'No orders have been placed for the moment', 'wpshop'); ?></div>
27
+<?php else {
28
+	: ?>
29
+<div class="wps-alert-info"><?php _e( 'No orders have been placed for the moment', 'wpshop');
30
+}
31
+?></div>
29 32
 <?php endif; ?>
Please login to merge, or discard this patch.
includes/modules/wps_statistics/templates/backend/wps_statistics_custom.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -2,27 +2,27 @@  discard block
 block discarded – undo
2 2
 /**
3 3
  * Display statistics for custom date
4 4
  */
5
-if ( ! defined( 'ABSPATH' ) ) {
5
+if (!defined('ABSPATH')) {
6 6
 	exit;
7 7
 }
8 8
 
9 9
 ?>
10 10
 <div class="wps-table" style="margin: 0px;" >
11 11
 	<div class="wps-table-row">
12
-		<div class="wps-table-cell"><a class="wps-statistics-quick-links" href="#" data-from="<?php echo $last_month_start; ?>" data-to="<?php echo $last_month_end; ?>" ><?php esc_html_e( 'Last month', 'wpshop' ); ?></a></div>
13
-		<div class="wps-table-cell"><a class="wps-statistics-quick-links" href="#" data-from="<?php echo $current_month_start; ?>" data-to="<?php echo $current_month_end; ?>" ><?php esc_html_e( 'Current month', 'wpshop' ); ?></a></div>
14
-		<div class="wps-table-cell"><a class="wps-statistics-quick-links" href="#" data-from="<?php echo current_time( 'Y-m-d' ); ?>" data-to="<?php echo current_time( 'Y-m-d' ); ?>" ><?php esc_html_e( 'Today', 'wpshop' ); ?></a></div>
12
+		<div class="wps-table-cell"><a class="wps-statistics-quick-links" href="#" data-from="<?php echo $last_month_start; ?>" data-to="<?php echo $last_month_end; ?>" ><?php esc_html_e('Last month', 'wpshop'); ?></a></div>
13
+		<div class="wps-table-cell"><a class="wps-statistics-quick-links" href="#" data-from="<?php echo $current_month_start; ?>" data-to="<?php echo $current_month_end; ?>" ><?php esc_html_e('Current month', 'wpshop'); ?></a></div>
14
+		<div class="wps-table-cell"><a class="wps-statistics-quick-links" href="#" data-from="<?php echo current_time('Y-m-d'); ?>" data-to="<?php echo current_time('Y-m-d'); ?>" ><?php esc_html_e('Today', 'wpshop'); ?></a></div>
15 15
 	</div>
16 16
 </div>
17 17
 <center>
18
-	<form action="<?php echo admin_url( 'admin-ajax.php' ); ?>" id="wps_statistics_date_customizer" method="post" >
18
+	<form action="<?php echo admin_url('admin-ajax.php'); ?>" id="wps_statistics_date_customizer" method="post" >
19 19
 		<input type="hidden" name="action" value="wps_statistics_custom_date_view" />
20
-		<?php wp_nonce_field( 'wps_statistics_custom_date_view' ); ?>
21
-		<?php esc_html_e( 'Begin date', 'wpshop' ); ?>
22
-		<input type="text" name="wps_statistics_start_date" class="wps_statistics_date" value="<?php echo esc_attr( $date_start ); ?>" />
23
-		<?php esc_html_e( 'End date', 'wpshop' ); ?>
24
-		<input type="text" name="wps_statistics_end_date" class="wps_statistics_date" value="<?php echo esc_attr( $date_end ); ?>" />
25
-		<button class="button button-primary" ><?php esc_html_e( 'View', 'wpshop' ); ?></button>
20
+		<?php wp_nonce_field('wps_statistics_custom_date_view'); ?>
21
+		<?php esc_html_e('Begin date', 'wpshop'); ?>
22
+		<input type="text" name="wps_statistics_start_date" class="wps_statistics_date" value="<?php echo esc_attr($date_start); ?>" />
23
+		<?php esc_html_e('End date', 'wpshop'); ?>
24
+		<input type="text" name="wps_statistics_end_date" class="wps_statistics_date" value="<?php echo esc_attr($date_end); ?>" />
25
+		<button class="button button-primary" ><?php esc_html_e('View', 'wpshop'); ?></button>
26 26
 	</form>
27 27
 </center>
28 28
 
@@ -30,25 +30,25 @@  discard block
 block discarded – undo
30 30
 
31 31
 <div class="wps-table">
32 32
 	<div class="wps-table-header wps-table-row">
33
-		<div class="wps-table-cell"><?php esc_html_e( 'Order count', 'wpshop' ); ?></div>
34
-		<div class="wps-table-cell"><?php esc_html_e( 'Order total amount', 'wpshop' ); ?></div>
35
-		<div class="wps-table-cell"><?php esc_html_e( 'Shipping amount', 'wpshop' ); ?></div>
36
-		<div class="wps-table-cell"><?php esc_html_e( 'Customer subscription', 'wpshop' ); ?></div>
33
+		<div class="wps-table-cell"><?php esc_html_e('Order count', 'wpshop'); ?></div>
34
+		<div class="wps-table-cell"><?php esc_html_e('Order total amount', 'wpshop'); ?></div>
35
+		<div class="wps-table-cell"><?php esc_html_e('Shipping amount', 'wpshop'); ?></div>
36
+		<div class="wps-table-cell"><?php esc_html_e('Customer subscription', 'wpshop'); ?></div>
37 37
 	</div>
38 38
 	<div class="wps-table-row">
39
-		<?php if ( null !== $order_list ) : ?>
40
-		<div class="wps-table-cell"><?php echo esc_html( count( $order_list ) ); ?></div>
41
-		<div class="wps-table-cell"><?php echo esc_html( number_format( $orders_total_amount, 2, '.', '' ) . ' ' . wpshop_tools::wpshop_get_currency( false ) ); ?></div>
42
-		<div class="wps-table-cell"><?php echo esc_html( number_format( $orders_total_shipping_cost, 2, '.', '' ) . ' ' . wpshop_tools::wpshop_get_currency( false ) ); ?></div>
39
+		<?php if (null !== $order_list) : ?>
40
+		<div class="wps-table-cell"><?php echo esc_html(count($order_list)); ?></div>
41
+		<div class="wps-table-cell"><?php echo esc_html(number_format($orders_total_amount, 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency(false)); ?></div>
42
+		<div class="wps-table-cell"><?php echo esc_html(number_format($orders_total_shipping_cost, 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency(false)); ?></div>
43 43
 		<?php else : ?>
44
-		<div class="wps-table-cell"><?php esc_html_e( 'No orders have been placed for the moment', 'wpshop' ); ?></div>
44
+		<div class="wps-table-cell"><?php esc_html_e('No orders have been placed for the moment', 'wpshop'); ?></div>
45 45
 		<div class="wps-table-cell">&nbsp;</div>
46 46
 		<?php endif; ?>
47
-		<div class="wps-table-cell"><?php echo esc_html( $user_subscription_number->get_total() ); ?></div>
47
+		<div class="wps-table-cell"><?php echo esc_html($user_subscription_number->get_total()); ?></div>
48 48
 	</div>
49 49
 </div>
50 50
 <script type="text/javascript">/* <![CDATA[ */
51
-	var wpsStats = <?php echo json_encode( $stats_translations ); ?>;
51
+	var wpsStats = <?php echo json_encode($stats_translations); ?>;
52 52
 
53 53
 	var numberOfSales = [<?php echo $orders_number_for_stats; ?>];
54 54
 	for (var i = 0; i < numberOfSales.length; ++i) numberOfSales[i][0] += 60 * 60 * 1000;
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,11 @@
 block discarded – undo
40 40
 		<div class="wps-table-cell"><?php echo esc_html( count( $order_list ) ); ?></div>
41 41
 		<div class="wps-table-cell"><?php echo esc_html( number_format( $orders_total_amount, 2, '.', '' ) . ' ' . wpshop_tools::wpshop_get_currency( false ) ); ?></div>
42 42
 		<div class="wps-table-cell"><?php echo esc_html( number_format( $orders_total_shipping_cost, 2, '.', '' ) . ' ' . wpshop_tools::wpshop_get_currency( false ) ); ?></div>
43
-		<?php else : ?>
44
-		<div class="wps-table-cell"><?php esc_html_e( 'No orders have been placed for the moment', 'wpshop' ); ?></div>
43
+		<?php else {
44
+	: ?>
45
+		<div class="wps-table-cell"><?php esc_html_e( 'No orders have been placed for the moment', 'wpshop' );
46
+}
47
+?></div>
45 48
 		<div class="wps-table-cell">&nbsp;</div>
46 49
 		<?php endif; ?>
47 50
 		<div class="wps-table-cell"><?php echo esc_html( $user_subscription_number->get_total() ); ?></div>
Please login to merge, or discard this patch.
includes/modules/wps_statistics/model/wps_statisticsmdl.php 2 patches
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 	/** Get hourly orders ***/
3 3
 	class wps_statistics_mdl {
4 4
 		private $wps_orders_all = null;
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 		 * Return most viewed products statistics
10 10
 		 * @return array
11 11
 		 */
12
-		function wps_most_viewed_products_datas( $product_number = 8 ) {
12
+		function wps_most_viewed_products_datas($product_number = 8) {
13 13
 			global $wpdb;
14 14
 			$output = '';
15 15
 			$query = $wpdb->prepare(
@@ -20,14 +20,14 @@  discard block
 block discarded – undo
20 20
 					AND meta_key = %s
21 21
 				ORDER BY CAST( meta_value AS SIGNED ) DESC
22 22
 				LIMIT " . $product_number, 'publish', '_wpshop_product_view_nb');
23
-			$products = $wpdb->get_results( $query );
23
+			$products = $wpdb->get_results($query);
24 24
 			return $products;
25 25
 		}
26 26
 
27 27
 		/*
28 28
 		 * Returns all orders and save in variable
29 29
 		 */
30
-		function wps_orders_all( $custom_args = array() ) {
30
+		function wps_orders_all($custom_args = array()) {
31 31
 			$orders_default_args = array(
32 32
 				'posts_per_page'	=> -1,
33 33
 				'orderby'					=> 'post_date',
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
 			);
56 56
 
57 57
 			$orders = null;
58
-			$orders_query = new WP_Query( wp_parse_args( $custom_args, $orders_default_args ) );
59
-			if ( $orders_query->have_posts() ) {
60
-				foreach( $orders_query->posts as $order ) {
61
-					$orders[ $order->ID ]['post'] = $order;
62
-					$orders[ $order->ID ]['order_postmeta'] = get_post_meta( $order->ID, '_order_postmeta', true );
63
-					$orders[ $order->ID ]['order_info'] = get_post_meta( $order->ID, '_order_info', true );
58
+			$orders_query = new WP_Query(wp_parse_args($custom_args, $orders_default_args));
59
+			if ($orders_query->have_posts()) {
60
+				foreach ($orders_query->posts as $order) {
61
+					$orders[$order->ID]['post'] = $order;
62
+					$orders[$order->ID]['order_postmeta'] = get_post_meta($order->ID, '_order_postmeta', true);
63
+					$orders[$order->ID]['order_info'] = get_post_meta($order->ID, '_order_info', true);
64 64
 				}
65 65
 			}
66 66
 
@@ -73,24 +73,24 @@  discard block
 block discarded – undo
73 73
 		 * @param string $enddate
74 74
 		 * @return array
75 75
 		 */
76
-		function wps_best_sales_datas( $begindate, $enddate) {
77
-			$begindate = new DateTime( $begindate.' 00:00:00' );
78
-			$enddate = new DateTime( $enddate.' 23:59:59' );
76
+		function wps_best_sales_datas($begindate, $enddate) {
77
+			$begindate = new DateTime($begindate . ' 00:00:00');
78
+			$enddate = new DateTime($enddate . ' 23:59:59');
79 79
 			$orders = $this->wps_orders_all();
80
-			if ( !empty($orders) ) {
80
+			if (!empty($orders)) {
81 81
 				$products = array();
82
-				foreach( $orders as $order ) {
83
-					$date_order = new DateTime( $order->post_date );
84
-					if( $begindate <= $date_order && $date_order <= $enddate ) {
82
+				foreach ($orders as $order) {
83
+					$date_order = new DateTime($order->post_date);
84
+					if ($begindate <= $date_order && $date_order <= $enddate) {
85 85
 						$order_meta = $order->_order_postmeta;
86
-						if( !empty($order_meta) && !empty($order_meta['order_items']) ) {
87
-							foreach( $order_meta['order_items'] as $item_id => $item ) {
88
-								if( !empty($item) && !empty($item['item_qty']) && !empty($item['item_id'])  ) {
89
-									if( !empty($products[ $item['item_id'] ]) ) {
90
-										$products[ $item['item_id'] ] += $item['item_qty'];
86
+						if (!empty($order_meta) && !empty($order_meta['order_items'])) {
87
+							foreach ($order_meta['order_items'] as $item_id => $item) {
88
+								if (!empty($item) && !empty($item['item_qty']) && !empty($item['item_id'])) {
89
+									if (!empty($products[$item['item_id']])) {
90
+										$products[$item['item_id']] += $item['item_qty'];
91 91
 									}
92 92
 									else {
93
-										$products[ $item['item_id'] ] = $item['item_qty'];
93
+										$products[$item['item_id']] = $item['item_qty'];
94 94
 									}
95 95
 								}
96 96
 							}
@@ -109,20 +109,20 @@  discard block
 block discarded – undo
109 109
 			$output = '';
110 110
 			$order_recap = array();
111 111
 			$orders = $this->wps_orders_all();
112
-			if ( !empty($orders) ) {
113
-				foreach( $orders as $order ) {
114
-					$order_year = date( 'Y', strtotime( $order->post_date) );
115
-					$order_month = date( 'n', strtotime( $order->post_date) );
116
-					if ( empty($order_recap[$order_year]) ) {
112
+			if (!empty($orders)) {
113
+				foreach ($orders as $order) {
114
+					$order_year = date('Y', strtotime($order->post_date));
115
+					$order_month = date('n', strtotime($order->post_date));
116
+					if (empty($order_recap[$order_year])) {
117 117
 						$order_recap[$order_year] = array();
118 118
 					}
119 119
 					$order_meta = $order->_order_postmeta;
120
-					if ( !empty($order_meta) && !empty($order_meta['order_grand_total']) ) {
121
-						if ( empty($order_recap[$order_year][ $order_month ]) ) {
122
-							$order_recap[$order_year][ $order_month ] = $order_meta['order_grand_total'];
120
+					if (!empty($order_meta) && !empty($order_meta['order_grand_total'])) {
121
+						if (empty($order_recap[$order_year][$order_month])) {
122
+							$order_recap[$order_year][$order_month] = $order_meta['order_grand_total'];
123 123
 						}
124 124
 						else {
125
-							$order_recap[$order_year][ $order_month ] += $order_meta['order_grand_total'];
125
+							$order_recap[$order_year][$order_month] += $order_meta['order_grand_total'];
126 126
 						}
127 127
 					}
128 128
 				}
@@ -135,24 +135,24 @@  discard block
 block discarded – undo
135 135
 		 * Orders Status
136 136
 		 * @return Array
137 137
 		 */
138
-		function wps_order_status( $begin_date, $end_date ) {
139
-			$begin_date = new DateTime( $begin_date.' 00:00:00' );
140
-			$end_date = new DateTime( $end_date.' 23:59:59' );
138
+		function wps_order_status($begin_date, $end_date) {
139
+			$begin_date = new DateTime($begin_date . ' 00:00:00');
140
+			$end_date = new DateTime($end_date . ' 23:59:59');
141 141
 			$output = '';
142 142
 			$orders = $this->wps_orders_all();
143
-			if ( !empty($orders) ) {
143
+			if (!empty($orders)) {
144 144
 				$orders_status = array();
145 145
 				/** Collect datas **/
146
-				foreach( $orders as $order ) {
147
-					$date_order = new DateTime( $order->post_date );
148
-					if( $begin_date <= $date_order && $date_order <= $end_date ) {
146
+				foreach ($orders as $order) {
147
+					$date_order = new DateTime($order->post_date);
148
+					if ($begin_date <= $date_order && $date_order <= $end_date) {
149 149
 						$order_meta = $order->_order_postmeta;
150
-						if ( !empty($order_meta) && !empty($order_meta['order_status']) ) {
151
-							if ( !empty($orders_status[ $order_meta['order_status'] ]) ) {
152
-								$orders_status[ $order_meta['order_status'] ]++;
150
+						if (!empty($order_meta) && !empty($order_meta['order_status'])) {
151
+							if (!empty($orders_status[$order_meta['order_status']])) {
152
+								$orders_status[$order_meta['order_status']]++;
153 153
 							}
154 154
 							else {
155
-								$orders_status[ $order_meta['order_status'] ] = 1;
155
+								$orders_status[$order_meta['order_status']] = 1;
156 156
 							}
157 157
 						}
158 158
 					}
@@ -167,32 +167,32 @@  discard block
 block discarded – undo
167 167
 		 * @param string $end_date
168 168
 		 * @return array
169 169
 		 */
170
-		function wps_best_customers( $begin_date, $end_date ) {
170
+		function wps_best_customers($begin_date, $end_date) {
171 171
 				$output = '';
172 172
 				$customer_recap = array();
173 173
 
174
-				$begin_date = new DateTime( $begin_date.' 00:00:00' );
175
-				$end_date = new DateTime( $end_date.' 23:59:59' );
174
+				$begin_date = new DateTime($begin_date . ' 00:00:00');
175
+				$end_date = new DateTime($end_date . ' 23:59:59');
176 176
 				$orders = $this->wps_orders_all();
177 177
 
178
-				if ( !empty($orders) ) {
179
-					foreach( $orders as $order ) {
180
-						$date_order = new DateTime( $order->post_date );
181
-						if( $begin_date <= $date_order && $date_order <= $end_date ) {
178
+				if (!empty($orders)) {
179
+					foreach ($orders as $order) {
180
+						$date_order = new DateTime($order->post_date);
181
+						if ($begin_date <= $date_order && $date_order <= $end_date) {
182 182
 							$order_meta = $order->_order_postmeta;
183
-							if ( !empty($order_meta) && !empty($order_meta['customer_id']) && !empty($order_meta['order_grand_total']) ) {
183
+							if (!empty($order_meta) && !empty($order_meta['customer_id']) && !empty($order_meta['order_grand_total'])) {
184 184
 								/** Check if user is administrator **/
185
-								$user_def = get_user_by( 'id', $order_meta['customer_id'] );
186
-								$wps_statistics_exclude_customer = get_user_meta( $order_meta['customer_id'], 'wps_statistics_exclude_customer', true );
187
-								$excluded_from_statistics = ( !empty($wps_statistics_exclude_customer) ) ? true : false;
185
+								$user_def = get_user_by('id', $order_meta['customer_id']);
186
+								$wps_statistics_exclude_customer = get_user_meta($order_meta['customer_id'], 'wps_statistics_exclude_customer', true);
187
+								$excluded_from_statistics = (!empty($wps_statistics_exclude_customer)) ? true : false;
188 188
 
189 189
 
190
-								if ( !empty($user_def) && !empty($user_def->caps) && is_array($user_def->caps) && array_key_exists( 'customer', $user_def->caps) && $excluded_from_statistics === false ) {
191
-									if ( empty($customer_recap[ $order_meta['customer_id'] ] ) ) {
192
-										$customer_recap[ $order_meta['customer_id'] ] = $order_meta['order_grand_total'];
190
+								if (!empty($user_def) && !empty($user_def->caps) && is_array($user_def->caps) && array_key_exists('customer', $user_def->caps) && $excluded_from_statistics === false) {
191
+									if (empty($customer_recap[$order_meta['customer_id']])) {
192
+										$customer_recap[$order_meta['customer_id']] = $order_meta['order_grand_total'];
193 193
 									}
194 194
 									else {
195
-										$customer_recap[ $order_meta['customer_id'] ] += $order_meta['order_grand_total'];
195
+										$customer_recap[$order_meta['customer_id']] += $order_meta['order_grand_total'];
196 196
 									}
197 197
 								}
198 198
 							}
@@ -205,22 +205,22 @@  discard block
 block discarded – undo
205 205
 
206 206
 
207 207
 
208
-		function wps_get_orders_by_hours( $begindate, $enddate, $choosenday = '', $ajax_origin = false ) {
209
-			$begin_date = new DateTime( $begindate.' 00:00:00' );
210
-			$end_date = new DateTime( $enddate.' 23:59:59' );
208
+		function wps_get_orders_by_hours($begindate, $enddate, $choosenday = '', $ajax_origin = false) {
209
+			$begin_date = new DateTime($begindate . ' 00:00:00');
210
+			$end_date = new DateTime($enddate . ' 23:59:59');
211 211
 			$resultarray = $this->wps_orders_all();
212 212
 
213 213
 			$datadate = array();
214
-			foreach ($resultarray as $array){
215
-				$date = new DateTime( $array->post_date );
216
-				if( $begin_date <= $date && $date <= $end_date ) {
214
+			foreach ($resultarray as $array) {
215
+				$date = new DateTime($array->post_date);
216
+				if ($begin_date <= $date && $date <= $end_date) {
217 217
 					$day = $date->format('l');
218 218
 					$day = strtolower($day);
219 219
 					$choosenday = strtolower($choosenday);
220
-					if( empty($choosenday) || ( !empty($choosenday) && $choosenday ==  $day ) ) {
220
+					if (empty($choosenday) || (!empty($choosenday) && $choosenday == $day)) {
221 221
 						$hour = $date->format('G');
222
-						if ( empty($datadate[$day])){
223
-							if	(empty($datadate[$day][$hour])){
222
+						if (empty($datadate[$day])) {
223
+							if (empty($datadate[$day][$hour])) {
224 224
 								$datadate[$day][$hour] = 1;
225 225
 							}
226 226
 							else {
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 							}
229 229
 						}
230 230
 						else {
231
-							if	(empty($datadate[$day][$hour])){
231
+							if (empty($datadate[$day][$hour])) {
232 232
 								$datadate[$day][$hour] = 1;
233 233
 							}
234 234
 							else {
Please login to merge, or discard this patch.
Braces   +10 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 	/** Get hourly orders ***/
3 5
 	class wps_statistics_mdl {
4 6
 		private $wps_orders_all = null;
@@ -88,8 +90,7 @@  discard block
 block discarded – undo
88 90
 								if( !empty($item) && !empty($item['item_qty']) && !empty($item['item_id'])  ) {
89 91
 									if( !empty($products[ $item['item_id'] ]) ) {
90 92
 										$products[ $item['item_id'] ] += $item['item_qty'];
91
-									}
92
-									else {
93
+									} else {
93 94
 										$products[ $item['item_id'] ] = $item['item_qty'];
94 95
 									}
95 96
 								}
@@ -120,8 +121,7 @@  discard block
 block discarded – undo
120 121
 					if ( !empty($order_meta) && !empty($order_meta['order_grand_total']) ) {
121 122
 						if ( empty($order_recap[$order_year][ $order_month ]) ) {
122 123
 							$order_recap[$order_year][ $order_month ] = $order_meta['order_grand_total'];
123
-						}
124
-						else {
124
+						} else {
125 125
 							$order_recap[$order_year][ $order_month ] += $order_meta['order_grand_total'];
126 126
 						}
127 127
 					}
@@ -150,8 +150,7 @@  discard block
 block discarded – undo
150 150
 						if ( !empty($order_meta) && !empty($order_meta['order_status']) ) {
151 151
 							if ( !empty($orders_status[ $order_meta['order_status'] ]) ) {
152 152
 								$orders_status[ $order_meta['order_status'] ]++;
153
-							}
154
-							else {
153
+							} else {
155 154
 								$orders_status[ $order_meta['order_status'] ] = 1;
156 155
 							}
157 156
 						}
@@ -190,8 +189,7 @@  discard block
 block discarded – undo
190 189
 								if ( !empty($user_def) && !empty($user_def->caps) && is_array($user_def->caps) && array_key_exists( 'customer', $user_def->caps) && $excluded_from_statistics === false ) {
191 190
 									if ( empty($customer_recap[ $order_meta['customer_id'] ] ) ) {
192 191
 										$customer_recap[ $order_meta['customer_id'] ] = $order_meta['order_grand_total'];
193
-									}
194
-									else {
192
+									} else {
195 193
 										$customer_recap[ $order_meta['customer_id'] ] += $order_meta['order_grand_total'];
196 194
 									}
197 195
 								}
@@ -222,16 +220,13 @@  discard block
 block discarded – undo
222 220
 						if ( empty($datadate[$day])){
223 221
 							if	(empty($datadate[$day][$hour])){
224 222
 								$datadate[$day][$hour] = 1;
225
-							}
226
-							else {
223
+							} else {
227 224
 								$datadate[$day][$hour] += 1;
228 225
 							}
229
-						}
230
-						else {
226
+						} else {
231 227
 							if	(empty($datadate[$day][$hour])){
232 228
 								$datadate[$day][$hour] = 1;
233
-							}
234
-							else {
229
+							} else {
235 230
 								$datadate[$day][$hour] += 1;
236 231
 							}
237 232
 						}
Please login to merge, or discard this patch.
includes/modules/wps_statistics/controller/wps_statistics_ctr.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@
 block discarded – undo
19 19
 	}
20 20
 
21 21
 	/**
22
-	* Add Javascript & CSS files
23
-	*/
22
+	 * Add Javascript & CSS files
23
+	 */
24 24
 	function add_scripts( $hook ) {
25 25
 		global $current_screen;
26 26
 		if( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) && $hook != 'wpshop_shop_order_page_wpshop_statistics' )
Please login to merge, or discard this patch.
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 class wps_statistics_ctr {
4 4
 
@@ -6,14 +6,14 @@  discard block
 block discarded – undo
6 6
 
7 7
 	function __construct() {
8 8
 		// WP Main Actions
9
-		add_action( 'admin_menu', array(&$this, 'register_stats_menu'), 250);
10
-		add_action( 'save_post', array( &$this, 'wps_statistics_save_customer_infos') );
11
-		add_action( 'add_meta_boxes', array( &$this, 'add_customer_meta_box'), 1 );
9
+		add_action('admin_menu', array(&$this, 'register_stats_menu'), 250);
10
+		add_action('save_post', array(&$this, 'wps_statistics_save_customer_infos'));
11
+		add_action('add_meta_boxes', array(&$this, 'add_customer_meta_box'), 1);
12 12
 
13 13
 		// Add Javascript Files & CSS File in admin
14
-		add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) );
14
+		add_action('admin_enqueue_scripts', array($this, 'add_scripts'));
15 15
 
16
-		add_action( 'wp_ajax_wps_statistics_custom_date_view', array( $this, 'wps_statistics_custom_date_view' ) );
16
+		add_action('wp_ajax_wps_statistics_custom_date_view', array($this, 'wps_statistics_custom_date_view'));
17 17
 
18 18
 		$this->wps_stats_mdl = new wps_statistics_mdl();
19 19
 	}
@@ -21,18 +21,18 @@  discard block
 block discarded – undo
21 21
 	/**
22 22
 	* Add Javascript & CSS files
23 23
 	*/
24
-	function add_scripts( $hook ) {
24
+	function add_scripts($hook) {
25 25
 		global $current_screen;
26
-		if( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) && $hook != 'wpshop_shop_order_page_wpshop_statistics' )
26
+		if (!in_array($current_screen->post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS), true) && $hook != 'wpshop_shop_order_page_wpshop_statistics')
27 27
 			return;
28 28
 
29
-		wp_enqueue_script( 'wps_statistics_js_chart', WPSHOP_JS_URL . 'Chart.js' );
30
-		wp_enqueue_script( 'jquery' );
31
-		wp_enqueue_script( 'jquery-ui-datepicker' );
32
-		wp_enqueue_script( 'jquery-form' );
29
+		wp_enqueue_script('wps_statistics_js_chart', WPSHOP_JS_URL . 'Chart.js');
30
+		wp_enqueue_script('jquery');
31
+		wp_enqueue_script('jquery-ui-datepicker');
32
+		wp_enqueue_script('jquery-form');
33 33
 
34
-		wp_register_style( 'jquery-ui-wpsstats', '//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css', '', WPSHOP_VERSION );
35
-		wp_enqueue_style( 'jquery-ui-wpsstats' );
34
+		wp_register_style('jquery-ui-wpsstats', '//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css', '', WPSHOP_VERSION);
35
+		wp_enqueue_style('jquery-ui-wpsstats');
36 36
 	}
37 37
 
38 38
 	/**
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 */
41 41
 	function add_customer_meta_box() {
42 42
 		global $post;
43
-		add_meta_box( 'wps_statistics_customer', __( 'Statistics', 'wps_price' ), array( &$this, 'wps_statistics_meta_box_content' ), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'side', 'low' );
43
+		add_meta_box('wps_statistics_customer', __('Statistics', 'wps_price'), array(&$this, 'wps_statistics_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'side', 'low');
44 44
 	}
45 45
 
46 46
 	/**
@@ -49,10 +49,10 @@  discard block
 block discarded – undo
49 49
 	function wps_statistics_meta_box_content() {
50 50
 		global $post;
51 51
 		$user_meta = '';
52
-		if ( !empty($post) && !empty($post->post_author) ) {
53
-			$user_meta = get_user_meta( $post->post_author, 'wps_statistics_exclude_customer', true );
52
+		if (!empty($post) && !empty($post->post_author)) {
53
+			$user_meta = get_user_meta($post->post_author, 'wps_statistics_exclude_customer', true);
54 54
 		}
55
-		$output = '<input type="checkbox" name="wps_statistics_exclude_customer" id="wps_statistics_exclude_customer" ' .( (!empty($user_meta) ) ? 'checked="checked"' : '' ). '/> <label for="wps_statistics_exclude_customer">' .__('Exclude this customer from WPShop Statistics', 'wpshop'). '</label>';
55
+		$output = '<input type="checkbox" name="wps_statistics_exclude_customer" id="wps_statistics_exclude_customer" ' . ((!empty($user_meta)) ? 'checked="checked"' : '') . '/> <label for="wps_statistics_exclude_customer">' . __('Exclude this customer from WPShop Statistics', 'wpshop') . '</label>';
56 56
 		echo $output;
57 57
 	}
58 58
 
@@ -60,15 +60,15 @@  discard block
 block discarded – undo
60 60
 	 * Save action to exclude customer of statistics
61 61
 	 */
62 62
 	function wps_statistics_save_customer_infos() {
63
-		$action = !empty( $_POST['action'] ) ? sanitize_text_field( $_POST['action'] ) : '';
64
-		$post_type = !empty( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : '';
65
-		$post_id = !empty( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0;
66
-		$wps_statistics_exclude_customer = isset( $_POST['wps_statistics_exclude_customer'] ) ? (int) $_POST['wps_statistics_exclude_customer'] : 0;
67
-
68
-		if ( !empty($action) && $action != 'autosave' && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) {
69
-			$customer_def = get_post( $post_id );
70
-			if( isset( $wps_statistics_exclude_customer ) ) {
71
-				update_user_meta( $customer_def->post_author, 'wps_statistics_exclude_customer', $wps_statistics_exclude_customer );
63
+		$action = !empty($_POST['action']) ? sanitize_text_field($_POST['action']) : '';
64
+		$post_type = !empty($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : '';
65
+		$post_id = !empty($_POST['post_ID']) ? (int)$_POST['post_ID'] : 0;
66
+		$wps_statistics_exclude_customer = isset($_POST['wps_statistics_exclude_customer']) ? (int)$_POST['wps_statistics_exclude_customer'] : 0;
67
+
68
+		if (!empty($action) && $action != 'autosave' && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) {
69
+			$customer_def = get_post($post_id);
70
+			if (isset($wps_statistics_exclude_customer)) {
71
+				update_user_meta($customer_def->post_author, 'wps_statistics_exclude_customer', $wps_statistics_exclude_customer);
72 72
 			}
73 73
 		}
74 74
 	}
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	 * Register statistics Menu
78 78
 	 */
79 79
 	function register_stats_menu() {
80
-		add_submenu_page( 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER, __('Statistics', 'wpshop' ), __('Statistics', 'wpshop'), 'wpshop_view_statistics', 'wpshop_statistics', array($this, 'wps_display_statistics'));
80
+		add_submenu_page('edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER, __('Statistics', 'wpshop'), __('Statistics', 'wpshop'), 'wpshop_view_statistics', 'wpshop_statistics', array($this, 'wps_display_statistics'));
81 81
 	}
82 82
 
83 83
 	/**
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		$main_stats_count = 5;
90 90
 
91 91
 		$ordered_customers = array();
92
-		foreach ( $shop_orders as $order ) {
92
+		foreach ($shop_orders as $order) {
93 93
 			$user_id = $order['order_postmeta']['customer_id'];
94 94
 			$customer_id = null;
95 95
 			$args = array(
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
 				'post_status'	 		=> 'all',
101 101
 				'posts_per_page' 	=>	1,
102 102
 			);
103
-			$customer = new WP_Query( $args );
103
+			$customer = new WP_Query($args);
104 104
 
105
-			if ( ! isset( $ordered_customers[ $user_id ]['count'] ) ) {
106
-				$ordered_customers[ $user_id ]['count'] = 0;
107
-				$ordered_customers[ $user_id ]['total_amount'] = 0;
105
+			if (!isset($ordered_customers[$user_id]['count'])) {
106
+				$ordered_customers[$user_id]['count'] = 0;
107
+				$ordered_customers[$user_id]['total_amount'] = 0;
108 108
 			}
109
-			$ordered_customers[ $user_id ]['count']++;
110
-			$ordered_customers[ $user_id ]['id'] = $user_id;
111
-			$ordered_customers[ $user_id ]['post_id'] = $customer->post->ID;
112
-			$ordered_customers[ $user_id ]['name'] = ( !empty($order['order_info']) && !empty($order['order_info']['billing']) && !empty($order['order_info']['billing']['address']) && !empty($order['order_info']['billing']['address']['address_last_name']) && !empty($order['order_info']['billing']['address']['address_first_name']) ) ? $order['order_info']['billing']['address']['address_first_name'].' '.$order['order_info']['billing']['address']['address_last_name'] : '';;
113
-			$ordered_customers[ $user_id ]['total_amount'] += $order['order_postmeta']['order_grand_total'];
109
+			$ordered_customers[$user_id]['count']++;
110
+			$ordered_customers[$user_id]['id'] = $user_id;
111
+			$ordered_customers[$user_id]['post_id'] = $customer->post->ID;
112
+			$ordered_customers[$user_id]['name'] = (!empty($order['order_info']) && !empty($order['order_info']['billing']) && !empty($order['order_info']['billing']['address']) && !empty($order['order_info']['billing']['address']['address_last_name']) && !empty($order['order_info']['billing']['address']['address_first_name'])) ? $order['order_info']['billing']['address']['address_first_name'] . ' ' . $order['order_info']['billing']['address']['address_last_name'] : ''; ;
113
+			$ordered_customers[$user_id]['total_amount'] += $order['order_postmeta']['order_grand_total'];
114 114
 		}
115 115
 
116
-		require( wpshop_tools::get_template_part( WPS_STATISTICS_DIR, WPS_STATISTICS_TEMPLATES_MAIN_DIR, "backend", "wps-statistics") );
116
+		require(wpshop_tools::get_template_part(WPS_STATISTICS_DIR, WPS_STATISTICS_TEMPLATES_MAIN_DIR, "backend", "wps-statistics"));
117 117
 	}
118 118
 
119 119
 	/**
@@ -123,20 +123,20 @@  discard block
 block discarded – undo
123 123
 	 *
124 124
 	 * @return [type]             [description]
125 125
 	 */
126
-	function get_average_time_between_orders( $order_list  ) {
126
+	function get_average_time_between_orders($order_list) {
127 127
 		$time_between_orders = 0;
128 128
 		$last_date = null;
129
-		foreach ( $order_list as $order ) {
130
-			if ( null !== $last_date ) {
131
-				$last_order = new DateTime( $last_date );
132
-				$current_order = new DateTime( $order['order_postmeta']['order_date'] );
129
+		foreach ($order_list as $order) {
130
+			if (null !== $last_date) {
131
+				$last_order = new DateTime($last_date);
132
+				$current_order = new DateTime($order['order_postmeta']['order_date']);
133 133
 				$time_between_orders += $last_order->getTimestamp() - $current_order->getTimestamp();
134 134
 			}
135 135
 
136 136
 			$last_date = $order['order_postmeta']['order_date'];
137 137
 		}
138 138
 
139
-		return round( $time_between_orders / count( $order_list ) );
139
+		return round($time_between_orders / count($order_list));
140 140
 	}
141 141
 
142 142
 	/**
@@ -151,22 +151,22 @@  discard block
 block discarded – undo
151 151
 			'average'		=> null,
152 152
 			'duration'	=> null,
153 153
 		);
154
-		$current_date = new DateTime( 'now' );
154
+		$current_date = new DateTime('now');
155 155
 
156 156
 		$list_orders = $this->wps_stats_mdl->wps_orders_all();
157
-		if ( ! empty( $list_orders ) ) {
157
+		if (!empty($list_orders)) {
158 158
 
159
-			$last_order = array_slice( $list_orders, 0, 1 );
160
-			foreach ( $last_order as $order ) {
161
-				$average_check[ 'last_date' ] = $order['order_postmeta']['order_date'];
159
+			$last_order = array_slice($list_orders, 0, 1);
160
+			foreach ($last_order as $order) {
161
+				$average_check['last_date'] = $order['order_postmeta']['order_date'];
162 162
 			}
163
-			$last_order_dateTime = new DateTime( $average_check[ 'last_date' ] );
163
+			$last_order_dateTime = new DateTime($average_check['last_date']);
164 164
 
165 165
 			$duration_since_last_order = $current_date->getTimestamp() - $last_order_dateTime->getTimestamp();
166 166
 			$average_check['duration'] = $duration_since_last_order;
167
-			$average_check['average'] = $this->get_average_time_between_orders( $list_orders );
167
+			$average_check['average'] = $this->get_average_time_between_orders($list_orders);
168 168
 
169
-			$average_check['status'] = ( $average_check['duration'] > $average_check['average'] ? true : false );
169
+			$average_check['status'] = ($average_check['duration'] > $average_check['average'] ? true : false);
170 170
 		}
171 171
 
172 172
 		return $average_check;
@@ -178,36 +178,36 @@  discard block
 block discarded – undo
178 178
 	function wps_display_main_statistics() {
179 179
 		global $wpdb, $current_month_offset;
180 180
 
181
-		$current_month_offset = (int) current_time( 'm' );
182
-		$current_month_offset = isset( $_GET['month'] ) ? (int) $_GET['month'] : $current_month_offset;
181
+		$current_month_offset = (int)current_time('m');
182
+		$current_month_offset = isset($_GET['month']) ? (int)$_GET['month'] : $current_month_offset;
183 183
 
184
-		$current_month_start = date( 'Y-m-d 00:00:00', strtotime( 'first day of this month', time() ) );
185
-		$current_month_end = date( 'Y-m-d 23:59:59', strtotime( 'last day of this month', time() ) );
184
+		$current_month_start = date('Y-m-d 00:00:00', strtotime('first day of this month', time()));
185
+		$current_month_end = date('Y-m-d 23:59:59', strtotime('last day of this month', time()));
186 186
 
187
-		$last_month_start = date( 'Y-m-d 00:00:00', strtotime( 'first day of last month', time() ) );
188
-		$last_month_end = date( 'Y-m-d 23:59:59', strtotime( 'last day of last month', time() ) );
189
-		$one_month_ago = date( 'Y-m-d 23:59:59', strtotime( '-1 month', time() ) );
187
+		$last_month_start = date('Y-m-d 00:00:00', strtotime('first day of last month', time()));
188
+		$last_month_end = date('Y-m-d 23:59:59', strtotime('last day of last month', time()));
189
+		$one_month_ago = date('Y-m-d 23:59:59', strtotime('-1 month', time()));
190 190
 
191 191
 		$dates = array(
192
-			__( 'Current month', 'wpshop' ) => array(
192
+			__('Current month', 'wpshop') => array(
193 193
 				'after'			=> $current_month_start,
194 194
 				'before'		=> $current_month_end,
195 195
 				'inclusive'	=> true,
196 196
 			),
197
-			sprintf( __( 'One month ago (%s)', 'wpshop' ), mysql2date( get_option( 'date_format' ), $one_month_ago, true ) ) => array(
197
+			sprintf(__('One month ago (%s)', 'wpshop'), mysql2date(get_option('date_format'), $one_month_ago, true)) => array(
198 198
 				'after'			=> $last_month_start,
199 199
 				'before'		=> $one_month_ago,
200 200
 				'inclusive'	=> true,
201 201
 			),
202
-			__( 'Last month', 'wpshop' ) => array(
202
+			__('Last month', 'wpshop') => array(
203 203
 				'after'			=> $last_month_start,
204 204
 				'before'		=> $last_month_end,
205 205
 				'inclusive'	=> true,
206 206
 			),
207
-			__( 'From the beginning', 'wpshop' ) => null,
207
+			__('From the beginning', 'wpshop') => null,
208 208
 		);
209 209
 
210
-		require_once( wpshop_tools::get_template_part( WPS_STATISTICS_DIR, WPS_STATISTICS_TEMPLATES_MAIN_DIR, 'backend', 'wps_statistics_main' ) );
210
+		require_once(wpshop_tools::get_template_part(WPS_STATISTICS_DIR, WPS_STATISTICS_TEMPLATES_MAIN_DIR, 'backend', 'wps_statistics_main'));
211 211
 	}
212 212
 
213 213
 	/**
@@ -216,24 +216,24 @@  discard block
 block discarded – undo
216 216
 	 * @param  string $start      Optionnal. The start date to get stats for.
217 217
 	 * @param  string $end        Optionnal. The end date to get stats for.
218 218
 	 */
219
-	function wps_display_custom_statistics( $start = null, $end = null ) {
220
-		$current_month_start = date( 'Y-m-d', strtotime( 'first day of this month', time() ) );
221
-		$current_month_end = date( 'Y-m-d', strtotime( 'last day of this month', time() ) );
219
+	function wps_display_custom_statistics($start = null, $end = null) {
220
+		$current_month_start = date('Y-m-d', strtotime('first day of this month', time()));
221
+		$current_month_end = date('Y-m-d', strtotime('last day of this month', time()));
222 222
 
223
-		$last_month_start = date( 'Y-m-d', strtotime( 'first day of last month', time() ) );
224
-		$last_month_end = date( 'Y-m-d', strtotime( 'last day of last month', time() ) );
223
+		$last_month_start = date('Y-m-d', strtotime('first day of last month', time()));
224
+		$last_month_end = date('Y-m-d', strtotime('last day of last month', time()));
225 225
 
226
-		$date_start = null !== $start ? $start : date( 'Y-m-d', strtotime( 'first day of this month', time() ) );
227
-		$date_end = null !== $end ? $end : date( 'Y-m-d', strtotime( 'last day of this month', time() ) );
226
+		$date_start = null !== $start ? $start : date('Y-m-d', strtotime('first day of this month', time()));
227
+		$date_end = null !== $end ? $end : date('Y-m-d', strtotime('last day of this month', time()));
228 228
 
229 229
 		$stats_translations = array(
230
-			'numberOfSales' => __('Number of sales','wpshop'),
231
-			'sales' => __('sales','wpshop'),
232
-			'salesAmount' => __('Sales amount','wpshop'),
230
+			'numberOfSales' => __('Number of sales', 'wpshop'),
231
+			'sales' => __('sales', 'wpshop'),
232
+			'salesAmount' => __('Sales amount', 'wpshop'),
233 233
 			'wpshopCurrency' => wpshop_tools::wpshop_get_currency(),
234 234
 		);
235 235
 
236
-		$order_list = $this->wps_stats_mdl->wps_orders_all( array(
236
+		$order_list = $this->wps_stats_mdl->wps_orders_all(array(
237 237
 			'date_query' => array(
238 238
 				array(
239 239
 					'after'			=> $date_start,
@@ -241,49 +241,49 @@  discard block
 block discarded – undo
241 241
 					'inclusive'	=> true,
242 242
 				)
243 243
 			),
244
-		) );
244
+		));
245 245
 
246 246
 		$orders_total_amount = $orders_total_shipping_cost = 0;
247 247
 		$orders_number_stats = $orders_amount_stats = array();
248
-		if ( ! empty( $order_list ) ) {
249
-			foreach ( $order_list as $order ) {
248
+		if (!empty($order_list)) {
249
+			foreach ($order_list as $order) {
250 250
 				$order_data = $order['order_postmeta'];
251 251
 				$orders_total_amount += $order_data['order_grand_total'];
252 252
 
253
-				$time = strtotime( date( 'Ymd', strtotime( $order_data['order_date'] ) ) ) . '000';
254
-				if ( ! isset( $orders_number_stats[ $time ] ) ) {
255
-					$orders_number_stats[ $time ] = 0;
253
+				$time = strtotime(date('Ymd', strtotime($order_data['order_date']))) . '000';
254
+				if (!isset($orders_number_stats[$time])) {
255
+					$orders_number_stats[$time] = 0;
256 256
 				}
257
-				$orders_number_stats[ $time ]++;
257
+				$orders_number_stats[$time]++;
258 258
 
259
-				if ( ! isset( $orders_amount_stats[ $time ] ) ) {
260
-					$orders_amount_stats[ $time ] = 0;
259
+				if (!isset($orders_amount_stats[$time])) {
260
+					$orders_amount_stats[$time] = 0;
261 261
 				}
262
-				$orders_amount_stats[ $time ] += $order_data['order_grand_total'];
262
+				$orders_amount_stats[$time] += $order_data['order_grand_total'];
263 263
 
264 264
 				$orders_total_shipping_cost += $order_data['order_shipping_cost'];
265 265
 			}
266 266
 		}
267 267
 
268 268
 		$orders_number_for_stats = null;
269
-		if ( ! empty( $orders_number_stats ) ) {
270
-			$orders_numbers= array();
271
-			foreach ( $orders_number_stats as $time => $number ) {
269
+		if (!empty($orders_number_stats)) {
270
+			$orders_numbers = array();
271
+			foreach ($orders_number_stats as $time => $number) {
272 272
 				$orders_numbers[] = "[$time, $number]";
273 273
 			}
274
-			$orders_number_for_stats = implode( ',', $orders_numbers );
274
+			$orders_number_for_stats = implode(',', $orders_numbers);
275 275
 		}
276 276
 
277 277
 		$orders_amount_for_stats = null;
278
-		if ( ! empty( $orders_amount_stats ) ) {
278
+		if (!empty($orders_amount_stats)) {
279 279
 			$orders_amounts = array();
280
-			foreach ( $orders_amount_stats as $time => $amount ) {
280
+			foreach ($orders_amount_stats as $time => $amount) {
281 281
 				$orders_amounts[] = "[$time, $amount]";
282 282
 			}
283
-			$orders_amount_for_stats = implode( ',', $orders_amounts );
283
+			$orders_amount_for_stats = implode(',', $orders_amounts);
284 284
 		}
285 285
 
286
-		$user_subscription_number = new WP_User_Query( array(
286
+		$user_subscription_number = new WP_User_Query(array(
287 287
 			'date_query' => array(
288 288
 				array(
289 289
 					'after'			=> $date_start,
@@ -292,25 +292,25 @@  discard block
 block discarded – undo
292 292
 				)
293 293
 			),
294 294
 			'count_total' => true,
295
-		) );
295
+		));
296 296
 
297
-		require( wpshop_tools::get_template_part( WPS_STATISTICS_DIR, WPS_STATISTICS_TEMPLATES_MAIN_DIR, 'backend', 'wps_statistics_custom') );
297
+		require(wpshop_tools::get_template_part(WPS_STATISTICS_DIR, WPS_STATISTICS_TEMPLATES_MAIN_DIR, 'backend', 'wps_statistics_custom'));
298 298
 	}
299 299
 
300 300
 	/**
301 301
 	 * Ajax callback - Display custom statistics for given date
302 302
 	 */
303 303
 	function wps_statistics_custom_date_view() {
304
-		check_ajax_referer( 'wps_statistics_custom_date_view' );
304
+		check_ajax_referer('wps_statistics_custom_date_view');
305 305
 
306
-		$start_date = ! empty( $_POST ) && ! empty( $_POST['wps_statistics_start_date'] ) ? sanitize_text_field( $_POST['wps_statistics_start_date'] ) : date( 'Y-m-d', strtotime( 'first day of this month', time() ) );
307
-		$end_date = ! empty( $_POST ) && ! empty( $_POST['wps_statistics_end_date'] ) ? sanitize_text_field( $_POST['wps_statistics_end_date'] ) : date( 'Y-m-d', strtotime( 'last day of this month', time() ) );
306
+		$start_date = !empty($_POST) && !empty($_POST['wps_statistics_start_date']) ? sanitize_text_field($_POST['wps_statistics_start_date']) : date('Y-m-d', strtotime('first day of this month', time()));
307
+		$end_date = !empty($_POST) && !empty($_POST['wps_statistics_end_date']) ? sanitize_text_field($_POST['wps_statistics_end_date']) : date('Y-m-d', strtotime('last day of this month', time()));
308 308
 
309 309
 		ob_start();
310
-		$this->wps_display_custom_statistics( $start_date, $end_date );
310
+		$this->wps_display_custom_statistics($start_date, $end_date);
311 311
 		$output = ob_get_clean();
312 312
 
313
-		wp_die( $output );
313
+		wp_die($output);
314 314
 	}
315 315
 
316 316
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if ( !defined( 'ABSPATH' ) ) {
2
+	exit;
3
+}
2 4
 
3 5
 class wps_statistics_ctr {
4 6
 
@@ -23,8 +25,9 @@  discard block
 block discarded – undo
23 25
 	*/
24 26
 	function add_scripts( $hook ) {
25 27
 		global $current_screen;
26
-		if( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) && $hook != 'wpshop_shop_order_page_wpshop_statistics' )
27
-			return;
28
+		if( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ), true ) && $hook != 'wpshop_shop_order_page_wpshop_statistics' ) {
29
+					return;
30
+		}
28 31
 
29 32
 		wp_enqueue_script( 'wps_statistics_js_chart', WPSHOP_JS_URL . 'Chart.js' );
30 33
 		wp_enqueue_script( 'jquery' );
Please login to merge, or discard this patch.