Update the date to search for leads data.
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 24 Aug 2016 19:44:57 +0000 (15:44 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 24 Aug 2016 19:44:57 +0000 (15:44 -0400)
Adjusting the start and end range for pulling weekly and monthly data.

models/admin/ajax/statCollector.php

index 9da44bb..3cfb582 100644 (file)
@@ -144,9 +144,11 @@ class GlmMembersAdmin_ajax_statCollector
         $last_stat_date = $this->getLastStatDate( 'weekly' );
         if ( $last_stat_date != self::STAT_START_DATE ) {
             $stat_date = new DateTime( $last_stat_date );
-            $stat_date->modify( '+ 2 week' );
+            $stat_date->modify( '+ 1 week' );
             $last_stat_date = $stat_date->format( 'Y-m-d' );
         }
+        $current_date = new DateTime();
+        $current_date->modify( '+ 2 weeks' );
         $results = $this->wpdb->get_results(
             $this->wpdb->prepare(
                 "SELECT count(id) as leads_count,DATE_FORMAT(date_submitted, '%%Y%%U') as weekly
@@ -154,7 +156,7 @@ class GlmMembersAdmin_ajax_statCollector
                   WHERE date_submitted < %s
                     AND date_submitted > %s
                GROUP BY weekly",
-                current_time( 'Y-m-d' ),
+                $current_date->format( 'Y-m-d' ),
                 $last_stat_date
             ),
             ARRAY_A
@@ -190,9 +192,11 @@ class GlmMembersAdmin_ajax_statCollector
         $last_stat_date = $this->getLastStatDate( 'monthly' );
         if ( $last_stat_date != self::STAT_START_DATE ) {
             $stat_date = new DateTime( $last_stat_date );
-            $stat_date->modify( '+ 2 month' );
+            $stat_date->modify( '+ 1 month' );
             $last_stat_date = $stat_date->format( 'Y-m-d' );
         }
+        $current_date = new DateTime();
+        $current_date->modify( '+ 2 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
@@ -205,7 +209,7 @@ class GlmMembersAdmin_ajax_statCollector
                   WHERE date_submitted < %s
                     AND date_submitted > %s
                GROUP BY monthly",
-                current_time( 'Y-m-d' ),
+                $current_date->format( 'Y-m-d' ),
                 $last_stat_date
             ),
             ARRAY_A