Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Manual.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class Manual implements AlgorithmInterface
14 {
18  private $dataProvider;
19 
23  private $options;
24 
29  public function __construct(DataProviderInterface $dataProvider, OptionsInterface $options)
30  {
31  $this->dataProvider = $dataProvider;
32  $this->options = $options;
33  }
34 
38  public function getItems(
39  BucketInterface $bucket,
40  array $dimensions,
41  EntityStorage $entityStorage
42  ) {
43  $range = $this->dataProvider->getRange();
44  $options = $this->options->get();
45  if (!$range) {
46  $range = $options['range_step'];
47  }
48  $dbRanges = $this->dataProvider->getAggregation($bucket, $dimensions, $range, $entityStorage);
49  $dbRanges = $this->processRange($dbRanges, $options['max_intervals_number']);
50  $data = $this->dataProvider->prepareData($range, $dbRanges);
51 
52  return $data;
53  }
54 
60  private function processRange($items, $maxIntervalsNumber)
61  {
62  $i = 0;
63  $lastIndex = null;
64  foreach ($items as $k => $v) {
65  ++$i;
66  if ($i > 1 && $i > $maxIntervalsNumber) {
67  $items[$lastIndex] += $v;
68  unset($items[$k]);
69  } else {
70  $lastIndex = $k;
71  }
72  }
73 
74  return $items;
75  }
76 }
getItems(BucketInterface $bucket, array $dimensions, EntityStorage $entityStorage)
Definition: Manual.php:38
$i
Definition: gallery.phtml:31
__construct(DataProviderInterface $dataProvider, OptionsInterface $options)
Definition: Manual.php:29
$items