// 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 );
+ $total_current_events = $this->checkHaveAnyEvents( $memberId, $categoryId );
// check how many events within date range selected
- $eventCount = $this->getEventCountForDateRange( $fromDate, $toDate, $memberId );
+ $eventCount = $this->getEventCountForDateRange( $fromDate, $toDate, $memberId, $categoryId );
$displayDate = time();
$dmonth = date( 'n', $displayDate );
$dyear = date( 'Y', $displayDate );
}
$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 );
+ $eventCount = $this->getEventCountForDateRange( $fromDate, $toDate, $memberId, $categoryId );
} while ( $eventCount < 1 );
// Setup the $_REQUEST for from and to
$_REQUEST['glm_event_from'] = $fromDate;
}
} else {
// This is the default date range for this agenda view.
- $total_current_events = $this->checkHaveAnyEvents( $memberId );
+ $total_current_events = $this->checkHaveAnyEvents( $memberId, $categoryId );
// Set default number of events wanted in default view.
$total_events_wanted = 5;
// Set default number of weeks to view.
$event_count = 0;
do {
- $event_count = $this->getEventCountForWeekRange( ++$weeks_to_check, $memberId );
+ $event_count = $this->getEventCountForWeekRange( ++$weeks_to_check, $memberId, $categoryId );
} while ( $event_count < $total_events_wanted && $total_current_events >= $total_events_wanted );
$week_string = ( $weeks_to_check === 1 ) ? 'weeks': 'week';
$text = str_replace("\r", '', $text);
return $text;
}
- public function checkHaveAnyEvents( $member_id = null )
+ public function checkHaveAnyEvents( $member_id = null, $categoryId = null )
{
$from = date( 'Y-m-d' );
- /*
- $sql = "SELECT count(id)
- FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
- WHERE status = 10
- AND id IN (
- SELECT event
- FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
- WHERE DATE(start_time) >= %s)";
- */
$sql = "
SELECT count(id)
FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
$sql .= " AND event in (SELECT id FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
WHERE ref_dest = " . $member_id . ")";
}
+ $cats = array_filter( filter_var( $categoryId, FILTER_VALIDATE_INT, array( 'flags' => FILTER_FORCE_ARRAY ) ) );
+ $catId = filter_var( $categoryId, FILTER_VALIDATE_INT );
+ if ( $catId ) {
+ $sql .= " AND event in (SELECT event
+ FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories
+ WHERE category = {$catId})";
+ } else if ( $cats && !empty( $cats ) ) {
+ $sql .= " AND event in (SELECT event
+ FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories
+ WHERE category IN (" . implode( ',', $categoryId ) . "))";
+ }
return $this->wpdb->get_var( $this->wpdb->prepare( $sql, $from ) );
}
/**
* @access public
* @return mixed
*/
- public function getEventCountForWeekRange( $weeks, $member_id = null )
+ public function getEventCountForWeekRange( $weeks, $member_id = null, $categoryId = null )
{
if ( !filter_var( $weeks, FILTER_VALIDATE_INT ) ) {
return false;
$sql .= " AND event in (SELECT id FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
WHERE ref_dest = " . $member_id . ")";
}
+ $cats = array_filter( filter_var( $categoryId, FILTER_VALIDATE_INT, array( 'flags' => FILTER_FORCE_ARRAY ) ) );
+ $catId = filter_var( $categoryId, FILTER_VALIDATE_INT );
+ if ( $catId ) {
+ $sql .= " AND event in (SELECT event
+ FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories
+ WHERE category = {$catId})";
+ } else if ( $cats && !empty( $cats ) ) {
+ $sql .= " AND event in (SELECT event
+ FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories
+ WHERE category IN (" . implode( ',', $categoryId ) . "))";
+ }
return $this->wpdb->get_var( $this->wpdb->prepare( $sql, $from, $to ) );
}
* @access public
* @return void
*/
- public function getEventCountForDateRange( $from, $end , $member_id = null )
+ public function getEventCountForDateRange( $from, $end , $member_id = null, $categoryId = null )
{
// regex for date validation
$regexp = array( 'options' => array( 'regexp' => '/\d{2}\/\d{2}\/\d{4}/') );
$sql .= " AND event in (SELECT id FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
WHERE ref_dest = " . $member_id . ")";
}
+ $cats = array_filter( filter_var( $categoryId, FILTER_VALIDATE_INT, array( 'flags' => FILTER_FORCE_ARRAY ) ) );
+ $catId = filter_var( $categoryId, FILTER_VALIDATE_INT );
+ if ( $catId ) {
+ $sql .= " AND event in (SELECT event
+ FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories
+ WHERE category = {$catId})";
+ } else if ( $cats && !empty( $cats ) ) {
+ $sql .= " AND event in (SELECT event
+ FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories
+ WHERE category IN (" . implode( ',', $categoryId ) . "))";
+ }
return $this->wpdb->get_var( $this->wpdb->prepare( $sql, $from, $end ) );
}
}