public function get($country = null) { if ($this->id && $this->id > 0) { $city = $this->city()->get($this->id); return $this->status($city, isset($city['id'])); } if (is_null($country)) { $geo = Tools::geoip(); $country = $geo['location']['country']; } $token = 'cities:' . $country; if ($data = Tools::memcache($token)) { return $this->status($data, true, 'cities'); } foreach ([$country, null] as $cntr) { $cities = $this->city()->country($cntr) ?: []; $data = array(); $event = new eventModel(); foreach ($cities as $city) { $events = $event->search(0, 0, null, $city['lat'], $city['lng'], $city['distance'] ?: 50) ?: []; $c = sprintf('%05d', count($events)); $city['count'] = $c + 0; if (count($events)) { $data[$c . '-' . $city['name']] = $city; } } krsort($data); $data2 = []; foreach ($data as $c) { $data2[] = $c; if (count($data2) == 3) { break; } } if (count($data2)) { break; } } return $this->status(Tools::memcache($token, $data2), true, 'cities'); }