Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AggregationFactory.php
Go to the documentation of this file.
1 <?php
7 
9 
16 {
23  protected $objectManager;
24 
29  {
30  $this->objectManager = $objectManager;
31  }
32 
40  public function create(array $rawAggregation)
41  {
42  $buckets = [];
43  foreach ($rawAggregation as $rawBucketName => $rawBucket) {
45  $buckets[$rawBucketName] = $this->objectManager->create(
46  \Magento\Framework\Search\Response\Bucket::class,
47  [
48  'name' => $rawBucketName,
49  'values' => $this->prepareValues($rawBucket)
50  ]
51  );
52  }
53  return $this->objectManager->create(
54  \Magento\Framework\Search\Response\Aggregation::class,
55  ['buckets' => $buckets]
56  );
57  }
58 
65  private function prepareValues(array $values)
66  {
67  $valuesObjects = [];
68  foreach ($values as $name => $value) {
69  $valuesObjects[] = $this->objectManager->create(
70  \Magento\Framework\Search\Response\Aggregation\Value::class,
71  [
72  'value' => $name,
73  'metrics' => $value,
74  ]
75  );
76  }
77  return $valuesObjects;
78  }
79 }
__construct(ObjectManagerInterface $objectManager)
$values
Definition: options.phtml:88
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14