Statistics.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Reports\Controller\Adminhtml\Report;
  7. use Magento\Backend\Model\Auth\Session as AuthSession;
  8. use Magento\Backend\Model\Session;
  9. use Magento\Framework\App\Action\HttpGetActionInterface;
  10. /**
  11. * Report statistics admin controller.
  12. *
  13. * @api
  14. * @since 100.0.2
  15. */
  16. abstract class Statistics extends \Magento\Backend\App\Action implements HttpGetActionInterface
  17. {
  18. /**
  19. * Authorization level of a basic admin session
  20. *
  21. * @see _isAllowed()
  22. */
  23. const ADMIN_RESOURCE = 'Magento_Reports::statistics';
  24. /**
  25. * Admin session model
  26. *
  27. * @var null|AuthSession
  28. */
  29. protected $_adminSession = null;
  30. /**
  31. * @var \Magento\Framework\Stdlib\DateTime\Filter\Date
  32. */
  33. protected $_dateFilter;
  34. /**
  35. * Codes for Refresh Statistics
  36. *
  37. * @var []
  38. */
  39. protected $reportTypes;
  40. /**
  41. * @param \Magento\Backend\App\Action\Context $context
  42. * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
  43. * @param array $reportTypes
  44. */
  45. public function __construct(
  46. \Magento\Backend\App\Action\Context $context,
  47. \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
  48. array $reportTypes
  49. ) {
  50. $this->_dateFilter = $dateFilter;
  51. $this->reportTypes = $reportTypes;
  52. parent::__construct($context);
  53. }
  54. /**
  55. * Add reports and statistics breadcrumbs
  56. *
  57. * @return $this
  58. */
  59. public function _initAction()
  60. {
  61. $this->_view->loadLayout();
  62. $this->_addBreadcrumb(__('Reports'), __('Reports'));
  63. $this->_addBreadcrumb(__('Statistics'), __('Statistics'));
  64. return $this;
  65. }
  66. /**
  67. * Retrieve array of collection names by code specified in request
  68. *
  69. * @return array
  70. * @throws \Exception
  71. */
  72. protected function _getCollectionNames()
  73. {
  74. $codes = $this->getRequest()->getParam('code');
  75. if (!$codes) {
  76. throw new \Exception(__('No report code is specified.'));
  77. }
  78. if (!is_array($codes) && strpos($codes, ',') === false) {
  79. $codes = [$codes];
  80. } elseif (!is_array($codes)) {
  81. $codes = explode(',', $codes);
  82. }
  83. $out = [];
  84. foreach ($codes as $code) {
  85. $out[] = $this->reportTypes[$code];
  86. }
  87. return $out;
  88. }
  89. /**
  90. * Retrieve admin session model
  91. *
  92. * @return AuthSession|Session|mixed|null
  93. */
  94. protected function _getSession()
  95. {
  96. if ($this->_adminSession === null) {
  97. $this->_adminSession = $this->_objectManager->get(\Magento\Backend\Model\Auth\Session::class);
  98. }
  99. return $this->_adminSession;
  100. }
  101. }