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
e3c281f3
Commit
e3c281f3
authored
Dec 03, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mongo Collection "aggregate" method interface refactored.
parent
a3f5236e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
9 deletions
+17
-9
Collection.php
extensions/mongo/Collection.php
+15
-7
Query.php
extensions/mongo/Query.php
+2
-2
No files found.
extensions/mongo/Collection.php
View file @
e3c281f3
...
...
@@ -349,19 +349,27 @@ class Collection extends Object
/**
* Performs aggregation using Mongo Aggregation Framework.
* @param array $pipeline list of pipeline operators, or just the first operator
* @param array $pipelineOperator Additional pipeline operators
* @param array $pipelineOperator additional pipeline operator. You can specify additional
* pipelines via third argument, fourth argument etc.
* @return array the result of the aggregation.
* @throws Exception on failure.
* @see http://docs.mongodb.org/manual/applications/aggregation/
*/
public
function
aggregate
(
$pipeline
,
$pipelineOperator
=
[])
{
$token
=
'Aggregating from '
.
$this
->
getFullName
();
Yii
::
info
(
$token
,
__METHOD__
);
Yii
::
beginProfile
(
$token
,
__METHOD__
);
$args
=
func_get_args
();
$result
=
call_user_func_array
([
$this
->
mongoCollection
,
'aggregate'
],
$args
);
Yii
::
endProfile
(
$token
,
__METHOD__
);
return
$result
;
try
{
Yii
::
beginProfile
(
$token
,
__METHOD__
);
$args
=
func_get_args
();
$result
=
call_user_func_array
([
$this
->
mongoCollection
,
'aggregate'
],
$args
);
$this
->
tryResultError
(
$result
);
Yii
::
endProfile
(
$token
,
__METHOD__
);
return
$result
[
'result'
];
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
__METHOD__
);
throw
new
Exception
(
$e
->
getMessage
(),
(
int
)
$e
->
getCode
(),
$e
);
}
}
/**
...
...
@@ -377,8 +385,8 @@ class Collection extends Object
* - condition - criteria for including a document in the aggregation.
* - finalize - function called once per unique key that takes the final output of the reduce function.
* @return array the result of the aggregation.
* @see http://docs.mongodb.org/manual/reference/command/group/
* @throws Exception on failure.
* @see http://docs.mongodb.org/manual/reference/command/group/
*/
public
function
group
(
$keys
,
$initial
,
$reduce
,
$options
=
[])
{
...
...
extensions/mongo/Query.php
View file @
e3c281f3
...
...
@@ -244,8 +244,8 @@ class Query extends Component implements QueryInterface
]
];
$result
=
$collection
->
aggregate
(
$pipelines
);
if
(
!
empty
(
$result
[
'ok'
]
))
{
return
$result
[
'result'
][
0
][
'total'
];
if
(
array_key_exists
(
0
,
$result
))
{
return
$result
[
0
][
'total'
];
}
else
{
return
0
;
}
...
...
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