Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
entityselector.php
1
<?php
2
namespace
Bitrix\Socialnetwork\Component
;
3
4
use
Bitrix\Main
,
5
Bitrix\Main\Localization\Loc
,
6
Bitrix\Socialnetwork\WorkgroupTable
,
7
Bitrix\Socialnetwork\UserToGroupTable
;
8
9
if
(!defined(
'B_PROLOG_INCLUDED'
) || B_PROLOG_INCLUDED !==
true
) die();
10
11
abstract
class
EntitySelector
extends
\CBitrixComponent implements
Main\Engine\Contract\Controllerable
,
Main\Errorable
12
{
14
protected
$errorCollection
=
null
;
15
16
protected
$defaultSettings
= [];
17
protected
$filter
= [];
18
protected
$filterId
=
false
;
19
protected
$filterPresets
= [];
20
protected
$requestData
= [];
21
26
public
function
__construct
($component =
null
)
27
{
28
parent::__construct($component);
29
$this->errorCollection =
new
Main\ErrorCollection
();
30
}
31
35
public
function
onIncludeComponentLang
()
36
{
37
Loc::loadMessages
(__FILE__);
38
}
39
44
public
function
onPrepareComponentParams
($params)
45
{
46
if
(
47
!isset($params[
'SITE_ID'
])
48
|| !is_string($params[
'SITE_ID'
])
49
)
50
{
51
$params[
'SITE_ID'
] = \CSite::getDefSite();
52
}
53
54
return
$params;
55
}
56
60
public
function
executeComponent
()
61
{
62
Main\Loader::includeModule(
'intranet'
);
63
64
if
(!Main\Loader::includeModule(
'socialnetwork'
))
65
{
66
showError(
Loc::getMessage
(
'SONET_ENTITY_SELECTOR_ERR_SONET_MODULE_NOT_INSTALLED'
));
67
return
;
68
}
69
70
$this->
prepareRequest
();
71
$this->
initDefaultSettings
();
72
$this->
prepareFilter
();
73
$this->
prepareResult
();
74
$this->includeComponentTemplate();
75
}
76
80
public
function
configureActions
()
81
{
82
return
[];
83
}
84
89
public
function
getErrorByCode
($code)
90
{
91
return
$this->errorCollection->getErrorByCode($code);
92
}
93
97
public
function
getErrors
()
98
{
99
return
$this->errorCollection->toArray();
100
}
101
105
protected
function
prepareRequest
()
106
{
107
108
}
109
113
protected
function
prepareFilter
()
114
{
115
$context =
'SONET_LANDING_ENTITY_SELECTOR_GROUP'
;
116
117
$this->filter = [
118
[
119
'id'
=>
'GROUP_ID'
,
120
'name'
=>
Loc::getMessage
(
'SONET_ENTITY_SELECTOR_FILTER_FIELD_GROUP_TITLE'
),
121
'default'
=>
true
,
122
'type'
=>
'dest_selector'
,
123
'params'
=> [
124
'apiVersion'
=>
'3'
,
125
'context'
=> $context,
126
'multiple'
=>
'N'
,
127
'contextCode'
=>
'SG'
,
128
'enableAll'
=>
'N'
,
129
'enableUsers'
=>
'N'
,
130
'enableSonetgroups'
=>
'Y'
,
131
'enableDepartments'
=>
'N'
,
132
'landing'
=>
'Y'
,
133
'useClientDatabase'
=>
'N'
134
],
135
],
136
[
137
'id'
=>
'AUTHOR_ID'
,
138
'name'
=>
Loc::getMessage
(
'SONET_ENTITY_SELECTOR_FILTER_FIELD_AUTHOR_TITLE'
),
139
'default'
=>
false
,
140
'type'
=>
'dest_selector'
,
141
'params'
=> [
142
'apiVersion'
=>
'3'
,
143
'context'
=> $context,
144
'multiple'
=>
'N'
,
145
'contextCode'
=>
'U'
,
146
'enableAll'
=>
'N'
,
147
'enableUsers'
=>
'Y'
,
148
'enableSonetgroups'
=>
'N'
,
149
'enableDepartments'
=>
'Y'
,
150
'departmentSelectDisable'
=>
'Y'
,
151
'landing'
=>
'Y'
,
152
'useClientDatabase'
=>
'Y'
153
],
154
]
155
];
156
}
157
158
protected
function
getFilter
()
159
{
160
return
$this->filter
;
161
}
162
166
protected
function
initDefaultSettings
()
167
{
168
$this->defaultSettings = [
169
];
170
}
171
172
173
protected
function
setFilterId
(
$filterId
=
false
)
174
{
175
$this->filterId =
$filterId
;
176
}
177
178
protected
function
getFilterId
()
179
{
180
return
$this->filterId
;
181
}
182
183
protected
function
setFilterPresets
(
$filterPresets
= [])
184
{
185
$this->filterPresets =
$filterPresets
;
186
}
187
188
protected
function
getFilterPresets
()
189
{
190
return
$this->filterPresets
;
191
}
192
193
protected
function
getCurrentUserId
()
194
{
195
global $USER;
196
197
return
$USER->getId();
198
}
199
200
protected
function
getWorkgroups
()
201
{
202
$result = [];
203
204
if
(\CSocNetUser::isCurrentUserModuleAdmin($this->arParams[
'SITE_ID'
]))
205
{
206
$filter
= [
207
'=LANDING'
=>
'Y'
,
208
'=ACTIVE'
=>
'Y'
209
];
210
if
(!empty($this->arParams[
'SITE_ID'
]))
211
{
212
$filter
[
"=WorkgroupSite:GROUP.SITE_ID"
] = $this->arParams[
'SITE_ID'
];
213
}
214
215
$res = WorkgroupTable::getList([
216
'filter'
=>
$filter
,
217
'limit'
=> 100,
218
'select'
=> [
219
'GROUP_ID'
=>
'ID'
,
220
'GROUP_NAME'
=>
'NAME'
221
]
222
]);
223
}
224
else
225
{
226
$filter
= [
227
'=GROUP.LANDING'
=>
'Y'
,
228
'=GROUP.ACTIVE'
=>
'Y'
,
229
'=USER_ID'
=> $this->
getCurrentUserId
(),
230
'@ROLE'
=>
UserToGroupTable::getRolesMember
()
231
];
232
if
(!empty($this->arParams[
'SITE_ID'
]))
233
{
234
$filter
[
"=GROUP.WorkgroupSite:GROUP.SITE_ID"
] = $this->arParams[
'SITE_ID'
];
235
}
236
237
$res = UserToGroupTable::getList([
238
'filter'
=>
$filter
,
239
'limit'
=> 100,
240
'select'
=> [
241
'GROUP_ID'
=>
'GROUP_ID'
,
242
'GROUP_NAME'
=>
'GROUP.NAME'
243
]
244
]);
245
}
246
247
while
($workgroupFields = $res->fetch())
248
{
249
$result[] = [
250
'ID'
=> $workgroupFields[
'GROUP_ID'
],
251
'CODE'
=>
'SG'
.$workgroupFields[
'GROUP_ID'
],
252
'NAME'
=> $workgroupFields[
'GROUP_NAME'
],
253
];
254
}
255
256
return
$result;
257
}
258
259
protected
function
setDefaultFilter
($value = [])
260
{
261
if
(
262
empty($value)
263
|| !is_array($value)
264
|| empty($value[
'GROUP_ID'
])
265
)
266
{
267
return
;
268
}
269
270
$options = new \Bitrix\Main\UI\Filter\Options($this->
getFilterId
(), $this->
getFilterPresets
());
271
$options->setupDefaultFilter(
272
$value,
273
[
'GROUP_ID'
,
'AUTHOR_ID'
]
274
);
275
}
276
280
protected
function
prepareResult
()
281
{
282
global $DB;
283
$this->
getData
();
284
285
$intranetInstalled = Main\Loader::includeModule(
'intranet'
);
286
$dateTimeformat = $DB->dateFormatToPHP(FORMAT_DATETIME);
287
288
$this->arResult = [
289
'FILTER_ID'
=> $this->
getFilterId
(),
290
'FILTER'
=> $this->
getFilter
(),
291
'FILTER_PRESETS'
=> $this->
getFilterPresets
(),
292
'CURRENT_DATETIME_FORMAT'
=> ($intranetInstalled ? \CIntranetUtils::getCurrentDateTimeFormat() : preg_replace(
'/[\/.,\s:][s]/'
,
''
, $dateTimeformat)),
293
'CURRENT_DATETIME_FORMAT_WOYEAR'
=> ($intranetInstalled ? \CIntranetUtils::getCurrentDateTimeFormat([
294
'woYear'
=>
true
295
]) : preg_replace(
'/[\/.,\s-][Yyo]/'
,
''
, $dateTimeformat)),
296
'CURRENT_USER_ID'
=> $this->
getCurrentUserId
()
297
];
298
}
299
303
protected
function
getDataFilter
()
304
{
305
return
[];
306
}
307
311
abstract
protected
function
getData
();
312
316
protected
function
getNavigationTitle
()
317
{
318
return
''
;
319
}
320
}
Bitrix\Main\ErrorCollection
Definition
errorcollection.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Socialnetwork\Component\EntitySelector
Definition
entityselector.php:12
Bitrix\Socialnetwork\Component\EntitySelector\initDefaultSettings
initDefaultSettings()
Definition
entityselector.php:166
Bitrix\Socialnetwork\Component\EntitySelector\onPrepareComponentParams
onPrepareComponentParams($params)
Definition
entityselector.php:44
Bitrix\Socialnetwork\Component\EntitySelector\__construct
__construct($component=null)
Definition
entityselector.php:26
Bitrix\Socialnetwork\Component\EntitySelector\getFilter
getFilter()
Definition
entityselector.php:158
Bitrix\Socialnetwork\Component\EntitySelector\prepareRequest
prepareRequest()
Definition
entityselector.php:105
Bitrix\Socialnetwork\Component\EntitySelector\$filterId
$filterId
Definition
entityselector.php:18
Bitrix\Socialnetwork\Component\EntitySelector\$requestData
$requestData
Definition
entityselector.php:20
Bitrix\Socialnetwork\Component\EntitySelector\getFilterPresets
getFilterPresets()
Definition
entityselector.php:188
Bitrix\Socialnetwork\Component\EntitySelector\getFilterId
getFilterId()
Definition
entityselector.php:178
Bitrix\Socialnetwork\Component\EntitySelector\getErrors
getErrors()
Definition
entityselector.php:97
Bitrix\Socialnetwork\Component\EntitySelector\$filterPresets
$filterPresets
Definition
entityselector.php:19
Bitrix\Socialnetwork\Component\EntitySelector\$errorCollection
$errorCollection
Definition
entityselector.php:14
Bitrix\Socialnetwork\Component\EntitySelector\getData
getData()
Bitrix\Socialnetwork\Component\EntitySelector\prepareFilter
prepareFilter()
Definition
entityselector.php:113
Bitrix\Socialnetwork\Component\EntitySelector\onIncludeComponentLang
onIncludeComponentLang()
Definition
entityselector.php:35
Bitrix\Socialnetwork\Component\EntitySelector\getDataFilter
getDataFilter()
Definition
entityselector.php:303
Bitrix\Socialnetwork\Component\EntitySelector\setFilterId
setFilterId($filterId=false)
Definition
entityselector.php:173
Bitrix\Socialnetwork\Component\EntitySelector\$filter
$filter
Definition
entityselector.php:17
Bitrix\Socialnetwork\Component\EntitySelector\setFilterPresets
setFilterPresets($filterPresets=[])
Definition
entityselector.php:183
Bitrix\Socialnetwork\Component\EntitySelector\getWorkgroups
getWorkgroups()
Definition
entityselector.php:200
Bitrix\Socialnetwork\Component\EntitySelector\getNavigationTitle
getNavigationTitle()
Definition
entityselector.php:316
Bitrix\Socialnetwork\Component\EntitySelector\configureActions
configureActions()
Definition
entityselector.php:80
Bitrix\Socialnetwork\Component\EntitySelector\getErrorByCode
getErrorByCode($code)
Definition
entityselector.php:89
Bitrix\Socialnetwork\Component\EntitySelector\executeComponent
executeComponent()
Definition
entityselector.php:60
Bitrix\Socialnetwork\Component\EntitySelector\$defaultSettings
$defaultSettings
Definition
entityselector.php:16
Bitrix\Socialnetwork\Component\EntitySelector\prepareResult
prepareResult()
Definition
entityselector.php:280
Bitrix\Socialnetwork\Component\EntitySelector\getCurrentUserId
getCurrentUserId()
Definition
entityselector.php:193
Bitrix\Socialnetwork\Component\EntitySelector\setDefaultFilter
setDefaultFilter($value=[])
Definition
entityselector.php:259
Bitrix\Socialnetwork\UserToGroupTable
Definition
usertogroup.php:33
Bitrix\Socialnetwork\UserToGroupTable\getRolesMember
static getRolesMember()
Definition
usertogroup.php:73
Bitrix\Socialnetwork\WorkgroupTable
Definition
workgroup.php:33
Bitrix\Main\Engine\Contract\Controllerable
Definition
controllerable.php:6
Bitrix\Main\Errorable
Definition
errorable.php:6
Bitrix\Main
Bitrix\Socialnetwork\Component
Definition
blogpostedit.php:3
modules
socialnetwork
lib
component
entityselector.php
Создано системой
1.10.0