/** * When called with data, some identification key and an aggregation container, the function should attempt to resolve * some kind of aggregation and store the result to the aggregation container. * * The aggregation may require many values to work out it's result or provide multiple results, this is why an * aggregation container is used to store the different aggregated value. Normally, this aggregation container is the * groupResult object but it could be something else in other cases. * * @param AggregationValueContainerInterface $container Container which implements aggregation data containment facilities * @param mixed $data Data to be used in the grouping operation * @param mixed $key Identification key to be used in the grouping operation * * @access public */ function aggregate(AggregationValueContainerInterface $container, $data, $key) { //If the value doesn't exist, just create it with a 1 if ($container->hasAggregationValue($this->getName()) == false) { $container->addAggregationValue(1, $this->getName()); return; } //Increment the value $container->setAggregationValue($container->getAggregationValue($this->getName()) + 1, $this->getName()); }
/** * When called with data, some identification key and an aggregation container, the function should attempt to resolve * some kind of aggregation and store the result to the aggregation container. * * The aggregation may require many values to work out it's result or provide multiple results, this is why an * aggregation container is used to store the different aggregated value. Normally, this aggregation container is the * groupResult object but it could be something else in other cases. * * @param AggregationValueContainerInterface $container Container which implements aggregation data containment facilities * @param mixed $data Data to be used in the grouping operation * @param mixed $key Identification key to be used in the grouping operation * * @access public */ function aggregate(AggregationValueContainerInterface $container, $data, $key) { //If the value doesn't exist, just create it with a if ($container->hasAggregationValue($this->getName()) == false) { $container->addAggregationValue(0, $this->getName()); } //Call the closure $closure = $this->getClosure(); $closure_value = $closure($data, $key); //Increment the sum $container->setAggregationValue($container->getAggregationValue($this->getName()) + $closure_value, $this->getName()); }
/** * When called with data, some identification key and an aggregation container, the function should attempt to resolve * some kind of aggregation and store the result to the aggregation container. * * The aggregation may require many values to work out it's result or provide multiple results, this is why an * aggregation container is used to store the different aggregated value. Normally, this aggregation container is the * groupResult object but it could be something else in other cases. * * @param AggregationValueContainerInterface $container Container which implements aggregation data containment facilities * @param mixed $data Data to be used in the grouping operation * @param mixed $key Identification key to be used in the grouping operation * * @access public */ function aggregate(AggregationValueContainerInterface $container, $data, $key) { //Call the closure $closure = $this->getClosure(); $closure_value = $closure($data, $key); //If the value doesn't exist, just create it with a default value if ($container->hasAggregationValue($this->getName()) == false) { $container->addAggregationValue($closure_value, $this->getName()); } else { $current_value = $container->getAggregationValue($this->getName()); $container->setAggregationValue($current_value > $closure_value ? $current_value : $closure_value, $this->getName()); } }