Updating the get events function in baseAction.php
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 2 Nov 2016 16:35:42 +0000 (12:35 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 2 Nov 2016 16:36:40 +0000 (12:36 -0400)
Updating these so you can have more than one of these given and it will
select events properly.
Before it would only goto one case.
Building an array for the wherePart and imploding it with AND to build
the where part for the event list call.

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

index 411c245..3fb764d 100644 (file)
@@ -122,7 +122,8 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents
      *
      * @param integer $categoryId Id of the category for filtering events (optional)
      * @param integer $limit      Number of events to return (optional)
-     * @param integer $memberID Member ID if filtering by member
+     * @param integer $memberId   Member ID if filtering by member
+     * @param integer $amenityId  Amenity id for filter
      *
      * @access public
      * @return array events
@@ -131,14 +132,15 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents
     {
 
         $this->postAddTimes = true;
+        $whereParts = array();
         $where = '';
 
         if ($memberId = filter_var( $memberId, FILTER_VALIDATE_INT )) {
-            $where .= "T.ref_type = ".$this->config['ref_type_numb']['Member']." and T.ref_dest = $memberId AND ";
+            $whereParts[] = "T.ref_type = ".$this->config['ref_type_numb']['Member']." and T.ref_dest = $memberId ";
         }
 
         if ( $amenityId = filter_var( $amenityId, FILTER_VALIDATE_INT ) ) {
-            $where = "
+            $whereParts[] = "
             T.id IN (
                 SELECT event
                   FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "amenity_event
@@ -155,7 +157,7 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents
         // If a category ID is supplied
         if ( $catId = filter_var( $categoryId, FILTER_VALIDATE_INT ) ) {
             //$events = $this->getEventsByCategory( $catId, $limit );
-            $where = "
+            $whereParts[] = "
                 T.id IN (
                     SELECT event
                       FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories
@@ -175,7 +177,7 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents
             // 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 ) );
-            $where .= "T.name like '%" . $term . "%'
+            $whereParts[] .= "T.name like '%" . $term . "%'
                 AND T.status = " . $this->config['status_numb']['Active'] . "
                 AND T.id IN (
                         SELECT event
@@ -188,7 +190,7 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents
             $order .= " LIMIT 2 OFFSET 0";
         } else if ( $limit = filter_var( $limit, FILTER_VALIDATE_INT ) ) {
             // Need to get the event id's for the next $limit number of events.
-            $where .= "T.id
+            $whereParts[] .= "T.id
                 AND T.status = " . $this->config['status_numb']['Active'] . "
                 AND T.id IN (
                         SELECT distinct event
@@ -200,7 +202,7 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents
             $order  = "T.id";
             // Otherwise get all categories
         } else {
-            $where .= "T.status = " . $this->config['status_numb']['Active'] . "
+            $whereParts[] .= "T.status = " . $this->config['status_numb']['Active'] . "
                 AND T.id IN (
                         SELECT event
                           FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
@@ -210,6 +212,11 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents
                 ";
         }
 
+        if ( isset( $whereParts ) && !empty( $whereParts ) ) {
+            $where = implode( ' AND ', $whereParts);
+        }
+        //echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
+
         $events = $this->getList( $where, $order );
 
         if ( !empty( $events ) ) {
index 53353b6..b1e9cde 100644 (file)
@@ -190,7 +190,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
         }
 
         if ( isset( $_REQUEST['event_name'] )
-            && $eventNameSearch = filter_var($_REQUEST['event_name'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)) {
+            && $eventNameSearch = filter_var( $_REQUEST['event_name'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES ) ) {
             $search = true;
             $action = 'event-list-name';
         } else {
@@ -212,7 +212,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
 
         switch ( $action ) {
         case 'front-page':
-            $events = $this->getModelEventsData( $categoryId, $limit );
+            $events = $this->getModelEventsData( $categoryId, $limit, $memberId, $amenityId );
             break;
         case 'event-list-name':
             $events = $this->getModelEventsData( $eventNameSearch, null, $memberId, $amenityId );
@@ -543,7 +543,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
             if ( !$view ) {
                 $view = 'agenda.html';
             }
-            $events = $this->getModelEventsData( $categoryId, null, $memberId );
+            $events = $this->getModelEventsData( $categoryId, null, $memberId, $amenityId );
             $this->postAddRecurrences = false;
             break;
         }