break;
}
} else {
- $toDate = date('m/d/Y', strtotime( '+ 2 weeks' ));
+ // This is the default date range for this agenda view
+ $total_current_events = $this->checkHaveAnyEvents();
+ echo '<pre>$total_current_events: ' . print_r( $total_current_events, true ) . '</pre>';
+ $weeks_to_check = 2;
+ $event_count = 0;
+ do {
+ $event_count = $this->getEventCountForWeekRange( $weeks_to_check );
+ ++$weeks_to_check;
+ } while ( $event_count <= 5 );
+
+ echo '<pre>$event_count: ' . print_r( $event_count, true ) . '</pre>';
+ echo '<pre>$weeks_to_check: ' . print_r( $weeks_to_check, true ) . '</pre>';
+ $week_string = ( $weeks === 1 ) ? 'weeks': 'week';
+ $toDate = date('m/d/Y', strtotime( '+ ' . $weeks_to_check . ' ' . $week_string ));
+ echo '<pre>$toDate: ' . print_r( $toDate, true ) . '</pre>';
}
}
if ( $fromDate && $toDate && !(isset($_REQUEST['event_name']) && $_REQUEST['event_name'])) {
$text = str_replace("\r", '', $text);
return $text;
}
+ public function checkHaveAnyEvents()
+ {
+ $from = date( 'Y-m-d' );
+ return $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT count(id)
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
+ WHERE DATE(start_time) >= %s ",
+ $from
+ )
+ );
+ }
+ /**
+ * getEventCountForWeekRange
+ *
+ * Returns the count of events from the current date based on given weeks.
+ *
+ * @param mixed $weeks Number of weeks to check.
+ *
+ * @access public
+ * @return mixed
+ */
+ public function getEventCountForWeekRange( $weeks )
+ {
+ if ( !filter_var( $weeks, FILTER_VALIDATE_INT ) ) {
+ return false;
+ }
+ $from = date( 'Y-m-d' );
+ $week_string = ( $weeks === 1 ) ? 'weeks': 'week';
+ $to = date( 'Y-m-d', strtotime( '+ ' . $weeks . ' ' . $week_string) );
+ return $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT count(id)
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
+ WHERE DATE(start_time) BETWEEN %s AND %s",
+ $from,
+ $to
+ )
+ );
+ }
}