20 private $conditionMap = [
21 'eq' =>
'%1$s = %2$s',
22 'neq' =>
'%1$s != %2$s',
23 'like' =>
'%1$s LIKE %2$s',
24 'nlike' =>
'%1$s NOT LIKE %2$s',
25 'in' =>
'%1$s IN(%2$s)',
26 'nin' =>
'%1$s NOT IN(%2$s)',
27 'notnull' =>
'%1$s IS NOT NULL',
28 'null' =>
'%1$s IS NULL',
29 'gt' =>
'%1$s > %2$s',
30 'lt' =>
'%1$s < %2$s',
31 'gteq' =>
'%1$s >= %2$s',
32 'lteq' =>
'%1$s <= %2$s',
33 'finset' =>
'FIND_IN_SET(%2$s, %1$s)' 44 private $resourceConnection;
61 private function getConnection()
63 if (!$this->connection) {
64 $this->connection = $this->resourceConnection->getConnection();
66 return $this->connection;
76 private function getValue($condition, $referencedEntity)
79 $argument = isset($condition[
'_value']) ? $condition[
'_value'] :
null;
80 if (!isset($condition[
'type'])) {
81 $condition[
'type'] =
'value';
84 switch ($condition[
'type']) {
86 $value = $this->getConnection()->quote($argument);
89 $value =
new Expression($argument);
92 $value = $this->getConnection()->quoteIdentifier(
93 $referencedEntity ? $referencedEntity .
'.' . $argument : $argument
109 private function getCondition(SelectBuilder $selectBuilder,
$tableName, $condition, $referencedEntity =
null)
111 $columns = $selectBuilder->getColumns();
112 if (isset(
$columns[$condition[
'attribute']])
113 &&
$columns[$condition[
'attribute']] instanceof Expression
115 $expression =
$columns[$condition[
'attribute']];
117 $expression = $this->getConnection()->quoteIdentifier(
$tableName .
'.' . $condition[
'attribute']);
120 $this->conditionMap[$condition[
'operator']],
122 $this->getValue($condition, $referencedEntity)
138 foreach ($filterConfig as $filter) {
139 $glue = $filter[
'glue'];
141 foreach ($filter[
'condition'] as $condition) {
142 if (isset($condition[
'type']) && $condition[
'type'] ==
'variable') {
143 $selectBuilder->
setParams(array_merge($selectBuilder->
getParams(), [$condition[
'_value']]));
145 $parts[] = $this->getCondition(
152 if (isset($filter[
'filter'])) {
160 $filtersParts[] =
'(' . implode(
' ' . strtoupper($glue) .
' ', $parts) .
')';
162 return implode(
' OR ', $filtersParts);
getFilter(SelectBuilder $selectBuilder, $filterConfig, $aliasName, $referencedAlias=null)
__construct(ResourceConnection $resourceConnection)