From: Steve Sutton Date: Tue, 2 Aug 2016 17:33:40 +0000 (-0400) Subject: Create a check for number of events and keep going out to get at least 5 X-Git-Tag: v1.2.27^2~1^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=63af87319176727d4dd7a663dc781af7deb7cbd6;p=WP-Plugins%2Fglm-member-db-events.git Create a check for number of events and keep going out to get at least 5 Create a dynamic check for number of events to get at least 5 events in list. --- diff --git a/models/front/events/list.php b/models/front/events/list.php index 69a7a05..9cd2392 100644 --- a/models/front/events/list.php +++ b/models/front/events/list.php @@ -135,7 +135,21 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction 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 '
$total_current_events: ' . print_r( $total_current_events, true ) . '
'; + $weeks_to_check = 2; + $event_count = 0; + do { + $event_count = $this->getEventCountForWeekRange( $weeks_to_check ); + ++$weeks_to_check; + } while ( $event_count <= 5 ); + + echo '
$event_count: ' . print_r( $event_count, true ) . '
'; + echo '
$weeks_to_check: ' . print_r( $weeks_to_check, true ) . '
'; + $week_string = ( $weeks === 1 ) ? 'weeks': 'week'; + $toDate = date('m/d/Y', strtotime( '+ ' . $weeks_to_check . ' ' . $week_string )); + echo '
$toDate: ' . print_r( $toDate, true ) . '
'; } } if ( $fromDate && $toDate && !(isset($_REQUEST['event_name']) && $_REQUEST['event_name'])) { @@ -642,4 +656,44 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction $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 + ) + ); + } }