파일 위치를 twe에서 hwe로 옮김.

This commit is contained in:
2018-04-01 01:23:44 +09:00
parent 1ddd26c8a1
commit 25ec9a2579
201 changed files with 0 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
<?php
namespace sammo;
class CityHelper{
//Just Helper
private static $list = null;
private static $listInv = null;
private static $listByNation = null;
private function __construct(){
}
public static function flushCache(){
self::$list = null;
self::$listInv = null;
self::$listByNation = null;
}
public static function generateCache(){
$list = [];
$listInv = [];
$listByNation = [];
foreach (DB::db()->query('SELECT `city` as `id`, `name`, `level`, `nation` from city') as $city) {
$id = $city['id'];
$name = $city['name'];
$list[$id] = $city;
$listInv[$city['name']] = $city;
if(!key_exists($id, $listByNation)){
$listByNation[$id] = [];
}
$listByNation[$id][] = $city;
}
self::$list = $list;
self::$listInv = $listInv;
self::$listByNation = $listByNation;
}
public static function getAllCities(){
if(self::$list === null){
self::generateCache();
}
return self::$list;
}
public static function getAllNationCities(int $nationID){
if(self::$listByNation === null){
self::generateCache();
}
return Util::array_get(self::$listByNation[$nationID], []);
}
public static function getCity(int $cityID){
if(self::$list === null){
self::generateCache();
}
return self::$list[$cityID];
}
public static function getCityByName(string $cityName){
if(self::$listInv === null){
self::generateCache();
}
return self::$listInv[$cityName];
}
}