protected function _processConditions($key, $value, $context, $schema = null, $glue = 'AND')
{
$constraintTypes =& $this->_constraintTypes;
$model = $context->model();
$models = $context->models();
list($first, $second) = $this->_splitFieldname($key);
if ($first && isset($models[$first]) && ($class = $models[$first])) {
$schema = $class::schema();
} elseif ($model) {
$schema = $model::schema();
}
$fieldMeta = $schema ? (array) $schema->fields($second) : array();
switch (true) {
case is_numeric($key) && is_string($value):
return $value;
case is_object($value) && isset($value->scalar):
if (is_numeric($key)) {
return $this->value($value);
}
case is_scalar($value) || $value === null:
if ($context && $context->type() === 'read' && ($alias = $context->alias())) {
$key = $this->_aliasing($key, $alias);
}
if (isset($value)) {
return $this->name($key) . ' = ' . $this->value($value, $fieldMeta);
}
return $this->name($key) . ' IS NULL';
case is_numeric($key) && is_array($value):
$result = array();
foreach ($value as $cKey => $cValue) {
$result[] = $this->_processConditions($cKey, $cValue, $context, $schema, $glue);
}
return '(' . implode(' ' . $glue . ' ', $result) . ')';
case is_string($key) && is_object($value):
$value = trim(rtrim($this->renderCommand($value), ';'));
return "{$this->name($key)} IN ({$value})";
case is_array($value) && isset($constraintTypes[strtoupper($key)]):
$result = array();
$glue = strtoupper($key);
foreach ($value as $cKey => $cValue) {
$result[] = $this->_processConditions($cKey, $cValue, $context, $schema, $glue);
}
return '(' . implode(' ' . $glue . ' ', $result) . ')';
case $result = $this->_processOperator($key, $value, $fieldMeta, $glue):
return $result;
case is_array($value):
$value = join(', ', $this->value($value, $fieldMeta));
return "{$this->name($key)} IN ({$value})";
}
}