Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
role.php
1<?php
2
11
15
16Loc::loadMessages(__FILE__);
17
18class Role
19{
20 public static function getRoleValue(array $params = []): string
21 {
22 $result = '';
23
24 $relationFields = ($params['RELATION'] ?? []);
25 if (empty($relationFields))
26 {
27 return $result;
28 }
29
30 $groupFields = ($params['GROUP'] ?? []);
31 if ($groupFields['SCRUM_MASTER_ID'] > 0)
32 {
33 $suffix = '_SCRUM';
34 }
35 elseif ($groupFields['PROJECT'])
36 {
37 $suffix = '_PROJECT';
38 }
39 else
40 {
41 $suffix = '';
42 }
43
44 $role = $relationFields['ROLE'];
45
46 $classList = [ 'ui-label' ];
47
48 if (in_array($role, UserToGroupTable::getRolesMember(), true))
49 {
50 $classList[] = 'sonet-ui-grid-role';
51
52 $isScrumMaster = (int)$relationFields['USER_ID'] === (int)$groupFields['SCRUM_MASTER_ID'];
53
54 $parts = [];
55
56 if (!(
57 $isScrumMaster
59 && $relationFields['AUTO_MEMBER'] === false
60 ))
61 {
62 $parts = [
64 'SOCIALNETWORK_HELPER_UI_GRID_ROLE_' . $role
65 . $suffix
66 . ($relationFields['AUTO_MEMBER'] ? '_AUTO' : '')
67 ),
68 ];
69 }
70
71 if ($isScrumMaster)
72 {
73 $parts[] = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ROLE_SCRUM_MASTER');
74 }
75
76 $result = implode(', ', $parts);
77
78 switch ($role)
79 {
81 $classList[] = '--role-green';
82 break;
84 $classList[] = '--role-yellow';
85 break;
87 $classList[] = '--role-blue';
88 break;
89 default:
90 }
91 }
92 elseif ($role === UserToGroupTable::ROLE_REQUEST)
93 {
94 $groupId = (int) $groupFields['ID'];
95 $gridId = ($params['GRID_ID'] ?? 'SONET_GROUP_LIST');
96 $type = $relationFields['INITIATED_TYPE'];
97 $onclick = 'event.stopPropagation();';
98
100 {
101 $acceptOnclick = $onclick . 'BX.Socialnetwork.WorkgroupList.Manager.getById(\''
102 . $gridId . '\').getActionManager().act({action: \''
104 . '\',groupId: \'' . $groupId . '\',});';
105
106 $cancelOnclick = $onclick . 'BX.Socialnetwork.WorkgroupList.Manager.getById(\''
107 . $gridId . '\').getActionManager().act({action: \''
109 . '\',groupId: \'' . $groupId . '\',});';
110
111 return '
112 <span class="sonet-ui-grid-badge-invite-box">
113 <span class="ui-label sonet-ui-grid-badge-invite-accept">
114 <span class="ui-label-inner">
115 ' . Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ROLE_REQUEST_' . $type) . '
116 </span>
117 </span>
118 <span
119 class="ui-label sonet-ui-grid-badge-accept"
120 onclick="'. $acceptOnclick .'"
121 title="' . Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ROLE_JOIN') . '"
122 >
123 <span class="ui-label-inner"></span>
124 </span>
125 <span
126 class="ui-label sonet-ui-grid-badge-cancel"
127 onclick="'. $cancelOnclick .'"
128 title="' . Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ROLE_DELETE_OUTGOING_REQUEST') . '"
129 >
130 <span class="ui-label-inner"></span>
131 </span>
132 </span>
133 ';
134 }
135 elseif ($type === UserToGroupTable::INITIATED_BY_USER)
136 {
137 $onclick .= 'BX.Socialnetwork.WorkgroupList.Manager.getById(\''
138 . $gridId . '\').getActionManager().act({action: \''
140 . '\',groupId: \'' . $groupId . '\',});';
141
142 return '
143 <span class="sonet-ui-grid-badge-invite-box">
144 <span class="ui-label sonet-ui-grid-badge-invite">
145 <span class="ui-label-inner">
146 ' . Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ROLE_REQUEST_' . $type) . '
147 </span>
148 </span>
149 <span
150 class="ui-label sonet-ui-grid-badge-cancel"
151 onclick="'. $onclick .'"
152 title="' . Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ROLE_DELETE_INCOMING_REQUEST') . '"
153 >
154 <span class="ui-label-inner"></span>
155 </span>
156 </span>
157 ';
158 }
159 }
160 elseif ($role === UserToGroupTable::ROLE_BAN)
161 {
162 $result = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ROLE_BAN');
163 }
164
165 $result = '
166 <span class="' . implode(' ', $classList) . '">
167 <span class="ui-label-inner">' . $result . '</span>
168 </span>
169 ';
170
171 return '<span class="sonet-ui-grid-request-cont">' . $result . '</span>';
172 }
173
174 public static function getJoinValue(array $params = []): string
175 {
176 $classList = [
177 'ui-label',
178 'sonet-ui-grid-join',
179 ];
180
181 $result = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ROLE_JOIN');
182
183 if (
184 isset($params['OPENED'])
185 && $params['OPENED'] === true
186 )
187 {
188 $result = '<span onclick="' . htmlspecialcharsbx($params['ONCLICK']) . '" class="' . implode(' ', $classList) . '"><span class="ui-label-inner">' . $result . '</span></span>';
189 }
190 else
191 {
192 $result = '<a href="'. $params['PATH_TO_JOIN_GROUP'] . '" class="' . implode(' ', $classList) . '"><span class="ui-label-inner">' . $result . '</span></a>';
193 }
194
195
196 return '<span class="sonet-ui-grid-request-cont">' . $result . '</span>';
197 }
198}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29