Updating the shortcode for event to have category attribute.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 11 Apr 2017 17:06:14 +0000 (13:06 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 11 Apr 2017 17:06:14 +0000 (13:06 -0400)
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
models/front/events/baseAction.php
models/front/events/list.php
setup/shortcodes.php
views/front/events/agenda.html
views/front/events/searchForm.html

index eac5483..dd6bd17 100644 (file)
@@ -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 );
 
index 0463c3e..3f05263 100644 (file)
@@ -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 ) ) {
index afb6edb..2c89397 100644 (file)
@@ -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();
         }
index d209d5e..beaf407 100644 (file)
@@ -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.
         </td>
     </tr>
+    <tr>
+        <td>&nbsp;</td>
+        <th>
+            category="{ category ID(s) }"
+        </th>
+        <td>
+            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.
+        </td>
+    </tr>
     <tr>
         <td>&nbsp;</td>
         <th>
@@ -185,6 +200,16 @@ $glmMembersEventsShortcodesDescription = '
             Displays a detail events.
         </td>
     </tr>
+    <tr>
+        <td>&nbsp;</td>
+        <th>
+            template="{ template }"
+        </th>
+        <td>
+        The "template" attribute is used to set the template that will be
+        used for smarty. Defaults to false.
+        </td>
+    </tr>
     <tr>
         <th>[glm-members-event-front-add]</th>
         <th>member_only="{ True/False }"</th>
@@ -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.
         </td>
     </tr>
+
 ';
 
index b2a5d86..b6243cc 100644 (file)
         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(){
 
                 action: 'glm_members_admin_ajax',
                 glm_action: 'eventsCalMonthAJAX',
-                month: month
+                month: month,
+                category: category
 
             };
             $('.fc-event').remove();
index 07b0492..117da84 100644 (file)
@@ -49,9 +49,9 @@
                 <div class="small-8 medium-4 column">
                     <input class="glm-search-icon right" type="image" alt="Search" src="{$assetsUrl}search-icon-24x24.png">
                     <select id="glm-event-category" name="category">
-                        <option value="">-- All Categories --</option>
+                        <option value="0">-- All Categories --</option>
                         {foreach $categories as $cat}
-                        <option value="{$cat.id}"{if $categoryId == $cat.id} selected{/if}>{$cat.name}</option>
+                            <option value="{$cat.id}"{if $cat.default == 1} selected{/if}>{$cat.name}</option>
                         {/foreach}
                     </select>
                 </div>