Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Auto.php
Go to the documentation of this file.
1 <?php
7 
13 
14 class Auto implements AlgorithmInterface
15 {
19  private $dataProvider;
20 
24  private $options;
25 
30  public function __construct(DataProviderInterface $dataProvider, OptionsInterface $options)
31  {
32  $this->dataProvider = $dataProvider;
33  $this->options = $options;
34  }
35 
39  public function getItems(
40  BucketInterface $bucket,
41  array $dimensions,
42  EntityStorage $entityStorage
43  ) {
44  $data = [];
45  $range = $this->dataProvider->getRange();
46  if ($entityStorage->getSource()) {
47  $range = !empty($range) ? $range : $this->getRange($bucket, $dimensions, $entityStorage);
48  $dbRanges = $this->dataProvider->getAggregation($bucket, $dimensions, $range, $entityStorage);
49  $data = $this->dataProvider->prepareData($range, $dbRanges);
50  }
51 
52  return $data;
53  }
54 
61  private function getRange($bucket, array $dimensions, EntityStorage $entityStorage)
62  {
63  $maxPrice = $this->getMaxPriceInt($entityStorage);
64  $index = 1;
65  do {
66  $range = pow(10, strlen(floor($maxPrice)) - $index);
67  $items = $this->dataProvider->getAggregation($bucket, $dimensions, $range, $entityStorage);
68  $index++;
69  } while ($range > $this->getMinRangePower() && count($items) < 2);
70 
71  return $range;
72  }
73 
80  private function getMaxPriceInt(EntityStorage $entityStorage)
81  {
82  $aggregations = $this->dataProvider->getAggregations($entityStorage);
83  $maxPrice = $aggregations['max'];
84  $maxPrice = floor($maxPrice);
85 
86  return $maxPrice;
87  }
88 
92  private function getMinRangePower()
93  {
94  $options = $this->options->get();
95 
96  return $options['min_range_power'];
97  }
98 }
getItems(BucketInterface $bucket, array $dimensions, EntityStorage $entityStorage)
Definition: Auto.php:39
$index
Definition: list.phtml:44
__construct(DataProviderInterface $dataProvider, OptionsInterface $options)
Definition: Auto.php:30
$items