From: Steve Sutton Date: Mon, 20 Aug 2018 16:56:58 +0000 (-0400) Subject: Update methods for getting event counts need category from shortcode. X-Git-Tag: v1.6.95^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=c14c165695e73bd4c800ee8c622373b78dfa53e1;p=WP-Plugins%2Fglm-member-db-events.git Update methods for getting event counts need category from shortcode. If category is in shortcode then need to pass it to the methods getting the number of total events and going out to make sure that 5 events show up on the event page, if possible. --- diff --git a/index.php b/index.php index 6a2c018..c4a784d 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ * Plugin Name: GLM Members Database Events * Plugin URI: http://www.gaslightmedia.com/ * Description: Gaslight Media Members Database. - * Version: 1.6.94 + * Version: 1.6.95 * Author: Chuck Scott * Author URI: http://www.gaslightmedia.com/ * License: GPL2 @@ -19,7 +19,7 @@ * @package glmMembersDatabaseEventsAddOn * @author Chuck Scott * @license http://www.gaslightmedia.com Gaslightmedia - * @version 1.6.94 + * @version 1.6.95 */ // Check that we're being called by WordPress. @@ -43,7 +43,7 @@ if (!defined('ABSPATH')) { * so that we're sure the other add-ons see an up to date * version from this plugin. */ -define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.6.94'); +define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.6.95'); define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.1.6'); // This is the minimum version of the GLM Members DB plugin require for this plugin. diff --git a/models/front/events/list.php b/models/front/events/list.php index 4fec55f..0bd6e3d 100644 --- a/models/front/events/list.php +++ b/models/front/events/list.php @@ -222,9 +222,9 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction // 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 ); @@ -241,7 +241,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction } $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; @@ -271,7 +271,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction } } 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. @@ -286,7 +286,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction $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'; @@ -970,18 +970,9 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction $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 @@ -995,6 +986,17 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction $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 ) ); } /** @@ -1007,7 +1009,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction * @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; @@ -1027,6 +1029,17 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction $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 ) ); } @@ -1040,7 +1053,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction * @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}/') ); @@ -1067,6 +1080,17 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction $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 ) ); } }