public function buildLikeCondition($indexes, $operator, $operands, &$params)
{
if (!isset($operands[0], $operands[1])) {
throw new InvalidParamException("Operator '{$operator}' requires two operands.");
}
$escape = isset($operands[2]) ? $operands[2] : ['%' => '\\%', '_' => '\\_', '\\' => '\\\\'];
unset($operands[2]);
list($column, $values) = $operands;
if (!is_array($values)) {
$values = [$values];
}
if (empty($values)) {
return $operator === 'LIKE' || $operator === 'OR LIKE' ? '0=1' : '';
}
if ($operator === 'LIKE' || $operator === 'NOT LIKE') {
$andor = ' AND ';
} else {
$andor = ' OR ';
$operator = $operator === 'OR LIKE' ? 'LIKE' : 'NOT LIKE';
}
if (strpos($column, '(') === false) {
$column = $this->db->quoteColumnName($column);
}
$parts = [];
foreach ($values as $value) {
if ($value instanceof Expression) {
foreach ($value->params as $n => $v) {
$params[$n] = $v;
}
$phName = $value->expression;
} else {
$phName = self::PARAM_PREFIX . count($params);
$params[$phName] = empty($escape) ? $value : '%' . strtr($value, $escape) . '%';
}
$parts[] = "{$column} {$operator} {$phName}";
}
return implode($andor, $parts);
}