Updated the weekly and monthly date ranges
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 24 Aug 2016 20:44:45 +0000 (16:44 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 24 Aug 2016 20:44:45 +0000 (16:44 -0400)
Now I'm getting the correct lead counts for weeks daily and monthly
stats.

models/admin/ajax/statCollector.php

index e3a9d19..bf698d4 100644 (file)
@@ -147,8 +147,6 @@ class GlmMembersAdmin_ajax_statCollector
             $stat_date->modify( '+ 1 week' );
             $last_stat_date = $stat_date->format( 'Y-m-d' );
         }
-        $current_date = new DateTime();
-        $current_date->modify( '+ 1 weeks' );
         $results = $this->wpdb->get_results(
             $this->wpdb->prepare(
                 "SELECT count(id) as leads_count,DATE_FORMAT(date_submitted, '%%Y%%U') as weekly
@@ -156,7 +154,7 @@ class GlmMembersAdmin_ajax_statCollector
                   WHERE date_submitted < %s
                     AND date_submitted > %s
                GROUP BY weekly",
-                $current_date->format( 'Y-m-d' ),
+                date( 'Y-m-d', strtotime( 'sunday last week' ) ),
                 $last_stat_date
             ),
             ARRAY_A
@@ -197,11 +195,6 @@ class GlmMembersAdmin_ajax_statCollector
         }
         $current_date = new DateTime();
         $current_date->modify( '+ 1 months' );
-        $sql = "
-          SELECT count(id) as leads_count,DATE_FORMAT(date_submitted, '%Y%m') as monthly
-            FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_entry
-        GROUP BY monthly";
-        //$results = $this->wpdb->get_results( $sql );
         $results = $this->wpdb->get_results(
             $this->wpdb->prepare(
                 "SELECT count(id) as leads_count,DATE_FORMAT(date_submitted, '%%Y%%m') as monthly
@@ -209,7 +202,7 @@ class GlmMembersAdmin_ajax_statCollector
                   WHERE date_submitted < %s
                     AND date_submitted > %s
                GROUP BY monthly",
-                $current_date->format( 'Y-m-d' ),
+                date( 'Y-m-d', mktime( 0, 0, 0, date('m'), 1, date('Y') ) ),
                 $last_stat_date
             ),
             ARRAY_A