Skip to content
Snippets Groups Projects
Commit f40fd130 authored by Martynas Sudintas's avatar Martynas Sudintas
Browse files

Added sub aggregations setter in AbstractAggregation

parent 1d50c2a9
No related branches found
No related tags found
No related merge requests found
......@@ -24,17 +24,17 @@ abstract class AbstractAggregation implements NamedBuilderInterface
/**
* @var string
*/
protected $field;
private $field;
/**
* @var string
*/
protected $name;
private $name;
/**
* @var NamedBuilderBag
*/
public $aggregations;
private $aggregations;
/**
* @return string
......@@ -88,6 +88,26 @@ abstract class AbstractAggregation implements NamedBuilderInterface
return self::PREFIX . $this->name;
}
/**
* Adds a sub-aggregation.
*
* @param AbstractAggregation $abstractAggregation
*/
public function addAggregation(AbstractAggregation $abstractAggregation)
{
$this->aggregations->add($abstractAggregation);
}
/**
* Returns all sub aggregations.
*
* @return AbstractAggregation[]
*/
public function getAggregations()
{
return $this->aggregations->all();
}
/**
* {@inheritdoc}
*/
......@@ -114,8 +134,7 @@ abstract class AbstractAggregation implements NamedBuilderInterface
protected function collectNestedAggregations()
{
$result = [];
$nested = $this->aggregations->all();
foreach ($nested as $aggregation) {
foreach ($this->aggregations->all() as $aggregation) {
$result = array_merge($result, $aggregation->toArray());
}
......
......@@ -58,7 +58,7 @@ class NestedAggregation extends AbstractAggregation
*/
public function getArray()
{
if (count($this->aggregations) == 0) {
if (count($this->getAggregations()) == 0) {
throw new \LogicException("Nested aggregation `{$this->getName()}` has no aggregations added");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment