From fd9956b2b71c70efb574c27cf48be749b789f749 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 11 Apr 2017 13:06:14 -0400 Subject: [PATCH] Updating the shortcode for event to have category attribute. Request will override the attribute for category. So they can still search for all categories. Also updated the calendar view to send the selected category. --- models/admin/ajax/eventsCalMonthAJAX.php | 10 +++++- models/front/events/baseAction.php | 20 ++++++++++- models/front/events/list.php | 42 ++++++++++++++++++++++-- setup/shortcodes.php | 26 +++++++++++++++ views/front/events/agenda.html | 4 ++- views/front/events/searchForm.html | 4 +-- 6 files changed, 98 insertions(+), 8 deletions(-) diff --git a/models/admin/ajax/eventsCalMonthAJAX.php b/models/admin/ajax/eventsCalMonthAJAX.php index eac5483..dd6bd17 100644 --- a/models/admin/ajax/eventsCalMonthAJAX.php +++ b/models/admin/ajax/eventsCalMonthAJAX.php @@ -86,7 +86,6 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes $this->postAddTimes = true; $where = ''; - $where .= "T.active = 1 AND T.event IN ( SELECT ET.id @@ -95,6 +94,15 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes ) AND $this->dateRangeTimes "; + if ( isset( $_REQUEST['category'] ) && $catId = filter_var( $_REQUEST['category'], FILTER_VALIDATE_INT ) ) { + $where .= " + AND T.event IN ( + SELECT event + FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories + WHERE category = {$catId} + ) + "; + } $events = $this->getList( $where ); diff --git a/models/front/events/baseAction.php b/models/front/events/baseAction.php index 0463c3e..3f05263 100644 --- a/models/front/events/baseAction.php +++ b/models/front/events/baseAction.php @@ -257,6 +257,25 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents if ( $limit = filter_var( $limit, FILTER_VALIDATE_INT ) ) { $order .= " LIMIT {$limit} OFFSET 0"; } + // Else if the $categoryId is an array + } else if ( $cats = filter_var( $categoryId, FILTER_VALIDATE_INT, array( 'flags' => FILTER_FORCE_ARRAY ) ) && !empty( $cats ) ) { + $whereParts[] = " + T.id IN ( + SELECT event + FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories + WHERE category IN (" . implode( ',', $categoryId ) . ") + 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 a event name is supplied } else if ( $term = filter_var( $categoryId, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES ) ) { $searchTerm = $this->wpdb->esc_like( stripslashes( $term ) ); @@ -298,7 +317,6 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents if ( isset( $whereParts ) && !empty( $whereParts ) ) { $where = implode( ' AND ', $whereParts); } - $events = $this->getList( $where, $order ); if ( !empty( $events ) ) { diff --git a/models/front/events/list.php b/models/front/events/list.php index afb6edb..2c89397 100644 --- a/models/front/events/list.php +++ b/models/front/events/list.php @@ -94,9 +94,36 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction $search = true; $action = 'event-detail'; } - if ( isset( $_REQUEST['category'] ) && $categoryId = filter_var( $_REQUEST['category'], FILTER_VALIDATE_INT ) ) { - $search = true; - $action = 'event-list'; + if ( isset( $_REQUEST['category'] ) ) { + $categoryId = filter_var( $_REQUEST['category'], FILTER_VALIDATE_INT ); + if ( $categoryId ) { + $search = true; + $action = 'event-list'; + } else { + $categoryId = null; + } + } + // 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 ) ) { + $categoryId = array(); + + // Convert comma separated list to an array + $catsRequested = explode(',', $actionData['request']['category']); + + // Check for numeric IDs only + while (list($k, $v) = each($catsRequested)) { + + // If it's just numeric - note Explode returns an array element with value = 0 if no string. + if (preg_match('/^[0-9]*$/', trim($v)) && $v > 0) { + + // Clean up the category number and add to cats array + $categoryId[] = ($v-0); + + } + + } + } if ( isset( $_REQUEST['amenity'] ) && $amenityId = filter_var( $_REQUEST['amenity'], FILTER_VALIDATE_INT ) ) { $search = true; @@ -232,6 +259,15 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction } $categories = $this->getCategories(); + if ( isset( $categories ) ) { + foreach( $categories as &$category ) { + if ( $categoryId && is_array( $categoryId ) && in_array( $category['id'], $categoryId ) ) { + $category['default'] = 1; + } else if ( $categoryId && $categoryId == $category['id'] ) { + $category['default'] = 1; + } + } + } if ( $this->config['settings']['use_event_amenities'] ) { $amenities = $this->getAmenities(); } diff --git a/setup/shortcodes.php b/setup/shortcodes.php index d209d5e..beaf407 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -106,6 +106,7 @@ $glmMembersEventsShortcodes = array( 'limit' => null, 'featured' => null, 'current' => null, + 'category' => null, ) ), 'glm-members-event-detail' => array( @@ -141,6 +142,20 @@ $glmMembersEventsShortcodesDescription = ' Displays a list of events. + +   + + category="{ category ID(s) }" + + + The "category" attribute is used to set the default display of events + to only those events in a specific category or categories by specifying + the category IDs. To select multiple categories, separate the categories with a ",". + Categories are specified by ID number. The ID for each category is + shown in the Events Categories list. The selection of which events + to display may be overridden by the "category-search" parameter. + +   @@ -185,6 +200,16 @@ $glmMembersEventsShortcodesDescription = ' Displays a detail events. + +   + + template="{ template }" + + + The "template" attribute is used to set the template that will be + used for smarty. Defaults to false. + + [glm-members-event-front-add] member_only="{ True/False }" @@ -192,5 +217,6 @@ $glmMembersEventsShortcodesDescription = ' Adds an event submission form to the page. The member_only attribute will allow the add event form in the member only section. + '; diff --git a/views/front/events/agenda.html b/views/front/events/agenda.html index b2a5d86..b6243cc 100644 --- a/views/front/events/agenda.html +++ b/views/front/events/agenda.html @@ -119,6 +119,7 @@ var event_search = $(".glm-search-icon"); var main_content = $("#main-content"); var view = '{$cal_view}'; + var category = $('#glm-event-category').val(); // console.log(sessionStorage.view + " : " + sessionStorage.override); event_search.on('click', function(){ @@ -138,7 +139,8 @@ action: 'glm_members_admin_ajax', glm_action: 'eventsCalMonthAJAX', - month: month + month: month, + category: category }; $('.fc-event').remove(); diff --git a/views/front/events/searchForm.html b/views/front/events/searchForm.html index 07b0492..117da84 100644 --- a/views/front/events/searchForm.html +++ b/views/front/events/searchForm.html @@ -49,9 +49,9 @@
-- 2.17.1