Collection.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Refresh Statistic Grid collection
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Reports\Model\ResourceModel\Refresh;
  12. /**
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Collection extends \Magento\Framework\Data\Collection
  17. {
  18. /**
  19. * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
  20. */
  21. protected $_localeDate;
  22. /**
  23. * @var \Magento\Reports\Model\FlagFactory
  24. */
  25. protected $_reportsFlagFactory;
  26. /**
  27. * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  28. * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  29. * @param \Magento\Reports\Model\FlagFactory $reportsFlagFactory
  30. */
  31. public function __construct(
  32. \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
  33. \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
  34. \Magento\Reports\Model\FlagFactory $reportsFlagFactory
  35. ) {
  36. parent::__construct($entityFactory);
  37. $this->_localeDate = $localeDate;
  38. $this->_reportsFlagFactory = $reportsFlagFactory;
  39. }
  40. /**
  41. * Get if updated
  42. *
  43. * @param string $reportCode
  44. * @return string
  45. */
  46. protected function _getUpdatedAt($reportCode)
  47. {
  48. $flag = $this->_reportsFlagFactory->create()->setReportFlagCode($reportCode)->loadSelf();
  49. return $flag->hasData() ? $flag->getLastUpdate() : '';
  50. }
  51. /**
  52. * Load data
  53. *
  54. * @param bool $printQuery
  55. * @param bool $logQuery
  56. * @return $this
  57. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  58. */
  59. public function loadData($printQuery = false, $logQuery = false)
  60. {
  61. if (!count($this->_items)) {
  62. $data = [
  63. [
  64. 'id' => 'sales',
  65. 'report' => __('Orders'),
  66. 'comment' => __('Total Ordered Report'),
  67. 'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_ORDER_FLAG_CODE),
  68. ],
  69. [
  70. 'id' => 'tax',
  71. 'report' => __('Tax'),
  72. 'comment' => __('Order Taxes Report Grouped by Tax Rates'),
  73. 'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_TAX_FLAG_CODE)
  74. ],
  75. [
  76. 'id' => 'shipping',
  77. 'report' => __('Shipping'),
  78. 'comment' => __('Total Shipped Report'),
  79. 'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_SHIPPING_FLAG_CODE)
  80. ],
  81. [
  82. 'id' => 'invoiced',
  83. 'report' => __('Total Invoiced'),
  84. 'comment' => __('Total Invoiced VS Paid Report'),
  85. 'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_INVOICE_FLAG_CODE)
  86. ],
  87. [
  88. 'id' => 'refunded',
  89. 'report' => __('Total Refunded'),
  90. 'comment' => __('Total Refunded Report'),
  91. 'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_REFUNDED_FLAG_CODE)
  92. ],
  93. [
  94. 'id' => 'coupons',
  95. 'report' => __('Coupons'),
  96. 'comment' => __('Promotion Coupons Usage Report'),
  97. 'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_COUPONS_FLAG_CODE)
  98. ],
  99. [
  100. 'id' => 'bestsellers',
  101. 'report' => __('Bestsellers'),
  102. 'comment' => __('Products Bestsellers Report'),
  103. 'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_BESTSELLERS_FLAG_CODE)
  104. ],
  105. [
  106. 'id' => 'viewed',
  107. 'report' => __('Most Viewed'),
  108. 'comment' => __('Most Viewed Products Report'),
  109. 'updated_at' => $this->_getUpdatedAt(\Magento\Reports\Model\Flag::REPORT_PRODUCT_VIEWED_FLAG_CODE)
  110. ],
  111. ];
  112. foreach ($data as $value) {
  113. $item = new \Magento\Framework\DataObject();
  114. $item->setData($value);
  115. $this->addItem($item);
  116. }
  117. }
  118. return $this;
  119. }
  120. }