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
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
18 deletions
+36
-18
Query.php
extensions/sphinx/Query.php
+17
-4
Query.php
framework/db/Query.php
+17
-4
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
...
@@ -822,11 +822,24 @@ class Query extends Component implements QueryInterface
case
'NOT'
:
case
'NOT'
:
case
'AND'
:
case
'AND'
:
case
'OR'
:
case
'OR'
:
$subCondition
=
$this
->
filterCondition
(
$condition
[
1
]);
for
(
$i
=
1
,
$operandsCount
=
count
(
$condition
);
$i
<
$operandsCount
;
$i
++
)
{
if
(
$this
->
parameterNotEmpty
(
$subCondition
))
{
$subCondition
=
$this
->
filterCondition
(
$condition
[
$i
]);
$condition
[
1
]
=
$subCondition
;
if
(
$this
->
parameterNotEmpty
(
$subCondition
))
{
}
else
{
$condition
[
$i
]
=
$subCondition
;
}
else
{
unset
(
$condition
[
$i
]);
}
}
$operandsCount
=
count
(
$condition
)
-
1
;
if
(
$operator
===
'NOT'
&&
$operandsCount
===
0
)
{
$condition
=
[];
$condition
=
[];
}
else
{
// reindex array
array_splice
(
$condition
,
0
,
0
);
if
(
$operandsCount
===
1
)
{
$condition
=
$condition
[
1
];
}
}
}
break
;
break
;
case
'IN'
:
case
'IN'
:
...
...
framework/db/Query.php
View file @
06fdb797
...
@@ -909,11 +909,24 @@ class Query extends Component implements QueryInterface
...
@@ -909,11 +909,24 @@ class Query extends Component implements QueryInterface
case
'NOT'
:
case
'NOT'
:
case
'AND'
:
case
'AND'
:
case
'OR'
:
case
'OR'
:
$subCondition
=
$this
->
filterCondition
(
$condition
[
1
]);
for
(
$i
=
1
,
$operandsCount
=
count
(
$condition
);
$i
<
$operandsCount
;
$i
++
)
{
if
(
$this
->
parameterNotEmpty
(
$subCondition
))
{
$subCondition
=
$this
->
filterCondition
(
$condition
[
$i
]);
$condition
[
1
]
=
$subCondition
;
if
(
$this
->
parameterNotEmpty
(
$subCondition
))
{
}
else
{
$condition
[
$i
]
=
$subCondition
;
}
else
{
unset
(
$condition
[
$i
]);
}
}
$operandsCount
=
count
(
$condition
)
-
1
;
if
(
$operator
===
'NOT'
&&
$operandsCount
===
0
)
{
$condition
=
[];
$condition
=
[];
}
else
{
// reindex array
array_splice
(
$condition
,
0
,
0
);
if
(
$operandsCount
===
1
)
{
$condition
=
$condition
[
1
];
}
}
}
break
;
break
;
case
'IN'
:
case
'IN'
:
...
...
tests/unit/extensions/sphinx/QueryTest.php
View file @
06fdb797
...
@@ -120,11 +120,7 @@ class QueryTest extends SphinxTestCase
...
@@ -120,11 +120,7 @@ class QueryTest extends SphinxTestCase
public
function
testFilterRecursively
()
public
function
testFilterRecursively
()
{
{
$query
=
new
Query
();
$query
=
new
Query
();
$query
->
filter
([
'not'
,
[
'like'
,
'name'
,
''
]]);
$query
->
filter
([
'and'
,
[
'like'
,
'name'
,
''
],
[
'like'
,
'title'
,
''
],
[
'id'
=>
1
],
[
'not'
,
[
'like'
,
'name'
,
''
]]]);
$this
->
assertEquals
(
null
,
$query
->
where
);
$query
->
where
([
'id'
=>
1
]);
$query
->
filter
([
'and'
,
[
'like'
,
'name'
,
''
]]);
$this
->
assertEquals
([
'id'
=>
1
],
$query
->
where
);
$this
->
assertEquals
([
'id'
=>
1
],
$query
->
where
);
}
}
...
...
tests/unit/framework/db/QueryTest.php
View file @
06fdb797
...
@@ -109,11 +109,7 @@ class QueryTest extends DatabaseTestCase
...
@@ -109,11 +109,7 @@ class QueryTest extends DatabaseTestCase
public
function
testFilterRecursively
()
public
function
testFilterRecursively
()
{
{
$query
=
new
Query
();
$query
=
new
Query
();
$query
->
filter
([
'not'
,
[
'like'
,
'name'
,
''
]]);
$query
->
filter
([
'and'
,
[
'like'
,
'name'
,
''
],
[
'like'
,
'title'
,
''
],
[
'id'
=>
1
],
[
'not'
,
[
'like'
,
'name'
,
''
]]]);
$this
->
assertEquals
(
null
,
$query
->
where
);
$query
->
where
([
'id'
=>
1
]);
$query
->
filter
([
'and'
,
[
'like'
,
'name'
,
''
]]);
$this
->
assertEquals
([
'id'
=>
1
],
$query
->
where
);
$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