From e790f9d5901957d3177c4c215686b813eedc1042 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 14 May 2018 12:21:55 -0400 Subject: [PATCH] Update events to exclude a category. When setting up the shortcode use a negative number to exclude the event category. --- models/front/events/baseAction.php | 21 ++++++++++- models/front/events/list.php | 60 ++++++++++++++++-------------- 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/models/front/events/baseAction.php b/models/front/events/baseAction.php index 669a5ff..db8ead9 100644 --- a/models/front/events/baseAction.php +++ b/models/front/events/baseAction.php @@ -224,7 +224,7 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents ) )"; } - + // check for city id in event list search if ( $cityId = filter_var( $cityId, FILTER_VALIDATE_INT ) ) { $whereParts[] = " @@ -276,6 +276,25 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents if ( $limit = filter_var( $limit, FILTER_VALIDATE_INT ) ) { $order .= " LIMIT {$limit} OFFSET 0"; } + } else if ( $this->notInCat && !empty( $this->notInCat ) ) { + $whereParts[] = " + T.id IN ( + SELECT event + FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories + WHERE category NOT IN (" . implode( ',', $this->notInCat ) . ") + AND event IN ( + SELECT event + FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET + WHERE status = " . $this->config['status_numb']['Active'] . " + AND " . $this->dateRange . " + ) + ) + "; + $order = "T.id"; + if ( $limit = filter_var( $limit, FILTER_VALIDATE_INT ) ) { + $order .= " LIMIT {$limit} OFFSET 0"; + } + // Else if the $categoryId is an array } else if ( $cats && !empty( $cats ) ) { $whereParts[] = " diff --git a/models/front/events/list.php b/models/front/events/list.php index 78fc17e..0ac3174 100644 --- a/models/front/events/list.php +++ b/models/front/events/list.php @@ -46,32 +46,33 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction */ public function modelAction( $actionData = false ) { - $limit = null; - $status = null; - $action = ''; - $settings = array(); - $events = array(); - $event = array(); - $calDates = false; - $view = null; - $featured = null; - $current = null; - $eventsByDate = null; - $categoryId = null; - $categories = array(); - $amenityId = null; - $amenities = array(); - $memberId = null; - $cityId = null; - $members = array(); - $venues = array(); - $venueId = null; - $eventDays = array(); - $eventDay = null; - $pageSlug = 'event-detail'; - $customPage = false; - $groupByDay = true; - $groupMonth = false; + $limit = null; + $status = null; + $action = ''; + $settings = array(); + $events = array(); + $event = array(); + $calDates = false; + $view = null; + $featured = null; + $current = null; + $eventsByDate = null; + $categoryId = null; + $categories = array(); + $amenityId = null; + $amenities = array(); + $memberId = null; + $cityId = null; + $members = array(); + $venues = array(); + $venueId = null; + $eventDays = array(); + $eventDay = null; + $pageSlug = 'event-detail'; + $customPage = false; + $groupByDay = true; + $groupMonth = false; + $this->notInCat = array(); // get list cities to search by @@ -129,7 +130,10 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction } // Get any numeric categories selected in the submitted shortcode and add to $cats array. // This sets categories that are available for selection by the user - if ( !isset( $_REQUEST['category'] ) && isset( $actionData['request']['category'] ) && $categoryId = filter_var( $actionData['request']['category'], FILTER_SANITIZE_STRING ) ) { + if ( !( isset( $_REQUEST['category'] ) && $_REQUEST['category'] ) + && isset( $actionData['request']['category'] ) + && $categoryId = filter_var( $actionData['request']['category'], FILTER_SANITIZE_STRING ) + ) { $categoryId = array(); // Convert comma separated list to an array @@ -144,6 +148,8 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction // Clean up the category number and add to cats array $categoryId[] = ($v-0); + } else if (preg_match('/^-[0-9]*$/', trim($v))) { + $this->notInCat[] = abs($v); } } -- 2.17.1