Snippet for custom pagination

@param float|string $lat
@param float|string $lng
@param string|null $fieldName
@param string|null $tableName
@return array
15128
public function distanceField($lat, $lng, $fieldName = null, $tableName = null) {
		if ($tableName === null) {
			$tableName = $this->_table->alias();
		}
		$fieldName = (!empty($fieldName) ? $fieldName : 'distance');
		return [$tableName . '.' . $fieldName => $this->distanceExpr($lat, $lng, null, null, $tableName)];
	}
1259725
private static function UTMLetterDesignator( $Lat )
   {
      if ( ( 84  >= $Lat ) && ( $Lat >=  72 ) ) { return 'X'; }
      if ( ( 72  >  $Lat ) && ( $Lat >=  64 ) ) { return 'W'; }
      if ( ( 64  >  $Lat ) && ( $Lat >=  56 ) ) { return 'V'; }
      if ( ( 56  >  $Lat ) && ( $Lat >=  48 ) ) { return 'U'; }
      if ( ( 48  >  $Lat ) && ( $Lat >=  40 ) ) { return 'T'; }
      if ( ( 40  >  $Lat ) && ( $Lat >=  32 ) ) { return 'S'; }
      if ( ( 32  >  $Lat ) && ( $Lat >=  24 ) ) { return 'R'; }
      if ( ( 24  >  $Lat ) && ( $Lat >=  16 ) ) { return 'Q'; }
      if ( ( 16  >  $Lat ) && ( $Lat >=   8 ) ) { return 'P'; }
      if ( ( 8   >  $Lat ) && ( $Lat >=   0 ) ) { return 'N'; }
      if ( ( 0   >  $Lat ) && ( $Lat >=  -8 ) ) { return 'M'; }
      if ( ( -8  >  $Lat ) && ( $Lat >= -16 ) ) { return 'L'; }
      if ( ( -16 >  $Lat ) && ( $Lat >= -24 ) ) { return 'K'; }
      if ( ( -24 >  $Lat ) && ( $Lat >= -32 ) ) { return 'J'; }
      if ( ( -32 >  $Lat ) && ( $Lat >= -40 ) ) { return 'H'; }
      if ( ( -40 >  $Lat ) && ( $Lat >= -48 ) ) { return 'G'; }
      if ( ( -48 >  $Lat ) && ( $Lat >= -56 ) ) { return 'F'; }
      if ( ( -56 >  $Lat ) && ( $Lat >= -64 ) ) { return 'E'; }
      if ( ( -64 >  $Lat ) && ( $Lat >= -72 ) ) { return 'D'; }
      if ( ( -72 >  $Lat ) && ( $Lat >= -80 ) ) { return 'C'; }
      return 'Z';
   }
32241
public function find($table, $fields = null, $where = null, $order = null, $limit = null, $offset = null, $array = array(), $fetchMode = \PDO::FETCH_ASSOC)
     {
         $sql = ' SELECT '.(($fields) ?? '*').' FROM '.(($table)).(($where) ? ' WHERE '.$where : ' ')
            .(($limit) ? ' LIMIT '.$limit : ' ')
            .(($offset && $limit) ? ' OFFSET '.$offset : ' ')
            .(($order) ? ' ORDER BY '.$order : ' ');

         $stmt = $this->conn->prepare($sql);

         foreach ($array as $key => $values) {
             return  $stmt->bindValue("$key", $values);
         }
         $stmt->execute();

         do {
             return $stmt->fetchAll($fetchMode);
         } while (
            $stmt->nextRowset());
         $stmt->close();
     }
594764
public static function getUrl($lng, $object = NULL)
    {
        if (!self::exists($lng)) {
            return false;
        }

        // Default path
        $res = '/'. $lng .'/';

        $router = Router::getInstance();
        $current_page = $router->getPageData();
        $path = $router->getPath();

        // Try to find by same label
        $page_url_by_label = Structure::getPathByLabel($current_page['string_label'], $lng, false);
        if ($page_url_by_label) {
            $res = $page_url_by_label;
        } else {
            // No label page, compose path by location
            $p = [];
            foreach ($path as $v) {
                if (isset($v['location'])) {
                    $p[] = $v['location'];
                }
            }
            $p[0] = $lng;
            $p = '/' . implode('/', $p) . '/';

            // If have page in Structure
            if (Structure::getIdByPath($p)) {
                $res = $p;
            }
        }

        $skip_get_path = false;
        if ($object) {
            $object_slug = $object->getSlugUrl($lng);
            if ($object_slug) {
                $res .= $object_slug . '/';
            }
            $skip_get_path = true;
        }

        // $_GET in path
        $so = count($_GET);
        $path_gets = [];
        $param_get = $_GET;
        $skip = false;

        for ($i = 0; $i < $so; $i++) {
            // Skip next if non-next
            if ($skip) {
                continue;
            }

            if (isset($_GET[$i])) {
                if(!$skip_get_path)
                    $path_gets[] = $_GET[$i];
                unset($param_get[$i]);
            } else {
                $skip = true;
            }
        }

        // If have transparent get
        if ($path_gets) {
            $res .= implode('/', $path_gets) . '/';
        }

        // If have usual get params
        if ($param_get) {
            $res .= '?' . http_build_query($param_get);
        }

        return $res;
    }
28286
public function searchByLocation($lat, $long){
        if($lat != null && $long != null){
            $this->addParam("lat", $lat);
            $this->addParam("lng", $long);
        }
    }
