3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
7
+ declare (strict_types=1 );
8
+
6
9
namespace Magento \AdminAnalytics \ViewModel ;
7
10
11
+ use Magento \Config \Model \Config \Backend \Admin \Custom ;
12
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
8
13
use Magento \Framework \App \ProductMetadataInterface ;
9
14
use Magento \Backend \Model \Auth \Session ;
10
15
use Magento \Framework \App \State ;
11
16
use Magento \Framework \View \Element \Block \ArgumentInterface ;
17
+ use Magento \Store \Model \Information ;
12
18
13
19
/**
14
20
* Gets user version and mode
@@ -30,19 +36,27 @@ class Metadata implements ArgumentInterface
30
36
*/
31
37
private $ productMetadata ;
32
38
39
+ /**
40
+ * @var ScopeConfigInterface
41
+ */
42
+ private $ config ;
43
+
33
44
/**
34
45
* @param ProductMetadataInterface $productMetadata
35
46
* @param Session $authSession
36
47
* @param State $appState
48
+ * @param ScopeConfigInterface $config
37
49
*/
38
50
public function __construct (
39
51
ProductMetadataInterface $ productMetadata ,
40
52
Session $ authSession ,
41
- State $ appState
53
+ State $ appState ,
54
+ ScopeConfigInterface $ config
42
55
) {
43
56
$ this ->productMetadata = $ productMetadata ;
44
57
$ this ->authSession = $ authSession ;
45
58
$ this ->appState = $ appState ;
59
+ $ this ->config = $ config ;
46
60
}
47
61
48
62
/**
@@ -55,15 +69,26 @@ public function getMagentoVersion() :string
55
69
return $ this ->productMetadata ->getVersion ();
56
70
}
57
71
72
+ /**
73
+ * Get product edition
74
+ *
75
+ * @return string
76
+ */
77
+ public function getProductEdition (): string
78
+ {
79
+ return $ this ->productMetadata ->getEdition ();
80
+ }
81
+
58
82
/**
59
83
* Get current user id (hash generated from email)
60
84
*
61
85
* @return string
62
86
*/
63
87
public function getCurrentUser () :string
64
88
{
65
- return hash ('sha512 ' , 'ADMIN_USER ' . $ this ->authSession ->getUser ()->getEmail ());
89
+ return hash ('sha256 ' , 'ADMIN_USER ' . $ this ->authSession ->getUser ()->getEmail ());
66
90
}
91
+
67
92
/**
68
93
* Get Magento mode that the user is using
69
94
*
@@ -73,4 +98,62 @@ public function getMode() :string
73
98
{
74
99
return $ this ->appState ->getMode ();
75
100
}
101
+
102
+ /**
103
+ * Get created date for current user
104
+ *
105
+ * @return string
106
+ */
107
+ public function getCurrentUserCreatedDate (): string
108
+ {
109
+ return $ this ->authSession ->getUser ()->getCreated ();
110
+ }
111
+
112
+ /**
113
+ * Get log date for current user
114
+ *
115
+ * @return string|null
116
+ */
117
+ public function getCurrentUserLogDate (): ?string
118
+ {
119
+ return $ this ->authSession ->getUser ()->getLogdate ();
120
+ }
121
+
122
+ /**
123
+ * Get secure base URL
124
+ *
125
+ * @param string $scope
126
+ * @param string|null $scopeCode
127
+ * @return string|null
128
+ */
129
+ public function getSecureBaseUrlForScope (
130
+ string $ scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
131
+ ?string $ scopeCode = null
132
+ ): ?string {
133
+ return $ this ->config ->getValue (Custom::XML_PATH_SECURE_BASE_URL , $ scope , $ scopeCode );
134
+ }
135
+
136
+ /**
137
+ * Get store name
138
+ *
139
+ * @param string $scope
140
+ * @param string|null $scopeCode
141
+ * @return string|null
142
+ */
143
+ public function getStoreNameForScope (
144
+ string $ scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
145
+ ?string $ scopeCode = null
146
+ ): ?string {
147
+ return $ this ->config ->getValue (Information::XML_PATH_STORE_INFO_NAME , $ scope , $ scopeCode );
148
+ }
149
+
150
+ /**
151
+ * Get current user role name
152
+ *
153
+ * @return string
154
+ */
155
+ public function getCurrentUserRoleName (): string
156
+ {
157
+ return $ this ->authSession ->getUser ()->getRole ()->getRoleName ();
158
+ }
76
159
}
0 commit comments