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