From 07acdb7c38baad6e38ea21ec82956690acb7326c Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 3 Sep 2018 09:50:53 -0400 Subject: [PATCH] Manage parameters for the function that returns the event array. Turning the many many parameters into one $event_config array. Set up $defaults array to merge with the $event_config. --- models/front/events/baseAction.php | 99 ++++++++++++++++++++++-------- models/front/events/detail.php | 2 +- models/front/events/list.php | 21 +++++-- 3 files changed, 89 insertions(+), 33 deletions(-) diff --git a/models/front/events/baseAction.php b/models/front/events/baseAction.php index 4cb5d4a..2045986 100644 --- a/models/front/events/baseAction.php +++ b/models/front/events/baseAction.php @@ -190,33 +190,80 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents * * Return the array of events. * - * @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 $amenityId Amenity id for filter - * @param integer $venueId Venue id for filter + * Defaults. + * $defaults = [ + * 'categories' => null, + * 'event_name' => null, + * 'member_id' => null, + * 'amenity_id' => null, + * 'venue_id' => null, + * 'city_id' => null, + * 'limit' => null, + * ]; + * + * Config parameters. Overrides Defaults. + * $config = [ + * 'categories' => $categories, + * 'event_name' => $event_name, + * 'member_id' => $member_id, + * 'amenity_id' => $amenity_id, + * 'venue_id' => $venue_id, + * 'city_id' => $city_id, + * 'limit' => $limit, + * ]; + * + * @param integer $event_config Config Parameters * * @access public * @return array events */ - public function getModelEventsData( $categoryId = null, $limit = null, $memberId = null, $amenityId = null, $venueId = null, $cityId = null, $isNameSearch = false ) + //public function getModelEventsData( $categoryId = null, $limit = null, $memberId = null, $amenityId = null, $venueId = null, $cityId = null, $isNameSearch = false ) + public function getModelEventsData( $event_config ) { + // Initialize $is_name_search to false. + $is_name_search = false; + + // Setup of defaults. + $defaults = [ + 'categories' => null, + 'event_name' => null, + 'member_id' => null, + 'amenity_id' => null, + 'venue_id' => null, + 'city_id' => null, + 'limit' => null, + ]; + + // Merge the default and event_config arrays. + $params = array_merge( $defaults, $event_config ); + + // Pull all parameter values. + $categories = $params['categories']; + $event_name = $params['event_name']; + $member_id = $params['member_id']; + $amenity_id = $params['amenity_id']; + $venue_id = $params['venue_id']; + $city_id = $params['city_id']; + $limit = $params['limit']; - // echo '
$cityId: ' . print_r( $cityId, true ) . '
'; $this->postAddTimes = true; $whereParts = array(); $where = $order = ''; - if ($memberId = filter_var( $memberId, FILTER_VALIDATE_INT )) { - $whereParts[] = "T.ref_type = ".$this->config['ref_type_numb']['Member']." and T.ref_dest = $memberId "; + if ( $event_name ) { + $is_name_search = true; + } + + if ( $member_id = filter_var( $member_id, FILTER_VALIDATE_INT )) { + $whereParts[] = "T.ref_type = ".$this->config['ref_type_numb']['Member']." and T.ref_dest = $member_id "; } - if ( $amenityId = filter_var( $amenityId, FILTER_VALIDATE_INT ) ) { + if ( $amenity_id = filter_var( $amenity_id, FILTER_VALIDATE_INT ) ) { $whereParts[] = " T.id IN ( SELECT event FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "amenity_event - WHERE amenity = {$amenityId} + WHERE amenity = {$amenity_id} AND event IN ( SELECT event FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET @@ -227,15 +274,15 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents } // check for city id in event list search - if ( ( $cityId = filter_var( $cityId, FILTER_VALIDATE_INT ) ) && !$isNameSearch ) { - // echo '
$cityId: ' . print_r( $cityId, true ) . '
'; + if ( ( $city_id = filter_var( $city_id, FILTER_VALIDATE_INT ) ) && !$is_name_search ) { + // echo '
$city_id: ' . print_r( $city_id, true ) . '
'; $whereParts[] = "( (T.use_member_location <> true AND T.id IN ( SELECT event FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "locations - WHERE city = {$cityId} + WHERE city = {$city_id} )) OR ( T.use_member_location = true @@ -244,15 +291,15 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents SELECT member FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info WHERE status = 10 - AND city = {$cityId} + AND city = {$city_id} ) ) )"; } - if ( $venueId = filter_var( $venueId, FILTER_VALIDATE_INT ) ) { + if ( $venue_id = filter_var( $venue_id, FILTER_VALIDATE_INT ) ) { $whereParts[] = " - T.other_ref_dest = {$venueId} + T.other_ref_dest = {$venue_id} AND T.id IN ( SELECT event FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET @@ -262,11 +309,11 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents "; } - // Get cats if categoryId is an array - $cats = array_filter( filter_var( $categoryId, FILTER_VALIDATE_INT, array( 'flags' => FILTER_FORCE_ARRAY ) ) ); - $catId = filter_var( $categoryId, FILTER_VALIDATE_INT ); + // Get cats if categories is an array + $cats = array_filter( filter_var( $categories, FILTER_VALIDATE_INT, array( 'flags' => FILTER_FORCE_ARRAY ) ) ); + $catId = filter_var( $categories, FILTER_VALIDATE_INT ); // If a category ID is supplied - if ( $catId && !$isNameSearch ) { + if ( $catId && !$is_name_search ) { //$events = $this->getEventsByCategory( $catId, $limit ); $whereParts[] = " T.id IN ( @@ -285,7 +332,7 @@ 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 ) && !$isNameSearch ) { + } else if ( $this->notInCat && !empty( $this->notInCat ) && !$is_name_search ) { $whereParts[] = " T.id NOT IN ( SELECT event @@ -303,13 +350,13 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents $order .= " LIMIT {$limit} OFFSET 0"; } - // Else if the $categoryId is an array - } else if ( $cats && !empty( $cats ) && !$isNameSearch ) { + // Else if the $categories is an array + } else if ( $cats && !empty( $cats ) && !$is_name_search ) { $whereParts[] = " T.id IN ( SELECT event FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories - WHERE category IN (" . implode( ',', $categoryId ) . ") + WHERE category IN (" . implode( ',', $categories ) . ") AND event IN ( SELECT event FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET @@ -323,7 +370,7 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents $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 ) ) { + } else if ( $term = filter_var( $event_name, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES ) ) { $searchTerm = $this->wpdb->esc_like( stripslashes( $term ) ); $whereParts[] .= "T.name like '%" . $term . "%' AND T.status = " . $this->config['status_numb']['Active'] . " diff --git a/models/front/events/detail.php b/models/front/events/detail.php index 9b9c1b0..ec3ab8e 100755 --- a/models/front/events/detail.php +++ b/models/front/events/detail.php @@ -33,7 +33,7 @@ class GlmMembersFront_events_detail extends GlmMembersFront_events_baseAction { $status = null; $action = ''; - $settings = $event = array(); + $settings = $event = array(); $event = null; $categories = array(); $amenityId = null; diff --git a/models/front/events/list.php b/models/front/events/list.php index 0bd6e3d..a5580e2 100644 --- a/models/front/events/list.php +++ b/models/front/events/list.php @@ -370,16 +370,25 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction wp_enqueue_script('event-dashboard-js'); wp_enqueue_style('jquery-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css'); - // echo '
$action: ' . print_r( $action, true ) . '
'; + $event_config = [ + 'categories' => $categoryId, + 'event_name' => $eventNameSearch, + 'member_id' => $memberId, + 'amenity_id' => $amenityId, + 'venue_id' => $venueId, + 'city_id' => $cityId, + 'limit' => $limit, + ]; + switch ( $action ) { case 'front-page': $this->postAddRecurrences = true; - $events = $this->getModelEventsData( $categoryId, $limit, $memberId, $amenityId, $venueId ); + $events = $this->getModelEventsData( $event_config ); $this->postAddRecurrences = false; break; case 'event-list-name': $this->postAddRecurrences = true; - $events = $this->getModelEventsData( $eventNameSearch, null, $memberId, $amenityId, $venueId, null, true ); + $events = $this->getModelEventsData( $event_config ); $this->postAddRecurrences = false; if ( !$view ) { $view = 'agenda.html'; @@ -388,7 +397,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction case 'event-list': $this->postAddLocations = true; $this->postAddRecurrences = true; - $events = $this->getModelEventsData( $categoryId, null, $memberId, $amenityId, $venueId, $cityId ); + $events = $this->getModelEventsData( $event_config ); if ( !$view ) { $view = 'agenda.html'; } @@ -445,7 +454,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction include_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/SetaPDF/Autoload.php'; $this->postAddLocations = true; $this->postAddRecurrences = true; - $events = $this->getModelEventsData( $categoryId, null, $memberId, $amenityId, $venueId ); + $events = $this->getModelEventsData( $event_config ); $this->postAddLocations = false; $this->postAddRecurrences = false; @@ -719,7 +728,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction if ( !$view ) { $view = 'agenda.html'; } - $events = $this->getModelEventsData( $categoryId, null, $memberId, $amenityId, $venueId, $cityId ); + $events = $this->getModelEventsData( $event_config ); $this->postAddRecurrences = false; $this->postAddLocations = false; break; -- 2.17.1