Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usertogroupdataprovider.php
1<?php
2
4
9
11{
13 protected $settings;
14
16 {
17 $this->settings = $settings;
18 }
19
24 public function getSettings(): ?UserToGroupSettings
25 {
26 return $this->settings;
27 }
28
34 protected function getFieldName($fieldID): string
35 {
36 $name = Loc::getMessage("SOCIALNETWORK_USERTOGROUP_FILTER_{$fieldID}");
37
38 if ($name === null)
39 {
40 $name = $fieldID;
41 }
42
43 return $name;
44 }
45
46 public function prepareFieldData($fieldID): ?array
47 {
48 $result = null;
49
50 if ($fieldID === 'ROLE')
51 {
52 $roles = [
53 UserToGroupTable::ROLE_OWNER => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_ROLE_OWNER'),
54 UserToGroupTable::ROLE_MODERATOR => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_ROLE_MODERATOR'),
55 UserToGroupTable::ROLE_USER => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_ROLE_USER'),
56 UserToGroupTable::ROLE_REQUEST => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_ROLE_REQUEST'),
57 ];
58 $result = [
59 'params' => ['multiple' => 'Y'],
60 'items' => $roles
61 ];
62 }
63 elseif ($fieldID === 'INITIATED_BY_TYPE')
64 {
65 $result = [
66 'params' => ['multiple' => 'N'],
67 'items' => [
68 UserToGroupTable::INITIATED_BY_USER => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_INITIATED_BY_USER'),
69 UserToGroupTable::INITIATED_BY_GROUP => Loc::getMessage('SOCIALNETWORK_USERTOGROUP_FILTER_INITIATED_BY_GROUP'),
70 ]
71 ];
72 }
73 elseif (
74 $fieldID === 'DEPARTMENT'
75 || $fieldID === 'DEPARTMENT_FLAT'
76 )
77 {
78 return [
79 'params' => [
80 'apiVersion' => 3,
81 'context' => 'USERTOGROUP_LIST_FILTER_DEPARTMENT',
82 'multiple' => 'N',
83 'contextCode' => 'DR',
84 'enableDepartments' => 'Y',
85 'departmentFlatEnable' => ($fieldID === 'DEPARTMENT_FLAT' ? 'Y' : 'N'),
86 'enableAll' => 'N',
87 'enableUsers' => 'N',
88 'enableSonetgroups' => 'N',
89 'allowEmailInvitation' => 'N',
90 'allowSearchEmailUsers' => 'N',
91 'departmentSelectDisable' => 'N',
92 'isNumeric' => 'N',
93 ],
94 ];
95 }
96
97 return $result;
98 }
99
104 public function prepareFields(): array
105 {
106 $result = [];
107
108 $fieldsList = [
109 'ID' => [],
110 'NAME' => [],
111 'LAST_NAME' => [
112 'options' => [ 'default' => true ],
113 ],
114 'FIRED' => [
115 'conditionMethod' => '\Bitrix\Main\Filter\UserDataProvider::getFiredAvailability',
116 'options' => [ 'type' => 'checkbox' ]
117 ],
118 'EXTRANET' => [
119 'conditionMethod' => '\Bitrix\Main\Filter\UserDataProvider::getExtranetAvailability',
120 'options' => [ 'type' => 'checkbox' ],
121 ],
122 'ROLE' => [
123 'options' => [ 'default' => true, 'type' => 'list', 'partial' => true ],
124 ],
125 'INITIATED_BY_TYPE' => [
126 'options' => [ 'type' => 'list', 'partial' => true ],
127 ],
128 'EMAIL' => [],
129 'DEPARTMENT' => [
130 'options' => [ 'default' => true, 'type' => 'dest_selector', 'partial' => true ],
131 ],
132 'DEPARTMENT_FLAT' => [
133 'options' => [ 'type' => 'dest_selector', 'partial' => true ],
134 ],
135 'AUTO_MEMBER' => [
136 'conditionMethod' => '\Bitrix\Socialnetwork\Filter\UserToGroupDataProvider::getAutoMemberAvailability',
137 'options' => [ 'type' => 'checkbox' ]
138 ],
139
140 ];
141
142 foreach ($fieldsList as $column => $field)
143 {
144 $whiteListPassed = true;
145 if (
146 !empty($field['conditionMethod'])
147 && is_callable($field['conditionMethod'])
148 )
149 {
150 $whiteListPassed = call_user_func_array($field['conditionMethod'], []);
151 }
152
153 if ($whiteListPassed)
154 {
155 $result[$column] = $this->createField(
156 $column,
157 (!empty($field['options']) ? $field['options'] : [])
158 );
159 }
160 }
161
162 return $result;
163 }
164
165 public static function getAutoMemberAvailability(): bool
166 {
167 static $result = null;
168
169 if ($result === null)
170 {
171 $result = (
172 ModuleManager::isModuleInstalled('intranet')
173 && (
174 !Loader::includeModule('extranet')
175 || !\CExtranet::isExtranetSite()
176 )
177 );
178 }
179
180 return $result;
181 }
182
183}
createField($fieldID, array $params=null)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29