From: Laury GvR Date: Wed, 7 Aug 2019 23:08:01 +0000 (-0400) Subject: POI route error messages added, coupons, packages initialised X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=b718ae14b046eeb99d58abd793a17c9b71058ddb;p=WP-Plugins%2Fglm-member-db-rest-api.git POI route error messages added, coupons, packages initialised --- diff --git a/setup/routes/pointsOfInterest.php b/setup/routes/pointsOfInterest.php index f492382..c5b696a 100644 --- a/setup/routes/pointsOfInterest.php +++ b/setup/routes/pointsOfInterest.php @@ -77,6 +77,7 @@ class GLMA_POI_Rest_Controller $poiRequest = $this->params['poiRequest']; + $addons = explode(",", $this->params['addons'] ); $searchText = "test"; @@ -84,11 +85,10 @@ class GLMA_POI_Rest_Controller $limit = $this->params['limit']; } + + //$mapItems = $MapItems->modelAction($data['request'], $data['area'], $data['filter']); + - // Callback function can be a lot shorter. - // You could just create a new model to get the results in an array - // and use return rest_ensure_response( $data ); - // Check if there's new area at the top of the map if ($latMax > $lastLatMax) { $poiAreas[] = array( 'area' => 'New at top', @@ -142,11 +142,6 @@ class GLMA_POI_Rest_Controller ) ); - $this->params = $request->get_params(); - - - //$mapItems = $MapItems->modelAction($data['request'], $data['area'], $data['filter']); - //$limit = 5; $dateFrom = "2016-11-22 00:00:00"; $dateTo = "2026-11-30 24:59:59"; @@ -168,117 +163,114 @@ class GLMA_POI_Rest_Controller } - $sql = " - SELECT E.id, - L.id AS loc_id, - L.lat, - L.lon, - E.name, - L.name AS loc_name, - L.address AS addr1, - '' AS addr2, - C.name AS city, - L.state, - L.zip, - E.contact_phone AS phone, - E.contact_email AS email, - E.url, - R.name AS region, - E.descr, - E.intro AS short_descr - FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."events E, - ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."locations L, - ".GLM_MEMBERS_PLUGIN_DB_PREFIX."cities C, - ".GLM_MEMBERS_PLUGIN_DB_PREFIX."regions R - WHERE E.status = 10 - AND L.event = E.id - AND C.id = L.city - AND R.id = L.region - AND ( - SELECT MIN(start_time) - FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."times - WHERE event = E.id - AND active - ) < '$dateFrom' - AND ( - SELECT MAX(end_time) - FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."times - WHERE event = E.id - AND active - ) > '$dateTo' - $latLonWhereForEventLoc - $textWhere - - ;"; - $eventsEventLocations = $this->wpdb->get_results($sql, ARRAY_A); - - $sql = " - SELECT E.id, - L.id AS loc_id, - L.lat, - L.lon, - E.name, - L.name AS loc_name, - L.address AS addr1, - '' AS addr2, - C.name AS city, - L.state, - L.zip, - E.contact_phone AS phone, - E.contact_email AS email, - E.url, - R.name AS region, - E.descr, - E.intro AS short_descr - FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."events E, - ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."locations L, - ".GLM_MEMBERS_PLUGIN_DB_PREFIX."cities C, - ".GLM_MEMBERS_PLUGIN_DB_PREFIX."regions R - WHERE E.status = 10 - AND L.event = E.id - AND C.id = L.city - AND R.id = L.region - AND L.lat < $latMax - AND L.lat > $latMin - AND L.lon < $lonMax - AND L.lon > $lonMin - LIMIT $limit - "; - - $latlontest = $this->wpdb->get_results($sql, ARRAY_A); - - - $sql = " - SELECT M.id, - M.name, - M.member_slug, - M.featured, - MI.member as member_info_id, - MI.addr1, - MI.addr2, - MI.city, - MI.state, - MI.country, - MI.zip, - MI.lat, - MI.lon, - MI.region, - MI.county, - MI.phone, - MI.url, - MI.email, - MI.logo - FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M, - ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI - WHERE M.id = MI.member - AND MI.status = 10 - AND MI.lat < $latMax - AND MI.lat > $latMin - AND MI.lon < $lonMax - AND MI.lon > $lonMin - LIMIT $limit - "; - $membertest = $this->wpdb->get_results($sql, ARRAY_A); + + + if ( in_array( 'events', $addons ) ) { + if ( !defined( "GLM_MEMBERS_EVENTS_PLUGIN_PATH" ) ) { + $events['error'] = "ERR: events addon requested but not found"; + } else { + $sql = " + SELECT E.id, + L.id AS loc_id, + L.lat, + L.lon, + E.name, + L.name AS loc_name, + L.address AS addr1, + '' AS addr2, + C.name AS city, + L.state, + L.zip, + E.contact_phone AS phone, + E.contact_email AS email, + E.url, + R.name AS region, + E.descr, + E.intro AS short_descr + FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."events E, + ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."locations L, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."cities C, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."regions R + WHERE E.status = 10 + AND L.event = E.id + AND C.id = L.city + AND R.id = L.region + AND L.lat < $latMax + AND L.lat > $latMin + AND L.lon < $lonMax + AND L.lon > $lonMin + LIMIT $limit + "; + + $events = $this->wpdb->get_results($sql, ARRAY_A); + if (!$events) { + $events['error'] = "ERR: no events found"; + } + } + $response['events'] = $events; + } + + if ( in_array( 'coupons', $addons ) ) { + + if ( !defined( "GLM_MEMBERS_COUPONS_PLUGIN_PATH" ) ) { + $coupons['error'] = "ERR: coupons addon requested but not found"; + } else { + $coupons = "o"; + } + //$summary['coupons'] = $this->get_coupons_summary(); + $response['coupons'] = $coupons; + } + if ( in_array( 'packaging', $addons ) ) { + if ( !defined( "GLM_MEMBERS_PACKAGING_PLUGIN_PATH" ) ) { + $packages['error'] = "ERR: packaging addon requested but not found"; + } else { + $packages = "o"; + } + //$summary['packaging'] = $this->get_packaging_summary(); + $response['packaging'] = $packages; + } + + if ( in_array( 'members', $addons ) ) { + if ( !defined( "GLM_MEMBERS_PLUGIN_PATH" ) ) { + $members['error'] = "ERR: members addon requested but not found"; + } else { + $sql = " + SELECT M.id, + M.name, + M.member_slug, + M.featured, + MI.member as member_info_id, + MI.addr1, + MI.addr2, + MI.city, + MI.state, + MI.country, + MI.zip, + MI.lat, + MI.lon, + MI.region, + MI.county, + MI.phone, + MI.url, + MI.email, + MI.logo + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI + WHERE M.id = MI.member + AND MI.status = 10 + AND MI.lat < $latMax + AND MI.lat > $latMin + AND MI.lon < $lonMax + AND MI.lon > $lonMin + LIMIT $limit + "; + $members = $this->wpdb->get_results($sql, ARRAY_A); + if (!$members) { + $members['error'] = "ERR: no members found"; + } + } + $response['members'] = $members; + } // $sql = " // SELECT L.id, L.event @@ -289,12 +281,9 @@ class GLMA_POI_Rest_Controller //$test = json_encode($request['latMax']); // $response['locationtest'] = $locationtest; - $response['membertest'] = $membertest; - $response['latlontest'] = $latlontest; $response['params'] = $this->params; $response['poiData'] = $poiData; $response['poiAreas'] = $poiAreas; - $response['eventsEventLocations'] = $eventsEventLocations; return rest_ensure_response( $response ); //return rest_ensure_response( get_object_vars ( (object) $response ) );