Data.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Helper\Dashboard;
  7. use Magento\Framework\App\DeploymentConfig;
  8. use Magento\Framework\Config\ConfigOptionsListConstants;
  9. /**
  10. * Data helper for dashboard
  11. *
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class Data extends \Magento\Framework\App\Helper\AbstractHelper
  16. {
  17. /**
  18. * @var \Magento\Framework\Data\Collection\AbstractDb
  19. */
  20. protected $_stores;
  21. /**
  22. * @var string
  23. */
  24. protected $_installDate;
  25. /**
  26. * @var \Magento\Store\Model\StoreManagerInterface
  27. */
  28. private $_storeManager;
  29. /**
  30. * @param \Magento\Framework\App\Helper\Context $context
  31. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  32. * @param DeploymentConfig $deploymentConfig
  33. */
  34. public function __construct(
  35. \Magento\Framework\App\Helper\Context $context,
  36. \Magento\Store\Model\StoreManagerInterface $storeManager,
  37. DeploymentConfig $deploymentConfig
  38. ) {
  39. parent::__construct(
  40. $context
  41. );
  42. $this->_installDate = $deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE);
  43. $this->_storeManager = $storeManager;
  44. }
  45. /**
  46. * Retrieve stores configured in system.
  47. *
  48. * @return \Magento\Framework\Data\Collection\AbstractDb
  49. */
  50. public function getStores()
  51. {
  52. if (!$this->_stores) {
  53. $this->_stores = $this->_storeManager->getStore()->getResourceCollection()->load();
  54. }
  55. return $this->_stores;
  56. }
  57. /**
  58. * Retrieve number of loaded stores
  59. *
  60. * @return int
  61. */
  62. public function countStores()
  63. {
  64. return sizeof($this->_stores->getItems());
  65. }
  66. /**
  67. * Prepare array with periods for dashboard graphs
  68. *
  69. * @return array
  70. */
  71. public function getDatePeriods()
  72. {
  73. return [
  74. '24h' => __('Last 24 Hours'),
  75. '7d' => __('Last 7 Days'),
  76. '1m' => __('Current Month'),
  77. '1y' => __('YTD'),
  78. '2y' => __('2YTD')
  79. ];
  80. }
  81. /**
  82. * Create data hash to ensure that we got valid
  83. * data and it is not changed by some one else.
  84. *
  85. * @param string $data
  86. * @return string
  87. */
  88. public function getChartDataHash($data)
  89. {
  90. $secret = $this->_installDate;
  91. return md5($data . $secret);
  92. }
  93. }