Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Collection.php
Go to the documentation of this file.
1 <?php
13 
19 {
23  protected $_localeDate;
24 
29 
35  public function __construct(
36  \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
37  \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
38  \Magento\Reports\Model\FlagFactory $reportsFlagFactory
39  ) {
40  parent::__construct($entityFactory);
41  $this->_localeDate = $localeDate;
42  $this->_reportsFlagFactory = $reportsFlagFactory;
43  }
44 
51  protected function _getUpdatedAt($reportCode)
52  {
53  $flag = $this->_reportsFlagFactory->create()->setReportFlagCode($reportCode)->loadSelf();
54  return $flag->hasData() ? $flag->getLastUpdate() : '';
55  }
56 
65  public function loadData($printQuery = false, $logQuery = false)
66  {
67  if (!count($this->_items)) {
68  $data = [
69  [
70  'id' => 'sales',
71  'report' => __('Orders'),
72  'comment' => __('Total Ordered Report'),
73  'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_ORDER_FLAG_CODE),
74  ],
75  [
76  'id' => 'tax',
77  'report' => __('Tax'),
78  'comment' => __('Order Taxes Report Grouped by Tax Rates'),
79  'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_TAX_FLAG_CODE)
80  ],
81  [
82  'id' => 'shipping',
83  'report' => __('Shipping'),
84  'comment' => __('Total Shipped Report'),
85  'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_SHIPPING_FLAG_CODE)
86  ],
87  [
88  'id' => 'invoiced',
89  'report' => __('Total Invoiced'),
90  'comment' => __('Total Invoiced VS Paid Report'),
91  'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_INVOICE_FLAG_CODE)
92  ],
93  [
94  'id' => 'refunded',
95  'report' => __('Total Refunded'),
96  'comment' => __('Total Refunded Report'),
97  'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_REFUNDED_FLAG_CODE)
98  ],
99  [
100  'id' => 'coupons',
101  'report' => __('Coupons'),
102  'comment' => __('Promotion Coupons Usage Report'),
103  'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_COUPONS_FLAG_CODE)
104  ],
105  [
106  'id' => 'bestsellers',
107  'report' => __('Bestsellers'),
108  'comment' => __('Products Bestsellers Report'),
109  'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_BESTSELLERS_FLAG_CODE)
110  ],
111  [
112  'id' => 'viewed',
113  'report' => __('Most Viewed'),
114  'comment' => __('Most Viewed Products Report'),
115  'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_PRODUCT_VIEWED_FLAG_CODE)
116  ],
117  ];
118  foreach ($data as $value) {
119  $item = new \Magento\Framework\DataObject();
120  $item->setData($value);
121  $this->addItem($item);
122  }
123  }
124  return $this;
125  }
126 }
const REPORT_PRODUCT_VIEWED_FLAG_CODE
Definition: Flag.php:31
const REPORT_BESTSELLERS_FLAG_CODE
Definition: Flag.php:29
__()
Definition: __.php:13
const REPORT_ORDER_FLAG_CODE
Definition: Flag.php:17
const REPORT_INVOICE_FLAG_CODE
Definition: Flag.php:23
const REPORT_COUPONS_FLAG_CODE
Definition: Flag.php:27
$value
Definition: gender.phtml:16
const REPORT_REFUNDED_FLAG_CODE
Definition: Flag.php:25
__construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Reports\Model\FlagFactory $reportsFlagFactory)
Definition: Collection.php:35
loadData($printQuery=false, $logQuery=false)
Definition: Collection.php:65
const REPORT_SHIPPING_FLAG_CODE
Definition: Flag.php:21
addItem(\Magento\Framework\DataObject $item)
Definition: Collection.php:399