Beispiel #1
0
 public function getTransports($lat, $lng)
 {
     $bbox = $this->getBoundingBox($lat, $lng);
     $url = "https://navitia.opendatasoft.com/api/records/1.0/download/?dataset=global_stops&format=json&geofilter.bbox={$bbox[0]},{$bbox[1]},{$bbox[2]},{$bbox[3]}&rows=1000&timezone=Europe%2FParis";
     return xCache('get.transports.' . sha1($url), function () use($url, $lat, $lng) {
         $json = lib('geo')->dwnCache($url);
         $tab = json_decode($json, true);
         $collection = [];
         foreach ($tab as $row) {
             $obj = [];
             $stop_id = isAke(isAke($row, 'fields', []), 'stop_id', '');
             $name = isAke(isAke($row, 'fields', []), 'stop_name', '');
             $geo = isAke(isAke($row, 'fields', []), 'geo', [0, 0]);
             $distances = distanceKmMiles($lng, $lat, $geo[1], $geo[0]);
             $type = 'bus';
             for ($i = 0; $i < strlen($name); $i++) {
                 $char = $name[$i];
                 $charC = Inflector::urlize($char, '');
                 if (strlen($charC)) {
                     if (!is_numeric($charC)) {
                         if (ctype_lower($char)) {
                             $type = 'subway';
                         }
                     }
                 }
             }
             $has = false;
             if (fnmatch("StopArea:OIF*", $stop_id)) {
                 list($dummy, $ratp_stop_id) = explode('StopArea:OIF', $stop_id, 2);
                 $native = clipp()->em('transports')->findOne(['stop_id' => strval($ratp_stop_id)]);
                 $has = true;
                 if ($native) {
                     unset($native['_id']);
                     unset($native['created_at']);
                     unset($native['updated_at']);
                     unset($native['status']);
                     unset($native['__v']);
                     $native['geo'] = $native['location']['coordinates'];
                     $native['km'] = $distances['km'];
                     $native['distances'] = $distances;
                     $collection[] = $native;
                 }
             }
             if (!$has) {
                 $obj['title'] = $name;
                 $obj['geo'] = $geo;
                 $obj['km'] = $distances['km'];
                 $obj['distances'] = $distances;
                 $obj['type'] = $type;
                 $obj['stop_id'] = $stop_id;
                 $collection[] = $obj;
             }
         }
         $check = coll($collection)->min('km');
         $collection = coll($collection)->sortBy('km')->toArray();
         $collection = array_values($collection);
         if (0.5 > $check) {
             $return = [];
             foreach ($collection as $row) {
                 if (0.5 >= $row['km']) {
                     $return[] = $row;
                 } else {
                     return $return;
                 }
             }
         } else {
             return $collection;
         }
     });
 }
Beispiel #2
0
function bag($k, $data = [])
{
    return clipp()->bag($k, $data);
}