33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
7+ declare (strict_types=1 );
8+
69namespace Magento \AdminAnalytics \ViewModel ;
710
11+ use Magento \Config \Model \Config \Backend \Admin \Custom ;
12+ use Magento \Framework \App \Config \ScopeConfigInterface ;
813use Magento \Framework \App \ProductMetadataInterface ;
914use Magento \Backend \Model \Auth \Session ;
1015use Magento \Framework \App \State ;
1116use Magento \Framework \View \Element \Block \ArgumentInterface ;
17+ use Magento \Store \Model \Information ;
1218
1319/**
1420 * Gets user version and mode
@@ -30,19 +36,27 @@ class Metadata implements ArgumentInterface
3036 */
3137 private $ productMetadata ;
3238
39+ /**
40+ * @var ScopeConfigInterface
41+ */
42+ private $ config ;
43+
3344 /**
3445 * @param ProductMetadataInterface $productMetadata
3546 * @param Session $authSession
3647 * @param State $appState
48+ * @param ScopeConfigInterface $config
3749 */
3850 public function __construct (
3951 ProductMetadataInterface $ productMetadata ,
4052 Session $ authSession ,
41- State $ appState
53+ State $ appState ,
54+ ScopeConfigInterface $ config
4255 ) {
4356 $ this ->productMetadata = $ productMetadata ;
4457 $ this ->authSession = $ authSession ;
4558 $ this ->appState = $ appState ;
59+ $ this ->config = $ config ;
4660 }
4761
4862 /**
@@ -55,15 +69,26 @@ public function getMagentoVersion() :string
5569 return $ this ->productMetadata ->getVersion ();
5670 }
5771
72+ /**
73+ * Get product edition
74+ *
75+ * @return string
76+ */
77+ public function getProductEdition (): string
78+ {
79+ return $ this ->productMetadata ->getEdition ();
80+ }
81+
5882 /**
5983 * Get current user id (hash generated from email)
6084 *
6185 * @return string
6286 */
6387 public function getCurrentUser () :string
6488 {
65- return hash ('sha512 ' , 'ADMIN_USER ' . $ this ->authSession ->getUser ()->getEmail ());
89+ return hash ('sha256 ' , 'ADMIN_USER ' . $ this ->authSession ->getUser ()->getEmail ());
6690 }
91+
6792 /**
6893 * Get Magento mode that the user is using
6994 *
@@ -73,4 +98,62 @@ public function getMode() :string
7398 {
7499 return $ this ->appState ->getMode ();
75100 }
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+ }
76159}
0 commit comments