From fb41550b857f8c2d7ccec44a7f9f82e01f68d282 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 25 Jan 2018 14:43:43 -0500 Subject: [PATCH] Added getEventsCities() method to get a simple list of cities for a list of events. --- classes/data/dataEvents.php | 79 ++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/classes/data/dataEvents.php b/classes/data/dataEvents.php index 5216567..0ac06e5 100644 --- a/classes/data/dataEvents.php +++ b/classes/data/dataEvents.php @@ -518,7 +518,8 @@ class GlmDataEvents extends GlmDataAbstract $r['categories'] = $this->wpdb->get_results($sql, ARRAY_A); } - if ( isset( $this->postAmenities ) && $this->postAmenities ) { + if ($this->postAmenities) { + $sql = " SELECT EC.event AS event_id, C.id, C.name FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "amenities AS C, @@ -551,16 +552,14 @@ class GlmDataEvents extends GlmDataAbstract } } if ($this->postAddLocations) { + include_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberInfo.php'; + $memberData = new GlmDataMemberInfo( $this->wpdb, $this->config ); $r['locations'] = array(); if ( $r['use_member_location']['value'] ) { - include_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberInfo.php'; - $memberData = new GlmDataMemberInfo( $this->wpdb, $this->config ); $member = $memberData->getActiveInfoForMember((int)$r['ref_dest_id']); $r['member'] = $member; } else if ( $r['other_ref_dest_id'] ) { // get member id from the name - include_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberInfo.php'; - $memberData = new GlmDataMemberInfo( $this->wpdb, $this->config ); $member = $memberData->getActiveInfoForMember( (int)$r['other_ref_dest_id'] ); $r['member'] = $member; } else { @@ -894,6 +893,76 @@ class GlmDataEvents extends GlmDataAbstract return $r; } + + /** + * Get Cities List for Events + * + * Searches for cities with both member and internal data. + * May use option to specify a WHERE clause to limit the events + * that the cities are drawn from. + * + * @param string $where WHERE string to limit initial query of events. + * + * @return array cities list where key is city ID and value is an array of 'id', 'name' + */ + public function getEventsCities($where = 'true') + { + + $savedFields = $this->fields; + $savedpostAddTimes = $this->postAddTimes; + $savedpostAddLocations = $this->postAddLocations; + $savedpostAddRecurrences = $this->postAddRecurrences; + $savedpostFirstAndLastTimes = $this->postFirstAndLastTimes; + $savedpostCategories = $this->postCategories; + $savedpostAmenities = $this->postAmenities; + + $this->postAddTimes = false; + $this->postAddLocations = true; + $this->postAddRecurrences = false; + $this->postFirstAndLastTimes = false; + $this->postCategories = false; + $this->postAmenities = false; + + $this->fields = array( + 'id' => $savedFields['id'], + 'name' => $savedFields['name'], + 'use_member_location' => $savedFields['use_member_location'], + 'ref_dest_id' => $savedFields['ref_dest_id'], + 'other_ref_dest_id' => $savedFields['other_ref_dest_id'] + ); + + $events = $this->getList($where); + + $eventCities = array(); + foreach ($events as $event) { + + if (isset($event['member'])) { + $eventCities[$event['member']['city_id']] = array( + 'id' => $event['member']['city_id'], + 'name' => $event['member']['city'] + ); + } elseif (isset($event['locations'])) { + $eventCities[$event['locations']['city']['value']] = array( + 'id' => $event['locations']['city']['value'], + 'name' => $event['locations']['city']['name'] + ); + } + + } + + $this->fields = $savedFields; + $this->postAddTimes = $savedpostAddTimes; + $this->postAddLocations = $savedpostAddLocations; + $this->postAddRecurrences = $savedpostAddRecurrences; + $this->postFirstAndLastTimes = $savedpostFirstAndLastTimes; + $this->postCategories = $savedpostCategories; + $this->postAmenities = $savedpostAmenities; + + return $eventCities; + + } + + } -- 2.17.1