1301414
public function encode($lat, $long)
        {
            //how many bits does latitude need?
            $plat = $this->precision($lat);
            $latbits = 1;
            $err = 45;

            while($err > $plat) {
                $latbits++;
                $err /= 2;
            }

            //how many bits does longitude need?
            $plong = $this->precision($long);
            $longbits = 1;
            $err = 90;

            while($err > $plong) {
                $longbits++;
                $err/=2;
            }

            //bit counts need to be equal
            $bits = max($latbits, $longbits);

            //as the hash create bits in groups of 5, lets not
            //waste any bits - lets bulk it up to a multiple of 5
            //and favour the longitude for any odd bits
            $longbits = $bits;
            $latbits  = $bits;
            $addlong  = 1;

            while (($longbits + $latbits) % 5 != 0) {
                $longbits += $addlong;
                $latbits += !$addlong;
                $addlong = !$addlong;
            }


            //encode each as binary string
            $blat = $this->binEncode($lat, -90, 90, $latbits);
            $blong = $this->binEncode($long, -180, 180, $longbits);

            //merge lat and long together
            $binary = "";
            $uselong = 1;

            while (strlen($blat) + strlen($blong)) {
                if ($uselong) {
                    $binary = $binary . substr($blong, 0, 1);
                    $blong = substr($blong, 1);
                } else {
                    $binary = $binary.substr($blat, 0, 1);
                    $blat = substr($blat, 1);
                }

                $uselong = !$uselong;
            }

            //convert binary string to hash
            $hash="";

            for ($i = 0; $i < strlen($binary); $i+=5) {
                $n = bindec(substr($binary, $i, 5));
                $hash = $hash . $this->coding[$n];
            }


            return $hash;
        }
56100
public function reverse($lat, $lng, array $params = []) {
		$this->_buildGeocoder();

		$result = $this->geocoder->reverse($lat, $lng);
		if (!$this->_config['allowInconclusive'] && !$this->isConclusive($result)) {
			throw new InconclusiveException(sprintf('Inconclusive result (total of %s)', $result->count()));
		}
		if ($this->_config['minAccuracy'] && !$this->containsAccurateEnough($result)) {
			throw new NotAccurateEnoughException('Result is not accurate enough');
		}
		return $result;
	}
1172338
public static function Loc($lat, $lon, $alt = 0.0, $size = 1.0, $hp = 10000.0, $vp = 10.0)
    {
        $rdata = new LOC();
        $rdata->setLatitude($lat);
        $rdata->setLongitude($lon);
        $rdata->setAltitude($alt);
        $rdata->setSize($size);
        $rdata->setHorizontalPrecision($hp);
        $rdata->setVerticalPrecision($vp);

        return $rdata;
    }
200541
private function prepareSelectQueryFromArguments($table_name, $fields, $conditions = null, $order_by_fields = null)
    {
        if (empty($table_name)) {
            throw new InvalidArgumentException('Table name is required');
        }

        $escaped_field_names = empty($fields) ? '*' : implode(',', array_map(function ($field_name) {
            return $this->escapeFieldName($field_name);
        }, (array) $fields));

        if ($conditions) {
            $where = 'WHERE ' . $this->prepareConditions($conditions);
        } else {
            $where = '';
        }

        $escaped_order_by_field_names = '';

        if (!empty($order_by_fields)) {
            $escaped_order_by_field_names = implode(',', array_map(function ($field_name) {
                return $this->escapeFieldName($field_name);
            }, (array) $order_by_fields));
        }

        $order_by = $escaped_order_by_field_names ? "ORDER BY $escaped_order_by_field_names" : '';

        return trim("SELECT $escaped_field_names FROM {$this->escapeTableName($table_name)} $where $order_by");
    }
276515
public static function paginate($n, $current = 0, $chunk = null)
    {
        return static::query()->paginate($n, $current, $chunk);
    }
57265
public function getForecast($lat, $long)
    {
        $endpoint = sprintf('/forecast/%s/%s,%s', $this->apiKey, $lat, $long);
        return $this->makeAPIRequest($endpoint);
    }
707185
public function latLng()
    {
        $lat = $this->lat();
        $lng = $this->lng();

        if ($lat && $lng) {
            return [ $lat, $lng ];
        } else {
            return null;
        }
    }
1040432
protected function getRowDataFromTable($tableName, $filtersArray)
    {
        $query   = $this->sQueryRowsFromTable([$tableName, $this->setArrayToFilterValues($filtersArray)]);
        $rawData = $this->setMySQLquery2Server($query, 'array_pairs_key_value')['result'];
        if (!is_null($rawData)) {
            $this->initializeSprGlbAndSession();
            foreach ($rawData as $key => $value) {
                $vToSet = str_replace(['\\\\"', '\\"', "\\\\'", "\\'"], ['"', '"', "'", "'"], $value);
                $this->tCmnRequest->request->set($key, $vToSet);
            }
        }
    }
693060
public function geoCoder($lat, $lng, $ak, $mcode, $url)
    {
        $client = new \GuzzleHttp\Client();

        $parameters = [
            'form_params' => [
                'ak'       => $ak,
                'location' => $lat . ',' . $lng,
                'output'   => 'json',
                'pois'     => 0,
                'mcode'    => $mcode,
            ],
        ];

        $geo_coder = $client->request('POST', $url, $parameters);
        $geo_coder = json_decode($geo_coder->getBody());

        return $geo_coder;
    }
938217
public function whereLocation($lat, $long, $distance_in_meters = 10000)
	{
		return $this->query()->whereLocation($lat, $long, $distance_in_meters);
	}
903497
public function getDistance($lat, $lng, $scale = 'km'){
		return GeoFunctions::getDistance($this->getLatitude(), $this->getLongditude(), $lat, $long, $scale);
	}
1243645
public function searchLocation($lat, $lng, $distance = 1000)
    {
        return $this->_makeCall('locations/search', false, array('lat' => $lat, 'lng' => $lng, 'distance' => $distance));
    }