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
a9286b89
Commit
a9286b89
authored
Jan 23, 2014
by
Ivan Pomortsev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update QueryBuilder.php
Change <code>array_reduce</code> with anonimous function variant to easy string collection from pieces of unions.
parent
c9c59bdc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
22 deletions
+9
-22
QueryBuilder.php
framework/db/QueryBuilder.php
+9
-22
No files found.
framework/db/QueryBuilder.php
View file @
a9286b89
...
@@ -740,35 +740,22 @@ class QueryBuilder extends \yii\base\Object
...
@@ -740,35 +740,22 @@ class QueryBuilder extends \yii\base\Object
return
''
;
return
''
;
}
}
/**
$result
=
''
;
* @param Query $left left element of reducing pair
* @param Query $right right element of reducing pair
* @return string imploding pair with "UNION ALL" if
* right element is array and "UNION" if not
*/
$reducer
=
function
(
$left
,
$right
)
{
if
(
is_array
(
$left
))
$left
=
$left
[
'query'
];
$all
=
false
;
if
(
is_array
(
$right
))
{
$all
=
$right
[
'all'
];
$right
=
$right
[
'query'
];
}
return
$left
.
' UNION '
.
(
$all
?
'ALL '
:
''
)
.
'( '
.
$right
.
' )'
;
};
foreach
(
$unions
as
$i
=>
$union
)
{
foreach
(
$unions
as
$i
=>
$union
)
{
if
(
$union
instanceof
Query
)
{
$query
=
$union
[
'query'
];
if
(
$query
instanceof
Query
)
{
// save the original parameters so that we can restore them later to prevent from modifying the query object
// save the original parameters so that we can restore them later to prevent from modifying the query object
$originalParams
=
$
union
->
params
;
$originalParams
=
$
query
->
params
;
$
union
->
addParams
(
$params
);
$
query
->
addParams
(
$params
);
list
(
$unions
[
$i
][
'query'
],
$params
)
=
$this
->
build
(
$query
);
list
(
$unions
[
$i
][
'query'
],
$params
)
=
$this
->
build
(
$query
);
$
union
->
params
=
$originalParams
;
$
query
->
params
=
$originalParams
;
}
}
$result
.=
'UNION '
.
(
$union
[
'all'
]
?
'ALL '
:
''
)
.
'( '
.
$unions
[
$i
][
'query'
]
.
' ) '
;
}
}
return
trim
(
array_reduce
(
$unions
,
$reducer
)
);
return
trim
(
$result
);
}
}
/**
/**
...
...
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