/** * * @param TheatreNearby $tnb * @return GeocodeCached * */ public static function getGeocodeCached(TheatreNearby $tnb) { $queryWhere = new \DbTableWhere(); $queryWhere->where('country_iso', $tnb->country_iso); if ($tnb->postal_code) { $queryWhere->where(new \DbTableFunction("REPLACE(postal_code, ' ', '')"), str_replace(' ', '', $tnb->postal_code)); } else { $queryWhere->where('city', $tnb->city); } $key = $queryWhere->getWhereString(); if (array_key_exists($key, self::$cachedGeocodes)) { return self::$cachedGeocodes[$key]; } else { return self::$cachedGeocodes[$key] = GeocodeCached::manager()->getEntityWhere($queryWhere); } }