diff --git a/includes/admin/class-wc-admin-dashboard.php b/includes/admin/class-wc-admin-dashboard.php index 48a30a48011..3b1f5301ff2 100644 --- a/includes/admin/class-wc-admin-dashboard.php +++ b/includes/admin/class-wc-admin-dashboard.php @@ -58,8 +58,8 @@ class WC_Admin_Dashboard { AND tax.taxonomy = 'shop_order_status' AND term.slug IN ( 'completed', 'processing', 'on-hold' ) AND postmeta.meta_key = '_order_total' - AND posts.post_date > '" . date( 'Y-m-d', strtotime( 'first day of this month', current_time('timestamp') ) ) . "' - AND posts.post_date < '" . date( 'Y-m-d', current_time('timestamp') ) . "' + AND posts.post_date >= '" . date( 'Y-m-01', current_time('timestamp') ) . "' + AND posts.post_date <= '" . date( 'Y-m-d', current_time('timestamp') ) . "' " ); // Get top seller @@ -77,8 +77,8 @@ class WC_Admin_Dashboard { AND term.slug IN ( 'completed', 'processing', 'on-hold' ) AND order_item_meta.meta_key = '_qty' AND order_item_meta_2.meta_key = '_product_id' - AND posts.post_date > '" . date( 'Y-m-d', strtotime( 'first day of this month', current_time('timestamp') ) ) . "' - AND posts.post_date < '" . date( 'Y-m-d', current_time('timestamp') ) . "' + AND posts.post_date >= '" . date( 'Y-m-01', current_time('timestamp') ) . "' + AND posts.post_date <= '" . date( 'Y-m-d', current_time('timestamp') ) . "' GROUP BY product_id ORDER BY qty DESC LIMIT 1 diff --git a/includes/admin/reports/class-wc-admin-report.php b/includes/admin/reports/class-wc-admin-report.php index 026364e439d..35bdb560386 100644 --- a/includes/admin/reports/class-wc-admin-report.php +++ b/includes/admin/reports/class-wc-admin-report.php @@ -138,7 +138,7 @@ class WC_Admin_Report { if ( $filter_range ) { $query['where'] .= " - AND post_date > '" . date('Y-m-d', $this->start_date ) . "' + AND post_date >= '" . date('Y-m-d', $this->start_date ) . "' AND post_date < '" . date('Y-m-d', strtotime( '+1 DAY', $this->end_date ) ) . "' "; } @@ -396,6 +396,73 @@ class WC_Admin_Report { return ''; } + /** + * Get the current range and calculate the start and end dates + * + * @param string $current_range + */ + public function calculate_current_range( $current_range ) { + switch ( $current_range ) { + case 'custom' : + $this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) ); + $this->end_date = strtotime( 'midnight', strtotime( sanitize_text_field( $_GET['end_date'] ) ) ); + + if ( ! $this->end_date ) + $this->end_date = current_time('timestamp'); + + $interval = 0; + $min_date = $this->start_date; + while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { + $interval ++; + } + + // 3 months max for day view + if ( $interval > 3 ) + $this->chart_groupby = 'month'; + else + $this->chart_groupby = 'day'; + break; + case 'year' : + $this->start_date = strtotime( date( 'Y-01-01', current_time('timestamp') ) ); + $this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) ); + $this->chart_groupby = 'month'; + break; + case 'last_month' : + $this->start_date = strtotime( date( 'Y-m-01', strtotime( '-1 MONTH', current_time('timestamp') ) ) ); + $this->end_date = strtotime( date( 'Y-m-t', strtotime( '-1 MONTH', current_time('timestamp') ) ) ); + $this->chart_groupby = 'day'; + break; + case 'month' : + $this->start_date = strtotime( date( 'Y-m-01', current_time('timestamp') ) ); + $this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) ); + $this->chart_groupby = 'day'; + break; + case '7day' : + $this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) ); + $this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) ); + $this->chart_groupby = 'day'; + break; + } + + // Group by + switch ( $this->chart_groupby ) { + case 'day' : + $this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)'; + $this->chart_interval = ceil( max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ) ); + $this->barwidth = 60 * 60 * 24 * 1000; + break; + case 'month' : + $this->group_by_query = 'YEAR(post_date), MONTH(post_date)'; + $this->chart_interval = 0; + $min_date = $this->start_date; + while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { + $this->chart_interval ++; + } + $this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000; + break; + } + } + /** * Get the main chart * @return string diff --git a/includes/admin/reports/class-wc-report-coupon-usage.php b/includes/admin/reports/class-wc-report-coupon-usage.php index 9c84c78a364..1f3f35627f3 100644 --- a/includes/admin/reports/class-wc-report-coupon-usage.php +++ b/includes/admin/reports/class-wc-report-coupon-usage.php @@ -100,66 +100,10 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report { $current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : '7day'; - switch ( $current_range ) { - case 'custom' : - $this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) ); - $this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) ); + if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) + $current_range = '7day'; - if ( ! $this->end_date ) - $this->end_date = current_time('timestamp'); - - $interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $interval ++; - } - - // 3 months max for day view - if ( $interval > 3 ) - $this->chart_groupby = 'month'; - else - $this->chart_groupby = 'day'; - break; - case 'year' : - $this->start_date = strtotime( 'first day of january', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'month'; - break; - case 'last_month' : - $this->start_date = strtotime( 'first day of last month', current_time('timestamp') ); - $this->end_date = strtotime( 'last day of last month', current_time('timestamp') ); - $this->chart_groupby = 'day'; - break; - case 'month' : - $this->start_date = strtotime( 'first day of this month', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - case '7day' : - default : - $this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - } - - // Group by - switch ( $this->chart_groupby ) { - case 'day' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)'; - $this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ); - $this->barwidth = 60 * 60 * 24 * 1000; - break; - case 'month' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date)'; - $this->chart_interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $this->chart_interval ++; - } - $this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000; - break; - } + $this->calculate_current_range( $current_range ); include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php'); } diff --git a/includes/admin/reports/class-wc-report-customers.php b/includes/admin/reports/class-wc-report-customers.php index 7639b5bb761..4bd4f6b701c 100644 --- a/includes/admin/reports/class-wc-report-customers.php +++ b/includes/admin/reports/class-wc-report-customers.php @@ -149,66 +149,10 @@ class WC_Report_Customers extends WC_Admin_Report { $current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : '7day'; - switch ( $current_range ) { - case 'custom' : - $this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) ); - $this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) ); + if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) + $current_range = '7day'; - if ( ! $this->end_date ) - $this->end_date = current_time('timestamp'); - - $interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $interval ++; - } - - // 3 months max for day view - if ( $interval > 3 ) - $this->chart_groupby = 'month'; - else - $this->chart_groupby = 'day'; - break; - case 'year' : - $this->start_date = strtotime( 'first day of january', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'month'; - break; - case 'last_month' : - $this->start_date = strtotime( 'first day of last month', current_time('timestamp') ); - $this->end_date = strtotime( 'last day of last month', current_time('timestamp') ); - $this->chart_groupby = 'day'; - break; - case 'month' : - $this->start_date = strtotime( 'first day of this month', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - case '7day' : - default : - $this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - } - - // Group by - switch ( $this->chart_groupby ) { - case 'day' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)'; - $this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ); - $this->barwidth = 60 * 60 * 24 * 1000; - break; - case 'month' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date)'; - $this->chart_interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $this->chart_interval ++; - } - $this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000; - break; - } + $this->calculate_current_range( $current_range ); $admin_users = new WP_User_Query( array( diff --git a/includes/admin/reports/class-wc-report-sales-by-category.php b/includes/admin/reports/class-wc-report-sales-by-category.php index efd07761e95..4d412753b91 100644 --- a/includes/admin/reports/class-wc-report-sales-by-category.php +++ b/includes/admin/reports/class-wc-report-sales-by-category.php @@ -72,66 +72,10 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report { $current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : '7day'; - switch ( $current_range ) { - case 'custom' : - $this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) ); - $this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) ); + if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) + $current_range = '7day'; - if ( ! $this->end_date ) - $this->end_date = current_time('timestamp'); - - $interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $interval ++; - } - - // 1 months max for day view - if ( $interval > 1 ) - $this->chart_groupby = 'month'; - else - $this->chart_groupby = 'day'; - break; - case 'year' : - $this->start_date = strtotime( 'first day of january', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'month'; - break; - case 'last_month' : - $this->start_date = strtotime( 'first day of last month', current_time('timestamp') ); - $this->end_date = strtotime( 'last day of last month', current_time('timestamp') ); - $this->chart_groupby = 'day'; - break; - case 'month' : - $this->start_date = strtotime( 'first day of this month', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - case '7day' : - default : - $this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - } - - // Group by - switch ( $this->chart_groupby ) { - case 'day' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)'; - $this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ); - $this->barwidth = 60 * 60 * 24 * 1000; - break; - case 'month' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date)'; - $this->chart_interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $this->chart_interval ++; - } - $this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000; - break; - } + $this->calculate_current_range( $current_range ); // Get item sales data if ( $this->show_categories ) { diff --git a/includes/admin/reports/class-wc-report-sales-by-date.php b/includes/admin/reports/class-wc-report-sales-by-date.php index 01ca9c73224..c1b8bfacbbc 100644 --- a/includes/admin/reports/class-wc-report-sales-by-date.php +++ b/includes/admin/reports/class-wc-report-sales-by-date.php @@ -136,66 +136,10 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report { $current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : '7day'; - switch ( $current_range ) { - case 'custom' : - $this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) ); - $this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) ); + if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) + $current_range = '7day'; - if ( ! $this->end_date ) - $this->end_date = current_time('timestamp'); - - $interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $interval ++; - } - - // 3 months max for day view - if ( $interval > 3 ) - $this->chart_groupby = 'month'; - else - $this->chart_groupby = 'day'; - break; - case 'year' : - $this->start_date = strtotime( 'first day of january', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'month'; - break; - case 'last_month' : - $this->start_date = strtotime( 'first day of last month', current_time('timestamp') ); - $this->end_date = strtotime( 'last day of last month', current_time('timestamp') ); - $this->chart_groupby = 'day'; - break; - case 'month' : - $this->start_date = strtotime( 'first day of this month', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - case '7day' : - default : - $this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - } - - // Group by - switch ( $this->chart_groupby ) { - case 'day' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)'; - $this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ); - $this->barwidth = 60 * 60 * 24 * 1000; - break; - case 'month' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date)'; - $this->chart_interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $this->chart_interval ++; - } - $this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000; - break; - } + $this->calculate_current_range( $current_range ); include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php'); } diff --git a/includes/admin/reports/class-wc-report-sales-by-product.php b/includes/admin/reports/class-wc-report-sales-by-product.php index 6a169007385..b27d229b0da 100644 --- a/includes/admin/reports/class-wc-report-sales-by-product.php +++ b/includes/admin/reports/class-wc-report-sales-by-product.php @@ -117,66 +117,10 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report { $current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : '7day'; - switch ( $current_range ) { - case 'custom' : - $this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) ); - $this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) ); + if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) + $current_range = '7day'; - if ( ! $this->end_date ) - $this->end_date = current_time('timestamp'); - - $interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $interval ++; - } - - // 3 months max for day view - if ( $interval > 3 ) - $this->chart_groupby = 'month'; - else - $this->chart_groupby = 'day'; - break; - case 'year' : - $this->start_date = strtotime( 'first day of january', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'month'; - break; - case 'last_month' : - $this->start_date = strtotime( 'first day of last month', current_time('timestamp') ); - $this->end_date = strtotime( 'last day of last month', current_time('timestamp') ); - $this->chart_groupby = 'day'; - break; - case 'month' : - $this->start_date = strtotime( 'first day of this month', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - case '7day' : - default : - $this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - } - - // Group by - switch ( $this->chart_groupby ) { - case 'day' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)'; - $this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ); - $this->barwidth = 60 * 60 * 24 * 1000; - break; - case 'month' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date)'; - $this->chart_interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $this->chart_interval ++; - } - $this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000; - break; - } + $this->calculate_current_range( $current_range ); include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php'); } diff --git a/includes/admin/reports/class-wc-report-taxes-by-code.php b/includes/admin/reports/class-wc-report-taxes-by-code.php index 06b5eb387ca..fc267a8155c 100644 --- a/includes/admin/reports/class-wc-report-taxes-by-code.php +++ b/includes/admin/reports/class-wc-report-taxes-by-code.php @@ -45,61 +45,10 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report { $current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : 'last_month'; - switch ( $current_range ) { - case 'custom' : - $this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) ); - $this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) ); + if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) + $current_range = 'last_month'; - if ( ! $this->end_date ) - $this->end_date = current_time('timestamp'); - - $interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $interval ++; - } - - // 3 months max for day view - if ( $interval > 3 ) - $this->chart_groupby = 'month'; - else - $this->chart_groupby = 'day'; - break; - case 'year' : - $this->start_date = strtotime( 'first day of january', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'month'; - break; - default : - case 'last_month' : - $this->start_date = strtotime( 'first day of last month', current_time('timestamp') ); - $this->end_date = strtotime( 'last day of last month', current_time('timestamp') ); - $this->chart_groupby = 'day'; - break; - case 'month' : - $this->start_date = strtotime( 'first day of this month', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - } - - // Group by - switch ( $this->chart_groupby ) { - case 'day' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)'; - $this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ); - $this->barwidth = 60 * 60 * 24 * 1000; - break; - case 'month' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date)'; - $this->chart_interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $this->chart_interval ++; - } - $this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000; - break; - } + $this->calculate_current_range( $current_range ); $hide_sidebar = true; diff --git a/includes/admin/reports/class-wc-report-taxes-by-date.php b/includes/admin/reports/class-wc-report-taxes-by-date.php index fa7d4a3cff6..35d4e60913e 100644 --- a/includes/admin/reports/class-wc-report-taxes-by-date.php +++ b/includes/admin/reports/class-wc-report-taxes-by-date.php @@ -45,61 +45,10 @@ class WC_Report_Taxes_By_Date extends WC_Admin_Report { $current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : 'last_month'; - switch ( $current_range ) { - case 'custom' : - $this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) ); - $this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) ); + if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) + $current_range = 'last_month'; - if ( ! $this->end_date ) - $this->end_date = current_time('timestamp'); - - $interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $interval ++; - } - - // 3 months max for day view - if ( $interval > 3 ) - $this->chart_groupby = 'month'; - else - $this->chart_groupby = 'day'; - break; - case 'year' : - $this->start_date = strtotime( 'first day of january', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'month'; - break; - default : - case 'last_month' : - $this->start_date = strtotime( 'first day of last month', current_time('timestamp') ); - $this->end_date = strtotime( 'last day of last month', current_time('timestamp') ); - $this->chart_groupby = 'day'; - break; - case 'month' : - $this->start_date = strtotime( 'first day of this month', current_time('timestamp') ); - $this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) ); - $this->chart_groupby = 'day'; - break; - } - - // Group by - switch ( $this->chart_groupby ) { - case 'day' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)'; - $this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ); - $this->barwidth = 60 * 60 * 24 * 1000; - break; - case 'month' : - $this->group_by_query = 'YEAR(post_date), MONTH(post_date)'; - $this->chart_interval = 0; - $min_date = $this->start_date; - while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) { - $this->chart_interval ++; - } - $this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000; - break; - } + $this->calculate_current_range( $current_range ); $hide_sidebar = true;