public function satisfy($condition, $objectItem, $objectKey = null)
{
if (is_array($condition)) {
$condition = Condition::create($condition, $this->jarves);
}
$complied = null;
$lastOperator = 'and';
$rules = $condition->getRules();
if (!$rules) {
return null;
}
/*
* [
* ['id', '=', 5],
* 'or',
* ['id', '=', 6]
* ]
*
* [
* Condition,
* 'and',
* [Condition]
* ]
*
*
*/
foreach ($rules as $conditionRule) {
if (is_string($conditionRule)) {
$lastOperator = strtolower($conditionRule);
continue;
}
$res = false;
if (is_array($conditionRule) && is_string($conditionRule[0]) && is_string($conditionRule[1])) {
$res = $this->checkRule($objectItem, $conditionRule, $objectKey);
} else {
if ($conditionRule instanceof Condition) {
$res = $this->satisfy($conditionRule, $objectItem, $objectKey);
} else {
if (is_array($conditionRule)) {
//group
$res = $this->satisfy(Condition::create($conditionRule, $this->jarves), $objectItem, $objectKey);
}
}
}
if (is_null($complied)) {
$complied = $res;
} else {
if ($lastOperator == 'and') {
$complied = $complied && $res;
}
if ($lastOperator == 'and not') {
$complied = $complied && !$res;
}
if ($lastOperator == 'or') {
$complied = $complied || $res;
}
}
}
return $complied === null ? true : ($complied ? true : false);
}