public function addCondition($field, $operator = null, $value = null)
{
if (is_array($field)) {
array_map(function ($a) {
call_user_func_array([$this, 'addCondition'], $a);
}, $field);
return $this;
}
$f = null;
// Perform basic validation to see if the field exists
if (is_string($field)) {
$f = $this->hasElement($field);
if (!$f) {
throw new Exception(['Field does not exist', 'model' => $this, 'field' => $field]);
}
} elseif ($field instanceof Field) {
$f = $field;
}
if ($f) {
$f->system = true;
if ($operator === '=' || func_num_args() == 2) {
$v = $operator === '=' ? $value : $operator;
if (!is_object($v) && !is_array($v)) {
$f->default = $v;
}
}
}
$this->conditions[] = func_get_args();
return $this;
}
public function testEditableAfterCondition() { $m = new Model(); $m->addField('name'); $m->addField('gender'); $m->addCondition('gender', 'M'); $this->assertEquals(true, $m->getElement('gender')->system); $this->assertEquals(false, $m->getElement('gender')->isEditable()); }