public function modelAction( $actionData = false )
{
// generate the stat entries
- //$this->dailyStats();
+ $this->dailyStats();
$this->weeklyStats();
- //$this->monthlyStats();
+ $this->monthlyStats();
echo 'done';
exit;
}
ARRAY_A
);
if ( $results ) {
- echo '<pre>$results: ' . print_r( $results, true ) . '</pre>';
foreach ( $results as $stat ) {
$this->wpdb->insert(
GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_stats',
public function weeklyStats()
{
$last_stat_date = $this->getLastStatDate( 'weekly' );
- echo '<pre>$last_stat_date: ' . print_r( $last_stat_date, true ) . '</pre>';
+ if ( $last_stat_date != self::STAT_START_DATE ) {
+ $stat_date = new DateTime( $last_stat_date );
+ $stat_date->modify( '+ 2 week' );
+ $last_stat_date = $stat_date->format( 'Y-m-d' );
+ }
$results = $this->wpdb->get_results(
$this->wpdb->prepare(
"SELECT count(id) as leads_count,DATE_FORMAT(date_submitted, '%%Y%%U') as weekly
),
ARRAY_A
);
- //echo '<pre>$sql: ' . print_r( $sql, true ) . '</pre>';
- //echo '<pre>$num_rows: ' . print_r( $this->wpdb->num_rows, true ) . '</pre>';
- echo '<pre>$time: ' . print_r( current_time( 'Y-m-d' ), true ) . '</pre>';
if ( $results ) {
- //echo '<pre>$results: ' . print_r( $results, true ) . '</pre>';
foreach ( $results as $stat ) {
if ( preg_match( '%(\d{4})(\d{2})%', $stat['weekly'], $matches ) ) {
- echo '<pre>$matches: ' . print_r( $matches, true ) . '</pre>';
$date = date( "Y-m-d", strtotime( $matches[1]."W".$matches[2]."0" ) );
- echo '<pre>$date: ' . print_r( $date, true ) . '</pre>';
} else {
return false;
}
public function monthlyStats()
{
+ $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' );
+ $last_stat_date = $stat_date->format( 'Y-m-d' );
+ }
$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( $sql );
+ $results = $this->wpdb->get_results(
+ $this->wpdb->prepare(
+ "SELECT count(id) as leads_count,DATE_FORMAT(date_submitted, '%%Y%%m') as monthly
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_entry
+ WHERE date_submitted < %s
+ AND date_submitted > %s
+ GROUP BY monthly",
+ current_time( 'Y-m-d' ),
+ $last_stat_date
+ ),
+ ARRAY_A
+ );
if ( $results ) {
- echo '<pre>$results: ' . print_r( $results, true ) . '</pre>';
+ foreach ( $results as $stat ) {
+ if ( preg_match( '%(\d{4})(\d{2})%', $stat['monthly'], $matches ) ) {
+ $date = date( "Y-m-d", strtotime( $matches[1]."-".$matches[2]."-01" ) );
+ } else {
+ return false;
+ }
+ if ( $date ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_stats',
+ array(
+ 'stat_type' => 'monthly',
+ 'stat_date' => $date,
+ 'leads_count' => $stat['leads_count']
+ ),
+ array(
+ '%s',
+ '%s',
+ '%d'
+ )
+ );
+ }
+ }
}
}
}