ChangeCity를 시나리오에서 처리할 수 있도록 '조건 방식' 추가
This commit is contained in:
@@ -18,17 +18,14 @@ class ChangeCity extends sammo\Event\Action{
|
|||||||
const REGEXP_MATH = '/^([\+\-\/\*])(\d+(\.\d+)?)$/'; //+30 [1]=기호, [2]=float
|
const REGEXP_MATH = '/^([\+\-\/\*])(\d+(\.\d+)?)$/'; //+30 [1]=기호, [2]=float
|
||||||
|
|
||||||
private $queries;
|
private $queries;
|
||||||
private $cities;
|
private $targetType;
|
||||||
public function __construct(array $cities = null, array $actions){
|
private $targetArgs;
|
||||||
|
public function __construct(array $target = [], array $actions){
|
||||||
|
|
||||||
//values 포맷은 key, value로
|
//values 포맷은 key, value로
|
||||||
if($cities == null){
|
|
||||||
//city가 null인 경우엔 모두
|
$this->targetType = $target[0];
|
||||||
$cities = DB::db()->queryFirstColumn('SELECT city FROM city');
|
$this->targetArgs = array_slice($target, 1);
|
||||||
}
|
|
||||||
else{
|
|
||||||
$cities = DB::db()->queryFirstColumn('SELECT city FROM city WHERE name IN (%ls)', $cities);
|
|
||||||
}
|
|
||||||
|
|
||||||
$queries = [];
|
$queries = [];
|
||||||
foreach($actions as $key => $value){
|
foreach($actions as $key => $value){
|
||||||
@@ -114,10 +111,42 @@ class ChangeCity extends sammo\Event\Action{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getTargetCities($env){
|
||||||
|
|
||||||
|
$targetType = $this->targetType;
|
||||||
|
if($targetType == 'all'){
|
||||||
|
return DB::db()->queryFirstColumn('SELECT city FROM city');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($targetType == 'free'){
|
||||||
|
return DB::db()->queryFirstColumn('SELECT city FROM city WHERE nation = 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($targetType == 'occupied'){
|
||||||
|
return DB::db()->queryFirstColumn('SELECT city FROM city WHERE nation != 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($targetType == 'cities'){
|
||||||
|
if(is_numeric($this->targetArgs)){
|
||||||
|
return DB::db()->queryFirstColumn('SELECT city FROM city WHERE city IN (%ls)', $this->targetArgs);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return DB::db()->queryFirstColumn('SELECT city FROM city WHERE name IN (%ls)', $this->targetArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \InvalidArgumentException('올바르지 않은 cond 입니다.');
|
||||||
|
}
|
||||||
|
|
||||||
public function run($env=null){
|
public function run($env=null){
|
||||||
|
|
||||||
|
$target = $this->target;
|
||||||
|
$cities = $this->getTargetCities($env);
|
||||||
|
|
||||||
DB::db()->update('city',
|
DB::db()->update('city',
|
||||||
$this->queries
|
$this->queries
|
||||||
, 'city IN (%li)', $this->cities);
|
, 'city IN (%li)', $cities);
|
||||||
return [__CLASS__, DB::db()->affectedRows()];
|
return [__CLASS__, DB::db()->affectedRows()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user