} else {
$toDate = $_REQUEST['glm_event_to'];
}
-// echo '<pre>$fromDate: ' . print_r( $fromDate, true ) . '</pre>';
-// echo '<pre>$toDate: ' . print_r( $toDate, true ) . '</pre>';
+ // If no dates given in requst check for at least one event in current month
+ if ( !isset( $_REQUEST['glm_event_from'] ) && !isset( $_REQUEST['glm_event_to'] ) ) {
+ // check how many events are active
+ $total_current_events = $this->checkHaveAnyEvents( $memberId );
+ // check how many events within date range selected
+ $eventCount = $this->getEventCountForDateRange( $fromDate, $toDate, $memberId );
+ $displayDate = time();
+ $dmonth = date( 'n', $displayDate );
+ $dyear = date( 'Y', $displayDate );
+ $endday = date( 't', $displayDate );
+ // Goto the next month if no events in current month
+ if ( $total_current_events > 0 && $eventCount == 0 ) {
+ do {
+ // Add a month to $displayDate
+ if ( $dmonth == 12 ) {
+ $dyear++;
+ $dmonth = 1;
+ } else {
+ $dmonth++;
+ }
+ $fromDate = date( 'm/d/Y', mktime( 0, 0, 0, $dmonth, 1, $dyear ) );
+ $toDate = date( 'm/d/Y', mktime( 0, 0, 0, $dmonth, $endday, $dyear ) );
+ $eventCount = $this->getEventCountForDateRange( $fromDate, $toDate, $memberId );
+ } while ( $eventCount < 1 );
+ // Setup the $_REQUEST for from and to
+ $_REQUEST['glm_event_from'] = $fromDate;
+ $_REQUEST['glm_event_to'] = $toDate;
+ }
+ }
} else if ( in_array($action, array( 'event-list-name', 'nameSearch', 'featured' ) ) || $this->config['settings']['use_venue_locations'] ) {
$toDate = null;
} else {
}
return $this->wpdb->get_var( $this->wpdb->prepare( $sql, $from, $to ) );
}
+
+ /**
+ * getEventCountForDateRange
+ *
+ * @param mixed $from
+ * @param mixed $end
+ * @param bool $member_id
+ *
+ * @access public
+ * @return void
+ */
+ public function getEventCountForDateRange( $from, $end , $member_id = null )
+ {
+ // regex for date validation
+ $regexp = array( 'options' => array( 'regexp' => '/\d{2}\/\d{2}\/\d{4}/') );
+ // Verify date format for $from
+ if ( !filter_var( $from, FILTER_VALIDATE_REGEXP, $regexp )) {
+ return false;
+ }
+ // Verify date format for $end
+ if ( !filter_var( $end, FILTER_VALIDATE_REGEXP, $regexp )) {
+ return false;
+ }
+ // Convert the date format for from and end to Y--m-d (mysql date format)
+ $from = date( 'Y-m-d', strtotime( $from ) );
+ $end = date( 'Y-m-d', strtotime( $end ) );
+ $sql = "
+ SELECT count(id)
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
+ WHERE DATE(start_time) BETWEEN %s AND %s
+ AND event IN (
+ SELECT id
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
+ WHERE status = 10 )";
+ if ( $member_id = filter_var( $member_id, FILTER_VALIDATE_INT ) ) {
+ $sql .= " AND event in (SELECT id FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
+ WHERE ref_dest = " . $member_id . ")";
+ }
+ return $this->wpdb->get_var( $this->wpdb->prepare( $sql, $from, $end ) );
+ }
}