From: Steve Sutton Date: Wed, 24 Aug 2016 13:44:42 +0000 (-0400) Subject: WIP weekly stats X-Git-Tag: v1.1.0^2~6^2~6 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=a25073855c622c90ce4d88522bc6196f23266d0e;p=WP-Plugins%2Fglm-member-db-leads.git WIP weekly stats Working out the issue with weekly stats. --- diff --git a/models/admin/ajax/statCollector.php b/models/admin/ajax/statCollector.php index 260ae38..28846f0 100644 --- a/models/admin/ajax/statCollector.php +++ b/models/admin/ajax/statCollector.php @@ -75,12 +75,12 @@ class GlmMembersAdmin_ajax_statCollector } - public function modelAction($actionData = false) + public function modelAction( $actionData = false ) { // generate the stat entries - $this->dailyStats(); + //$this->dailyStats(); $this->weeklyStats(); - $this->monthlyStats(); + //$this->monthlyStats(); echo 'done'; exit; } @@ -146,41 +146,45 @@ class GlmMembersAdmin_ajax_statCollector echo '
$last_stat_date: ' . print_r( $last_stat_date, true ) . '
'; $results = $this->wpdb->get_results( $this->wpdb->prepare( - "SELECT count(id) as leads_count,DATE_FORMAT(date_submitted, '%Y%U') as weekly + "SELECT count(id) as leads_count,DATE_FORMAT(date_submitted, '%%Y%%U') as weekly FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_entry WHERE date_submitted < %s AND date_submitted > %s GROUP BY weekly", - current_time( 'mysql' ), + current_time( 'Y-m-d' ), $last_stat_date ), ARRAY_A ); - echo '
$results: ' . print_r( $results, true ) . '
'; + //echo '
$sql: ' . print_r( $sql, true ) . '
'; + //echo '
$num_rows: ' . print_r( $this->wpdb->num_rows, true ) . '
'; + echo '
$time: ' . print_r( current_time( 'Y-m-d' ), true ) . '
'; if ( $results ) { - echo '
$results: ' . print_r( $results, true ) . '
'; - /* + //echo '
$results: ' . print_r( $results, true ) . '
'; foreach ( $results as $stat ) { - if ( preg_match( '%/d{4}/d{2}%', $stat['weekly'], $matches ) ) { - $date = new DateTime( $matches[1], $matches[2] ); + if ( preg_match( '%(\d{4})(\d{2})%', $stat['weekly'], $matches ) ) { + echo '
$matches: ' . print_r( $matches, true ) . '
'; + $date = date( "Y-m-d", strtotime( $matches[1]."W".$matches[2]."0" ) ); + echo '
$date: ' . print_r( $date, true ) . '
'; } else { return false; } - $this->wpdb->insert( - GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_stats', - array( - 'stat_type' => 'weekly', - 'stat_date' => $date->format( 'P-m-d' ), - 'leads_count' => $stat['leads_count'] - ), - array( - '%s', - '%s', - '%d' - ) - ); + if ( $date ) { + $this->wpdb->insert( + GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_stats', + array( + 'stat_type' => 'weekly', + 'stat_date' => $date, + 'leads_count' => $stat['leads_count'] + ), + array( + '%s', + '%s', + '%d' + ) + ); + } } - */ } }