Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
LeanMapper Workflow
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Mpro
LeanMapper Workflow
Commits
d909a9cb
Commit
d909a9cb
authored
May 27, 2014
by
Tomas Lang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Entity: getCountOf* method
parent
1d867a92
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
Entity.php
src/LeanMapperWorkflow/Entity.php
+40
-0
No files found.
src/LeanMapperWorkflow/Entity.php
View file @
d909a9cb
...
...
@@ -2,7 +2,47 @@
namespace
LeanMapperWorkflow
;
use
LeanMapper\Relationship\HasMany
;
use
LeanMapper\Filtering
;
use
LeanMapper\Fluent
;
abstract
class
Entity
extends
\LeanMapper\Entity
{
/**
* @param string $name
* @param array $arguments
*/
public
function
__call
(
$name
,
array
$arguments
)
{
if
(
substr
(
$name
,
0
,
10
)
===
'getCountOf'
)
{
$property
=
$this
->
getCurrentReflection
()
->
getEntityProperty
(
lcfirst
(
substr
(
$name
,
10
)));
if
(
$property
->
containsCollection
())
{
$relationship
=
$property
->
getRelationship
();
$table
=
$relationship
instanceof
HasMany
?
$relationship
->
getRelationshipTable
()
:
$relationship
->
getTargetTable
();
$column
=
$relationship
->
getColumnReferencingSourceTable
();
$filters
=
array
(
'counter'
);
$propertyFilters
=
$property
->
getFilters
();
if
(
$propertyFilters
!==
NULL
)
{
$filters
=
array_merge
(
$filters
,
$propertyFilters
);
}
$filtering
=
new
Filtering
(
function
(
Fluent
$statement
)
use
(
$column
)
{
$statement
->
removeClause
(
'select'
)
->
select
(
'COUNT(*) [count], %n'
,
$column
)
->
groupBy
(
$column
);
});
$rows
=
$this
->
row
->
referencing
(
$table
,
$column
,
$filtering
);
return
empty
(
$rows
)
?
0
:
$rows
[
0
]
->
count
;
}
}
return
parent
::
__call
(
$name
,
$arguments
);
}
}
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