Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
actions.php
1<?php
2
11
14use Bitrix\Socialnetwork\EO_Workgroup;
15use Bitrix\Socialnetwork\EO_UserToGroup;
18
20{
21 public static function getActions(
22 ?EO_Workgroup $group,
23 ?EO_UserToGroup $currentUserRelationItem,
24 array $actions = [],
25 array $params = []
26 ): array
27 {
28 $result = [];
29
30 $isProject = (bool)$group->get('PROJECT');
31 $isScrum = ($isProject && $group->get('SCRUM_MASTER_ID') > 0);
32
33 if (in_array(WorkgroupList::AVAILABLE_ACTION_VIEW, $actions, true))
34 {
35 $text = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_VIEW');
36 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_VIEW_TITLE');
37 if ($isScrum)
38 {
39 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_VIEW_TITLE_SCRUM');
40 }
41 elseif ($isProject)
42 {
43 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_VIEW_TITLE_PROJECT');
44 }
45
46 $groupUrl = str_replace(
47 [ '#id#', '#ID#', '#GROUP_ID#', '#group_id#' ],
48 $group->getId(),
49 $params['PATH_TO_GROUP']
50 );
51 if ($isScrum)
52 {
53 $groupUrl = (new Uri($groupUrl))
54 ->addParams(['scrum' => 'Y'])
55 ->getUri()
56 ;
57 }
58
59 $result[] = [
60 'text' => $text,
61 'title' => $title,
62 'href' => $groupUrl,
63 ];
64 }
65
66 if (in_array(WorkgroupList::AVAILABLE_ACTION_ADD_TO_FAVORITES, $actions, true))
67 {
68 $text = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_ADD_TO_FAVORITES');
69 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_ADD_TO_FAVORITES_TITLE');
70 if ($isScrum)
71 {
72 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_ADD_TO_FAVORITES_TITLE_SCRUM');
73 }
74 elseif ($isProject)
75 {
76 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_ADD_TO_FAVORITES_TITLE_PROJECT');
77 }
78
79 $result[] = [
80 'text' => $text,
81 'title' => $title,
82 'onclick' => 'BX.Socialnetwork.WorkgroupList.Manager.getById("' . $params['GRID_ID'] . '").getActionManager().act({
83 action: "' . WorkgroupList::AJAX_ACTION_ADD_TO_FAVORITES . '",
84 groupId: "' . $group->getId() . '",
85 })',
86 ];
87 }
88
89 if (in_array(WorkgroupList::AVAILABLE_ACTION_REMOVE_FROM_FAVORITES, $actions, true))
90 {
91 $text = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_REMOVE_FROM_FAVORITES');
92 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_REMOVE_FROM_FAVORITES_TITLE');
93 if ($isScrum)
94 {
95 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_REMOVE_FROM_FAVORITES_TITLE_SCRUM');
96 }
97 elseif ($isProject)
98 {
99 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_REMOVE_FROM_FAVORITES_TITLE_PROJECT');
100 }
101
102 $result[] = [
103 'text' => $text,
104 'title' => $title,
105 'onclick' => 'BX.Socialnetwork.WorkgroupList.Manager.getById("' . $params['GRID_ID'] . '").getActionManager().act({
106 action: "' . WorkgroupList::AJAX_ACTION_REMOVE_FROM_FAVORITES . '",
107 groupId: "' . $group->getId() . '",
108 })',
109 ];
110 }
111
112 if (in_array(WorkgroupList::AVAILABLE_ACTION_EDIT, $actions, true))
113 {
114 $text = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_EDIT');
115 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_EDIT_TITLE');
116 if ($isScrum)
117 {
118 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_EDIT_TITLE_SCRUM');
119 }
120 elseif ($isProject)
121 {
122 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_EDIT_TITLE_PROJECT');
123 }
124
125 $result[] = [
126 'text' => $text,
127 'title' => $title,
128 'href' => str_replace([ '#id#', '#ID#', '#GROUP_ID#', '#group_id#' ], $group->getId(), $params['PATH_TO_GROUP_EDIT']),
129 ];
130 }
131
132 if (in_array(WorkgroupList::AVAILABLE_ACTION_JOIN, $actions, true))
133 {
134 $text = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_JOIN');
135 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_JOIN_TITLE');
136 if ($isScrum)
137 {
138 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_JOIN_TITLE_SCRUM');
139 }
140 elseif ($isProject)
141 {
142 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_JOIN_TITLE_PROJECT');
143 }
144
145 $menuItem = [
146 'text' => $text,
147 'title' => $title,
148 ];
149
150 if (
151 $group->getOpened()
152 || (
153 $currentUserRelationItem
154 && $currentUserRelationItem->get('ROLE') === UserToGroupTable::ROLE_REQUEST
155 && $currentUserRelationItem->get('INITIATED_BY_TYPE') === UserToGroupTable::INITIATED_BY_GROUP
156 )
157 )
158 {
159 $menuItem['onclick'] = 'BX.Socialnetwork.WorkgroupList.Manager.getById("' . $params['GRID_ID'] . '").getActionManager().act({
160 action: "' . WorkgroupList::AJAX_ACTION_JOIN . '",
161 groupId: "' . $group->getId() . '",
162 })';
163 }
164 else
165 {
166 $menuItem['href'] = str_replace([ '#id#', '#ID#', '#GROUP_ID#', '#group_id#' ], $group->getId(), $params['PATH_TO_JOIN_GROUP']);
167 }
168
169 $result[] = $menuItem;
170 }
171
172 if (in_array(WorkgroupList::AVAILABLE_ACTION_LEAVE, $actions, true))
173 {
174 $text = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_LEAVE');
175 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_LEAVE_TITLE');
176 if ($isScrum)
177 {
178 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_LEAVE_TITLE_SCRUM');
179 }
180 elseif ($isProject)
181 {
182 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_LEAVE_TITLE_PROJECT');
183 }
184
185 $result[] = [
186 'text' => $text,
187 'title' => $title,
188 'href' => str_replace([ '#id#', '#ID#', '#GROUP_ID#', '#group_id#' ], $group->getId(), $params['PATH_TO_LEAVE_GROUP']),
189 ];
190 }
191
192 if (in_array(WorkgroupList::AVAILABLE_ACTION_DELETE_INCOMING_REQUEST, $actions, true))
193 {
194 $text = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_DELETE_INCOMING_REQUEST');
195 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_DELETE_INCOMING_REQUEST_TITLE');
196 if ($isScrum)
197 {
198 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_DELETE_INCOMING_REQUEST_TITLE_SCRUM');
199 }
200 elseif ($isProject)
201 {
202 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_DELETE_INCOMING_REQUEST_TITLE_PROJECT');
203 }
204
205 $result[] = [
206 'text' => $text,
207 'title' => $title,
208 'onclick' => 'BX.Socialnetwork.WorkgroupList.Manager.getById("' . $params['GRID_ID'] . '").getActionManager().act({
209 action: "' . WorkgroupList::AJAX_ACTION_DELETE_INCOMING_REQUEST . '",
210 groupId: "' . $group->getId() . '",
211 })',
212 ];
213 }
214
215 if (in_array(WorkgroupList::AVAILABLE_ACTION_ADD_TO_ARCHIVE, $actions, true))
216 {
217 $text = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_ADD_TO_ARCHIVE');
218 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_ADD_TO_ARCHIVE_TITLE');
219 if ($isScrum)
220 {
221 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_ADD_TO_ARCHIVE_TITLE_SCRUM');
222 }
223 elseif ($isProject)
224 {
225 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_ADD_TO_ARCHIVE_TITLE_PROJECT');
226 }
227
228 $result[] = [
229 'text' => $text,
230 'title' => $title,
231 'onclick' => 'BX.Socialnetwork.WorkgroupList.Manager.getById("' . $params['GRID_ID'] . '").getActionManager().act({
232 action: "' . WorkgroupList::AJAX_ACTION_ADD_TO_ARCHIVE . '",
233 groupId: "' . $group->getId() . '",
234 })',
235 ];
236 }
237
238 if (in_array(WorkgroupList::AVAILABLE_ACTION_REMOVE_FROM_ARCHIVE, $actions, true))
239 {
240 $text = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_REMOVE_FROM_ARCHIVE');
241 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_REMOVE_FROM_ARCHIVE_TITLE');
242 if ($isScrum)
243 {
244 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_REMOVE_FROM_ARCHIVE_TITLE_SCRUM');
245 }
246 elseif ($isProject)
247 {
248 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_REMOVE_FROM_ARCHIVE_TITLE_PROJECT');
249 }
250
251 $result[] = [
252 'text' => $text,
253 'title' => $title,
254 'onclick' => 'BX.Socialnetwork.WorkgroupList.Manager.getById("' . $params['GRID_ID'] . '").getActionManager().act({
255 action: "' . WorkgroupList::AJAX_ACTION_REMOVE_FROM_ARCHIVE . '",
256 groupId: "' . $group->getId() . '",
257 })',
258 ];
259 }
260
261 if (in_array(WorkgroupList::AVAILABLE_ACTION_DELETE, $actions, true))
262 {
263 $text = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_DELETE');
264 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_DELETE_TITLE');
265 if ($isScrum)
266 {
267 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_DELETE_TITLE_SCRUM');
268 }
269 elseif ($isProject)
270 {
271 $title = Loc::getMessage('SOCIALNETWORK_HELPER_UI_GRID_ACTION_DELETE_TITLE_PROJECT');
272 }
273
274 $result[] = [
275 'text' => $text,
276 'title' => $title,
277 'href' => str_replace([ '#id#', '#ID#', '#GROUP_ID#', '#group_id#' ], $group->getId(), $params['PATH_TO_GROUP_DELETE']),
278 ];
279 }
280
281 return $result;
282 }
283}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getActions(?EO_Workgroup $group, ?EO_UserToGroup $currentUserRelationItem, array $actions=[], array $params=[])
Definition actions.php:21