Working on lat/lon parameter filter processing on pointsofinterest route
authorLaury GvR <laury@gaslightmedia.com>
Thu, 1 Aug 2019 15:41:32 +0000 (11:41 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Thu, 1 Aug 2019 15:41:32 +0000 (11:41 -0400)
setup/routes/pointsOfInterest.php

index 417f6d0..53a7d1b 100644 (file)
@@ -57,66 +57,74 @@ class GLMA_POI_Rest_Controller
             $this->resource_name ,  // resource_name
             array(      // array of arrays for multiple methods. Add more arrays for different endpoints.
                 array(  // endpoint for getting members
-                    'methods'  => WP_REST_Server::CREATABLE,
+                    'methods'  => WP_REST_Server::READABLE,
                     'callback' => function( $request ) {
                         // 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',
-                        //         'latMax' => $latMax,
-                        //         'latMin' => $lastLatMax,
-                        //         'lonMax' => $lonMax,
-                        //         'lonMin' => $lonMin
-                        //     );
-                        // }
-
-                        // // Check if there's new area at the bottom of the map
-                        // if ($latMin < $lastLatMin) {
-                        //     $poiAreas[] = array(
-                        //         'area'   => 'New at bottom',
-                        //         'latMax' => $lastLatMin,
-                        //         'latMin' => $latMin,
-                        //         'lonMax' => $lonMax,
-                        //         'lonMin' => $lonMin
-                        //     );
-                        // }
-
-                        // // Check if there's new area at the left of the map
-                        // if ($lonMin < $lastLonMin) {
-                        //     $poiAreas[] = array(
-                        //         'area'   => 'New at left',
-                        //         'latMax' => $latMax,
-                        //         'latMin' => $latMin,
-                        //         'lonMax' => $lastLonMin,
-                        //         'lonMin' => $lonMin
-                        //     );
-                        // }
-
-                        // // Check if there's new area at the right of the map
-                        // if ($lonMax > $lastLonMax) {
-                        //     $poiAreas[] = array(
-                        //         'area'   => 'New at right',
-                        //         'latMax' => $latMax,
-                        //         'latMin' => $latMin,
-                        //         'lonMax' => $lonMax,
-                        //         'lonMin' => $lastLonMax
-                        //     );
-                        // }
-                        // $poiData = apply_filters(
-                        //     'glm-hook-list-map-items-by-latlon',
-                        //     array(
-                        //         'request' => $request,
-                        //         'filter' => $searchText,
-                        //         'area'   => $poiAreas,
-                        //         'sources'  => array(),
-                        //         'mapItems' => array()
-                        //     )
-                        // );
+                        if ($latMax > $lastLatMax) {
+                            $poiAreas[] = array(
+                                'area'   => 'New at top',
+                                'latMax' => $latMax,
+                                'latMin' => $lastLatMax,
+                                'lonMax' => $lonMax,
+                                'lonMin' => $lonMin
+                            );
+                        }
+
+                        // Check if there's new area at the bottom of the map
+                        if ($latMin < $lastLatMin) {
+                            $poiAreas[] = array(
+                                'area'   => 'New at bottom',
+                                'latMax' => $lastLatMin,
+                                'latMin' => $latMin,
+                                'lonMax' => $lonMax,
+                                'lonMin' => $lonMin
+                            );
+                        }
+
+                        // Check if there's new area at the left of the map
+                        if ($lonMin < $lastLonMin) {
+                            $poiAreas[] = array(
+                                'area'   => 'New at left',
+                                'latMax' => $latMax,
+                                'latMin' => $latMin,
+                                'lonMax' => $lastLonMin,
+                                'lonMin' => $lonMin
+                            );
+                        }
+
+                        // Check if there's new area at the right of the map
+                        if ($lonMax > $lastLonMax) {
+                            $poiAreas[] = array(
+                                'area'   => 'New at right',
+                                'latMax' => $latMax,
+                                'latMin' => $latMin,
+                                'lonMax' => $lonMax,
+                                'lonMin' => $lastLonMax
+                            );
+                        }
+                        $poiData = apply_filters(
+                            'glm-hook-list-map-items-by-latlon',
+                            array(
+                                'request' => $request,
+                                // 'filter' => $searchText,
+                                'area'   => $poiAreas,
+                                'sources'  => array(),
+                                'mapItems' => array()
+                            )
+                        );
+
+                        $this->params = $request->get_params();
+
                         $test = json_encode($request['latMax']);
-                        return rest_ensure_response( $test );
+                        $response['params'] = $this->params;
+                        $response['poiData'] = $poiData;
+                        $response['poiAreas'] = $poiAreas;
+
+                        return rest_ensure_response( $response );
+                        //return rest_ensure_response( get_object_vars ( (object) $response ) );
                     },
                 )
             )