}
} else {
// This is the default date range for this agenda view
- $total_current_events = $this->checkHaveAnyEvents();
+ $total_current_events = $this->checkHaveAnyEvents( $memberId );
$total_events_wanted = 5;
if ( $total_events_wanted > $total_current_events ) {
$total_events_wanted = ( $total_current_events > 1 ) ? $total_current_events - 1: 1;
$weeks_to_check = 1;
$event_count = 0;
do {
- $event_count = $this->getEventCountForWeekRange( ++$weeks_to_check );
+ $event_count = $this->getEventCountForWeekRange( ++$weeks_to_check, $memberId );
} 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()
+ public function checkHaveAnyEvents( $member_id = null )
{
$from = date( 'Y-m-d' );
$sql = "SELECT count(id)
SELECT event
FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
WHERE DATE(start_time) >= %s)";
+ if ( $member_id = filter_var( $member_id, FILTER_VALIDATE_INT ) ) {
+ $sql .= " AND ref_dest = " . $member_id;
+ }
return $this->wpdb->get_var( $this->wpdb->prepare( $sql, $from ) );
}
/**
* @access public
* @return mixed
*/
- public function getEventCountForWeekRange( $weeks )
+ public function getEventCountForWeekRange( $weeks, $member_id = null )
{
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)
+ $sql = "SELECT count(id)
FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
- WHERE DATE(start_time) BETWEEN %s AND %s",
- $from,
- $to
- )
- );
+ WHERE DATE(start_time) BETWEEN %s AND %s";
+ 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, $to ) );
}
}