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
06fdb797
Commit
06fdb797
authored
Mar 31, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for arbitrary number of parameters for NOT, AND, OR in filter methods of Query
parent
94fd4e7e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
14 deletions
+32
-14
Query.php
extensions/sphinx/Query.php
+15
-2
Query.php
framework/db/Query.php
+15
-2
QueryTest.php
tests/unit/extensions/sphinx/QueryTest.php
+1
-5
QueryTest.php
tests/unit/framework/db/QueryTest.php
+1
-5
No files found.
extensions/sphinx/Query.php
View file @
06fdb797
...
...
@@ -822,11 +822,24 @@ class Query extends Component implements QueryInterface
case
'NOT'
:
case
'AND'
:
case
'OR'
:
$subCondition
=
$this
->
filterCondition
(
$condition
[
1
]);
for
(
$i
=
1
,
$operandsCount
=
count
(
$condition
);
$i
<
$operandsCount
;
$i
++
)
{
$subCondition
=
$this
->
filterCondition
(
$condition
[
$i
]);
if
(
$this
->
parameterNotEmpty
(
$subCondition
))
{
$condition
[
1
]
=
$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'
:
...
...
framework/db/Query.php
View file @
06fdb797
...
...
@@ -909,11 +909,24 @@ class Query extends Component implements QueryInterface
case
'NOT'
:
case
'AND'
:
case
'OR'
:
$subCondition
=
$this
->
filterCondition
(
$condition
[
1
]);
for
(
$i
=
1
,
$operandsCount
=
count
(
$condition
);
$i
<
$operandsCount
;
$i
++
)
{
$subCondition
=
$this
->
filterCondition
(
$condition
[
$i
]);
if
(
$this
->
parameterNotEmpty
(
$subCondition
))
{
$condition
[
1
]
=
$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'
:
...
...
tests/unit/extensions/sphinx/QueryTest.php
View file @
06fdb797
...
...
@@ -120,11 +120,7 @@ class QueryTest extends SphinxTestCase
public
function
testFilterRecursively
()
{
$query
=
new
Query
();
$query
->
filter
([
'not'
,
[
'like'
,
'name'
,
''
]]);
$this
->
assertEquals
(
null
,
$query
->
where
);
$query
->
where
([
'id'
=>
1
]);
$query
->
filter
([
'and'
,
[
'like'
,
'name'
,
''
]]);
$query
->
filter
([
'and'
,
[
'like'
,
'name'
,
''
],
[
'like'
,
'title'
,
''
],
[
'id'
=>
1
],
[
'not'
,
[
'like'
,
'name'
,
''
]]]);
$this
->
assertEquals
([
'id'
=>
1
],
$query
->
where
);
}
...
...
tests/unit/framework/db/QueryTest.php
View file @
06fdb797
...
...
@@ -109,11 +109,7 @@ class QueryTest extends DatabaseTestCase
public
function
testFilterRecursively
()
{
$query
=
new
Query
();
$query
->
filter
([
'not'
,
[
'like'
,
'name'
,
''
]]);
$this
->
assertEquals
(
null
,
$query
->
where
);
$query
->
where
([
'id'
=>
1
]);
$query
->
filter
([
'and'
,
[
'like'
,
'name'
,
''
]]);
$query
->
filter
([
'and'
,
[
'like'
,
'name'
,
''
],
[
'like'
,
'title'
,
''
],
[
'id'
=>
1
],
[
'not'
,
[
'like'
,
'name'
,
''
]]]);
$this
->
assertEquals
([
'id'
=>
1
],
$query
->
where
);
}
...
...
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