집합, 귀환 추가

This commit is contained in:
2018-10-17 02:38:51 +09:00
parent 337424cb96
commit 220e98b2cc
9 changed files with 338 additions and 135 deletions
@@ -0,0 +1,38 @@
<?php
namespace sammo\Constraint;
use sammo\DB;
//TODO: DB 사용하지 않도록 변경
class MustBeTroopLeader extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
if(!key_exists('troop', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require troop in general");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
//XXX: 부대장인지 알 수가 없음
$db = DB::db();
$troopLeader = $db->queryFirstField('SELECT no FROM troop WHERE troop = %i', $this->general['troop']);
if($troopLeader == $this->general['no']){
return true;
}
$this->reason = "부대장이 아닙니다.";
return false;
}
}