From: Chuck Scott Date: Tue, 13 Dec 2016 18:33:48 +0000 (-0500) Subject: Added support for nearMe feature by adding quick search capability by lat/lon and... X-Git-Tag: v1.6.0^2~7 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=2bab33898c68c6bd2c8b6545b68b3c33f65a8cd6;p=WP-Plugins%2Fglm-member-db-events.git Added support for nearMe feature by adding quick search capability by lat/lon and text adminHooks now haa hook for this search eventDataByLatLon.php added to do these queries --- diff --git a/models/front/events/eventDataByLatLon.php b/models/front/events/eventDataByLatLon.php index e9efdee..c4d5dad 100644 --- a/models/front/events/eventDataByLatLon.php +++ b/models/front/events/eventDataByLatLon.php @@ -131,27 +131,43 @@ class GlmMembersFront_events_eventDataByLatLon extends GlmDataEvents * @return array Items (see above) - Returns false if total failure. * */ - public function modelAction ($search = false) + public function modelAction ($request = 'onMap', $search = false, $searchText = '') { $items = array(); // Do sanity check on supplied data - if (!is_array($search) || count($search) <= 0) { + if ($request == 'onMap' && (!is_array($search) || count($search) <= 0)) { return false; } - // Build query where clause for each search area - $latLonWhereForEventLoc = '( '; - $latLonWhereForMembLoc = '( '; - $or = ''; - foreach ($search as $area) { - $latLonWhereForEventLoc .= " $or ( (L.lat BETWEEN ".$area['latMin']." AND ".$area['latMax'].") AND (L.lon BETWEEN ".$area['lonMin']." AND ".$area['lonMax'].") ) "; - $latLonWhereForMembLoc .= " $or ( (I.lat BETWEEN ".$area['latMin']." AND ".$area['latMax'].") AND (I.lon BETWEEN ".$area['lonMin']." AND ".$area['lonMax'].") ) "; - $or = 'OR'; + // If this is an "onMap" request build query where clause for each search area - otherwise it's anywhere + $latLonWhereForEventLoc = ''; + $latLonWhereForMembLoc = ''; + if ($request == 'onMap') { + + $latLonWhereForEventLoc = ' AND ( '; + $latLonWhereForMembLoc = ' AND ( '; + $or = ''; + foreach ($search as $area) { + $latLonWhereForEventLoc .= " $or ( (L.lat BETWEEN ".$area['latMin']." AND ".$area['latMax'].") AND (L.lon BETWEEN ".$area['lonMin']." AND ".$area['lonMax'].") ) "; + $latLonWhereForMembLoc .= " $or ( (I.lat BETWEEN ".$area['latMin']." AND ".$area['latMax'].") AND (I.lon BETWEEN ".$area['lonMin']." AND ".$area['lonMax'].") ) "; + $or = 'OR'; + } + $latLonWhereForEventLoc .= ')'; + $latLonWhereForMembLoc .= ')'; + + } + + $testWhere = ''; + if ($searchText != '') { + $textWhere .= " + AND ( + E.name like '%".addslashes($searchText)."%' + OR E.descr like '%".addslashes($searchText)."%' + ) + "; } - $latLonWhereForEventLoc .= ')'; - $latLonWhereForMembLoc .= ')'; // Determine first and last dates to display $dateFrom = "2016-11-22 00:00:00"; @@ -196,7 +212,9 @@ class GlmMembersFront_events_eventDataByLatLon extends GlmDataEvents WHERE event = E.id AND active ) > '$dateTo' - AND $latLonWhereForEventLoc + $latLonWhereForEventLoc + $textWhere + ;"; $eventsEventLocations = $this->wpdb->get_results($sql, ARRAY_A); //trigger_error(print_r($eventsEventLocations,1), E_USER_NOTICE); @@ -254,16 +272,19 @@ class GlmMembersFront_events_eventDataByLatLon extends GlmDataEvents WHERE event = E.id AND active ) > '$dateTo' - AND $latLonWhereForMembLoc + $latLonWhereForEventLoc + $textWhere ;"; + $eventsMemberLocations = $this->wpdb->get_results($sql, ARRAY_A); // Merge both arrays into one to simplify further processing - $events = array_merge($eventsEventLocations, $eventsMemberLocations); + $eventsData = array_merge($eventsEventLocations, $eventsMemberLocations); // Rebuild data with correct array format for map items - if (is_array($events) && count($events) > 0) { - foreach ($events as $k=>$v) { + $events = array(); + if (is_array($eventsData) && count($eventsData) > 0) { + foreach ($eventsData as $k=>$v) { // Get any categories for this event $cats = array(); @@ -276,7 +297,8 @@ class GlmMembersFront_events_eventDataByLatLon extends GlmDataEvents ;"; $eventCats = $this->wpdb->get_results($sql, ARRAY_A); - $events[$k] = array( + // Add to results - Key is {type}.{event ID} + $events['Event'+$v['id']] = array( 'type' => 'Event', 'id' => $v['id'], 'lat' => $v['lat'], diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 60b3ff9..b47200a 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -68,8 +68,17 @@ add_filter( * The array supplied is in the following standardized format. This format is * used for all generic map items aggregated from multiple sources. * + * 'request' What type of request is being made - Request only + * 'filter' A string filter to use to limit results - Request only + * 'area' A set of lat/lon areas to get results for (if request = 'onMap') - Request only + * If false then get all results without regard as to where they are. + * 'sources' An array of source information for what type of item and which add-on - Each source adds one entry here + * 'mapItems' Array of new map items to return to NearMe - Each source adds one or more map items here + * * array( - * search => array( + * 'request' => {'onMap', 'anywhere'} + * 'filter' => {some search string} + * 'area' => array( * // First area to search * array( * 'latMax' => {lat at North end of area}, @@ -86,26 +95,33 @@ add_filter( * ), * // Additional areas * ), - * mapItems => array( + * 'sources' => array( + * addOn' => {addOn slug}, + * 'type' => {text name for the marker type (i.e. Member, ...)} + * ), + * 'mapItems' => array( * array( - * 'type' => {type of item, i.e. 'member', 'event', ...}, - * 'id' => {ID of item for reference}, - * 'lat' => {Latitude}, - * 'lon' => {Longitude}, - * 'name' => {Name of item}, - * 'addr1' => {Address line 1 of location}, - * 'addr2' => {Address line 2 of location}, - * 'city' => {City of location}, - * 'state' => {State code of location}, - * 'zip' => {Postal Code of location}, - * 'phone' => {Contact phone number}, - * 'email' => {Contact E-Mail address}, - * 'url' => {URL of item}, - * 'detailPage' => {URL of detail page, if available}, - * 'region' => {Region name, if available}, - * 'category' => {Category name if available}, - * 'description'=> {Description}, - * 'shortDescr' => {Short Description} + * 'type' => {type of item, i.e. 'member', 'event', ...}, + * 'id' => {ID of item for reference}, + * 'lat' => {Latitude}, + * 'lon' => {Longitude}, + * 'name' => {Name of item}, + * 'loc_name' => {Name of Location}, + * 'addr1' => {Address line 1 of location}, + * 'addr2' => {Address line 2 of location}, + * 'city' => {City of location}, + * 'state' => {State code of location}, + * 'zip' => {Postal Code of location}, + * 'phone' => {Contact phone number}, + * 'email' => {Contact E-Mail address}, + * 'url' => {URL of item}, + * 'region' => {Region name, if available}, + * 'categories' => {array of categories - i.e. array( 0 = array( id => {id}, name => {name}), ... ) + * 'descr' => {Description}, + * 'short_descr' => {Short Description}, + * 'detail_page' => {URL of detail page, if available}, + * 'dates' => {Text stating date, dates, or date range}, + * 'times' => {Text stating time, times, or time range} * ) * ) * ) @@ -123,7 +139,7 @@ add_filter( 'glm-hook-list-map-items-by-latlon', function($data) { // Call dedicated model to perform search include_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/models/front/events/eventDataByLatLon.php'; $MapItems = new GlmMembersFront_events_eventDataByLatLon($this->wpdb, $this->config); - $mapItems = $MapItems->modelAction($data['search']); + $mapItems = $MapItems->modelAction($data['request'], $data['area'], $data['filter']); // Add the info on this source $data['sources'][GLM_MEMBERS_EVENTS_PLUGIN_SLUG] = array(