Using these two classes, getting aggregate values out of your models is a piece of cake!
To use them, simply create a ghost-getter method and annotate it as follows:
/**
* @FEATURE\Aggregate(property="entries", targetProperty="amount", function="SUM")
* @return float
*/
public function getBalance() {
return $this->balance;
}
I've used the example Entities for as mentioned in the Doctrine Blog: http://www.doctrine-project.org/blog/implementing-aggregate-fields (only modified it so it fits into FLOW3 and added this method)
Of course the $balance
field doesn't actually exist, but that doesn't matter since the method call is intercepted by the AggregateField aspect.
Now in your template, all you need to do to get the actual SUM of all entries' values is use the getter of the model instance as always:
<p>Balance: {account.balance -> f:format.currency(currencySign: '$')}</p>
Now I'm not yet sure if this is a rather huge performance gain or loss, so don't blame me. But at least you now have a very simple way of getting aggregates, right?