Update events to exclude a category.
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 14 May 2018 16:21:55 +0000 (12:21 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 14 May 2018 16:21:55 +0000 (12:21 -0400)
When setting up the shortcode use a negative number to exclude the event
category.

models/front/events/baseAction.php
models/front/events/list.php

index 669a5ff..db8ead9 100644 (file)
@@ -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[] = "
index 78fc17e..0ac3174 100644 (file)
@@ -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);
                 }
 
             }