Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
entityselector.php
1<?php
3
8
9if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();
10
11abstract 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 {
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(),
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}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29