protected function Condition::translateCondition in MongoDB 8
1 call to Condition::translateCondition()
- Condition::compile in src/
Entity/ Condition.php - Compiles this conditional clause.
File
- src/
Entity/ Condition.php, line 121 - Contains Drupal\mongodb\Entity\ContentEntityStorage.
Class
Namespace
Drupal\mongodb\EntityCode
protected function translateCondition(array $condition, $type) {
$value = MongoCollectionFactory::castValue($type, $condition['value']);
$operator = $condition['operator'];
if ($operator[0] === '$') {
return array(
$operator => $value,
);
}
switch ($operator) {
case '=':
return array(
'$eq' => $value,
);
case 'IN':
return array(
'$in' => $value,
);
case 'NOT IN':
return array(
'$nin' => $value,
);
case '<':
return array(
'$lt' => $value,
);
case '>':
return array(
'$gt' => $value,
);
case '<=':
return array(
'$lte' => $value,
);
case '>=':
return array(
'$gte' => $value,
);
case '!=':
case '<>':
return array(
'$ne' => $value,
);
case 'STARTS_WITH':
return new \MongoRegex('/^' . preg_quote($value, '/') . '/');
case 'CONTAINS':
return new \MongoRegex('/' . preg_quote($value, '/') . '/i');
case 'ENDS_WITH':
return new \MongoRegex('/' . preg_quote($value, '/') . '/$i');
case 'BETWEEN':
return array(
'$gte' => $value[0],
'$lte' => $value[1],
);
default:
throw new QueryException(String::format('@operator not implemented', array(
'@operator' => $operator,
)));
}
}