Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
e9e59483
Commit
e9e59483
authored
Apr 02, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed unnecessary code duplication
parent
c572c23c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
134 deletions
+52
-134
Query.php
extensions/sphinx/Query.php
+0
-58
Query.php
framework/db/Query.php
+0
-58
QueryTrait.php
framework/db/QueryTrait.php
+52
-18
No files found.
extensions/sphinx/Query.php
View file @
e9e59483
...
...
@@ -800,62 +800,4 @@ class Query extends Component implements QueryInterface
->
callSnippets
(
$from
,
$source
,
$match
,
$this
->
snippetOptions
)
->
queryColumn
();
}
/**
* Returns new condition with empty (null, empty string, blank string, or empty array) parameters removed
*
* @param array $condition original condition
* @return array condition with empty parameters removed
*/
protected
function
filterCondition
(
$condition
)
{
if
(
is_array
(
$condition
)
&&
isset
(
$condition
[
0
]))
{
$operator
=
strtoupper
(
$condition
[
0
]);
switch
(
$operator
)
{
case
'NOT'
:
case
'AND'
:
case
'OR'
:
for
(
$i
=
1
,
$operandsCount
=
count
(
$condition
);
$i
<
$operandsCount
;
$i
++
)
{
$subCondition
=
$this
->
filterCondition
(
$condition
[
$i
]);
if
(
$this
->
isParameterNotEmpty
(
$subCondition
))
{
$condition
[
$i
]
=
$subCondition
;
}
else
{
unset
(
$condition
[
$i
]);
}
}
$operandsCount
=
count
(
$condition
)
-
1
;
if
(
$operator
===
'NOT'
&&
$operandsCount
===
0
)
{
$condition
=
[];
}
else
{
// reindex array
array_splice
(
$condition
,
0
,
0
);
if
(
$operandsCount
===
1
)
{
$condition
=
$condition
[
1
];
}
}
break
;
case
'IN'
:
case
'NOT IN'
:
case
'LIKE'
:
case
'OR LIKE'
:
case
'NOT LIKE'
:
case
'OR NOT LIKE'
:
if
(
!
$this
->
isParameterNotEmpty
(
$condition
[
2
]))
{
$condition
=
[];
}
break
;
case
'BETWEEN'
:
case
'NOT BETWEEN'
:
if
(
!
$this
->
isParameterNotEmpty
(
$condition
[
2
])
&&
!
$this
->
isParameterNotEmpty
(
$condition
[
3
]))
{
$condition
=
[];
}
break
;
}
}
else
{
$condition
=
$this
->
filterHashCondition
(
$condition
);
}
return
$condition
;
}
}
framework/db/Query.php
View file @
e9e59483
...
...
@@ -888,62 +888,4 @@ class Query extends Component implements QueryInterface
return
$this
;
}
/**
* Returns new condition with empty (null, empty string, blank string, or empty array) parameters removed
*
* @param array $condition original condition
* @return array condition with empty parameters removed
*/
protected
function
filterCondition
(
$condition
)
{
if
(
is_array
(
$condition
)
&&
isset
(
$condition
[
0
]))
{
$operator
=
strtoupper
(
$condition
[
0
]);
switch
(
$operator
)
{
case
'NOT'
:
case
'AND'
:
case
'OR'
:
for
(
$i
=
1
,
$operandsCount
=
count
(
$condition
);
$i
<
$operandsCount
;
$i
++
)
{
$subCondition
=
$this
->
filterCondition
(
$condition
[
$i
]);
if
(
$this
->
isParameterNotEmpty
(
$subCondition
))
{
$condition
[
$i
]
=
$subCondition
;
}
else
{
unset
(
$condition
[
$i
]);
}
}
$operandsCount
=
count
(
$condition
)
-
1
;
if
(
$operator
===
'NOT'
&&
$operandsCount
===
0
)
{
$condition
=
[];
}
else
{
// reindex array
array_splice
(
$condition
,
0
,
0
);
if
(
$operandsCount
===
1
)
{
$condition
=
$condition
[
1
];
}
}
break
;
case
'IN'
:
case
'NOT IN'
:
case
'LIKE'
:
case
'OR LIKE'
:
case
'NOT LIKE'
:
case
'OR NOT LIKE'
:
if
(
!
$this
->
isParameterNotEmpty
(
$condition
[
2
]))
{
$condition
=
[];
}
break
;
case
'BETWEEN'
:
case
'NOT BETWEEN'
:
if
(
!
$this
->
isParameterNotEmpty
(
$condition
[
2
])
&&
!
$this
->
isParameterNotEmpty
(
$condition
[
3
]))
{
$condition
=
[];
}
break
;
}
}
else
{
$condition
=
$this
->
filterHashCondition
(
$condition
);
}
return
$condition
;
}
}
framework/db/QueryTrait.php
View file @
e9e59483
...
...
@@ -188,14 +188,63 @@ trait QueryTrait
*
* @param array $condition original condition
* @return array condition with [[isParameterNotEmpty|empty parameters]] removed.
* @throws NotSupportedException if the condition format is not supported
*/
protected
function
filterCondition
(
$condition
)
{
if
(
is_array
(
$condition
)
&&
!
isset
(
$condition
[
0
]))
{
return
$this
->
filterHashCondition
(
$condition
);
if
(
is_array
(
$condition
)
&&
isset
(
$condition
[
0
]))
{
$operator
=
strtoupper
(
$condition
[
0
]);
switch
(
$operator
)
{
case
'NOT'
:
case
'AND'
:
case
'OR'
:
for
(
$i
=
1
,
$operandsCount
=
count
(
$condition
);
$i
<
$operandsCount
;
$i
++
)
{
$subCondition
=
$this
->
filterCondition
(
$condition
[
$i
]);
if
(
$this
->
isParameterNotEmpty
(
$subCondition
))
{
$condition
[
$i
]
=
$subCondition
;
}
else
{
unset
(
$condition
[
$i
]);
}
}
$operandsCount
=
count
(
$condition
)
-
1
;
if
(
$operator
===
'NOT'
&&
$operandsCount
===
0
)
{
$condition
=
[];
}
else
{
// reindex array
array_splice
(
$condition
,
0
,
0
);
if
(
$operandsCount
===
1
)
{
$condition
=
$condition
[
1
];
}
}
break
;
case
'IN'
:
case
'NOT IN'
:
case
'LIKE'
:
case
'OR LIKE'
:
case
'NOT LIKE'
:
case
'OR NOT LIKE'
:
if
(
!
$this
->
isParameterNotEmpty
(
$condition
[
2
]))
{
$condition
=
[];
}
break
;
case
'BETWEEN'
:
case
'NOT BETWEEN'
:
if
(
!
$this
->
isParameterNotEmpty
(
$condition
[
2
])
&&
!
$this
->
isParameterNotEmpty
(
$condition
[
3
]))
{
$condition
=
[];
}
break
;
default
:
throw
new
NotSupportedException
(
"filterWhere() does not support the '
$operator
' operator."
);
}
}
elseif
(
is_array
(
$condition
))
{
// hash format: 'column1' => 'value1', 'column2' => 'value2', ...
return
array_filter
(
$condition
,
[
$this
,
'isParameterNotEmpty'
]);
}
else
{
throw
new
NotSupportedException
(
'filterWhere() only supports hash condition format.'
);
throw
new
NotSupportedException
(
"filterWhere() does not support plain string conditions use where() instead."
);
}
return
$condition
;
}
/**
...
...
@@ -220,21 +269,6 @@ trait QueryTrait
}
/**
* Returns a new hash condition without [[isParameterNotEmpty|empty parameters]].
*
* @param array $condition original condition
* @return array condition without [[isParameterNotEmpty|empty parameters]].
*/
protected
function
filterHashCondition
(
$condition
)
{
if
(
is_array
(
$condition
)
&&
!
isset
(
$condition
[
0
]))
{
// hash format: 'column1' => 'value1', 'column2' => 'value2', ...
return
array_filter
(
$condition
,
[
$this
,
'isParameterNotEmpty'
]);
}
return
$condition
;
}
/**
* Sets the ORDER BY part of the query.
* @param string|array $columns the columns (and the directions) to be ordered by.
* Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment