Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Data Class Reference
Inheritance diagram for Data:
AbstractHelper

Public Member Functions

 __construct (\Magento\Framework\App\Helper\Context $context, \Magento\Reports\Model\ItemFactory $itemFactory)
 
 getIntervals ($from, $to, $period=self::REPORT_PERIOD_TYPE_DAY)
 
 prepareIntervalsCollection ($collection, $from, $to, $periodType=self::REPORT_PERIOD_TYPE_DAY)
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Data Fields

const REPORT_PERIOD_TYPE_DAY = 'day'
 
const REPORT_PERIOD_TYPE_MONTH = 'month'
 
const REPORT_PERIOD_TYPE_YEAR = 'year'
 

Protected Attributes

 $_itemFactory
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Detailed Description

@api

Since
100.0.2

Definition at line 19 of file Data.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Helper\Context  $context,
\Magento\Reports\Model\ItemFactory  $itemFactory 
)

Constructor

Parameters
\Magento\Framework\App\Helper\Context$context
\Magento\Reports\Model\ItemFactory$itemFactory

Definition at line 40 of file Data.php.

43  {
44  parent::__construct($context);
45  $this->_itemFactory = $itemFactory;
46  }

Member Function Documentation

◆ getIntervals()

getIntervals (   $from,
  $to,
  $period = self::REPORT_PERIOD_TYPE_DAY 
)

Retrieve array of intervals

Parameters
string$from
string$to
string$period
Returns
array @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 57 of file Data.php.

58  {
59  $intervals = [];
60  if (!$from && !$to) {
61  return $intervals;
62  }
63 
64  $dateStart = new \DateTime($from);
65  $dateEnd = new \DateTime($to);
66  while ($dateStart->diff($dateEnd)->invert == 0) {
67  switch ($period) {
69  $intervals[] = $dateStart->format('Y-m-d');
70  $dateStart->add(new \DateInterval('P1D'));
71  break;
73  $intervals[] = $dateStart->format('Y-m');
74  $dateStart->add(new \DateInterval('P1M'));
75  break;
77  $intervals[] = $dateStart->format('Y');
78  $dateStart->add(new \DateInterval('P1Y'));
79  break;
80  }
81  }
82  return $intervals;
83  }
const REPORT_PERIOD_TYPE_MONTH
Definition: Data.php:23

◆ prepareIntervalsCollection()

prepareIntervalsCollection (   $collection,
  $from,
  $to,
  $periodType = self::REPORT_PERIOD_TYPE_DAY 
)

Add items to interval collection

Parameters
Collection$collection
string$from
string$to
string$periodType
Returns
void

Definition at line 94 of file Data.php.

95  {
96  $intervals = $this->getIntervals($from, $to, $periodType);
97 
98  foreach ($intervals as $interval) {
99  $item = $this->_itemFactory->create();
100  $item->setPeriod($interval);
101  $item->setIsEmpty();
102  $collection->addItem($item);
103  }
104  }
getIntervals($from, $to, $period=self::REPORT_PERIOD_TYPE_DAY)
Definition: Data.php:57

Field Documentation

◆ $_itemFactory

$_itemFactory
protected

Definition at line 32 of file Data.php.

◆ REPORT_PERIOD_TYPE_DAY

const REPORT_PERIOD_TYPE_DAY = 'day'

Definition at line 21 of file Data.php.

◆ REPORT_PERIOD_TYPE_MONTH

const REPORT_PERIOD_TYPE_MONTH = 'month'

Definition at line 23 of file Data.php.

◆ REPORT_PERIOD_TYPE_YEAR

const REPORT_PERIOD_TYPE_YEAR = 'year'

Definition at line 25 of file Data.php.


The documentation for this class was generated from the following file: