Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
user.php
1<?php
9
14
16
17Loc::loadMessages(__FILE__);
18
23class User
24{
26 protected $id = null;
27
29 protected $object;
30
32 protected $access;
33
35 protected static $instanceCurrentUser;
36
38 protected static $instance;
39
40 protected static array $cache = [];
46 public static function current()
47 {
48 if (!static::$instanceCurrentUser)
49 {
50 static::$instanceCurrentUser = new static();
51 }
52
53 return static::$instanceCurrentUser;
54 }
55
62 public static function get($id)
63 {
64 if (!static::$instance || static::$instance->getId() != $id)
65 {
66 static::$instance = new static($id);
67 }
68
69 return static::$instance;
70 }
71
77 public function __construct($id = null)
78 {
79 $this->id = $id;
80 }
81
87 public function getId()
88 {
89 if ($this->isCurrent())
90 {
91 return $this->getObject()->getID();
92 }
93
94 return $this->id;
95 }
96
102 public function isAdmin()
103 {
104 if ($this->isCurrent())
105 {
106 return $this->getObject()->isAdmin();
107 }
108
109 return in_array(1, UserTable::getUserGroupIds($this->id));
110 }
111
117 public function hasAccess()
118 {
119 return $this->getAccess()->canViewAnything();
120 }
121
128 public function getAccess()
129 {
130 if (!$this->access)
131 {
132 $this->access = Access::getInstance($this);
133 }
134
135 return $this->access;
136 }
137
143 public function canView()
144 {
145 if (!$this->isModuleAccessibleOnPortal())
146 {
147 return false;
148 }
149
150 if ($this->isBroadAccess())
151 {
152 return true;
153 }
154
155 if ($this->isPortalAdmin())
156 {
157 return true;
158 }
159
160 if (is_object($GLOBALS['APPLICATION']) && $GLOBALS['APPLICATION']->getGroupRight('sender') !== "D")
161 {
162 return true;
163 }
164
165 return false;
166 }
167
168 private function isBroadAccess()
169 {
170 if ($this->isExtranet())
171 {
172 return false;
173 }
174
175 if (!Integration\Bitrix24\Service::isPortal())
176 {
177 return false;
178 }
179
180 return !Role\Manager::canUse();
181 }
182
183 private function isModuleAccessibleOnPortal()
184 {
185 if (!Integration\Bitrix24\Service::isCloud())
186 {
187 return true;
188 }
189
190 return Option::get('sender', '~is_accessible_on_portal', 'Y') === 'Y';
191 }
192
198 public function canEdit()
199 {
200 if (!$this->isModuleAccessibleOnPortal())
201 {
202 return false;
203 }
204
205 if ($this->isBroadAccess())
206 {
207 return true;
208 }
209
210 if ($this->isPortalAdmin())
211 {
212 return true;
213 }
214
215 if (is_object($GLOBALS['APPLICATION']) && $GLOBALS['APPLICATION']->getGroupRight('sender') === "W")
216 {
217 return true;
218 }
219
220 return false;
221 }
222
228 public function isPortalAdmin()
229 {
230 if (!Integration\Bitrix24\Service::isPortal() && !Integration\Bitrix24\Service::isCloud())
231 {
232 return $this->isAdmin();
233 }
234
235 return $this->getObject()->canDoOperation('bitrix24_config', $this->id);
236 }
237
238 public function isExtranet()
239 {
240 if(!$this->isConfigured())
241 {
242 return false;
243 }
244
245 if(array_key_exists($this->getId(), static::$cache))
246 {
247 return static::$cache[$this->getId()];
248 }
249
250 $result = !\CExtranet::IsIntranetUser(SITE_ID, $this->getId());
251
252 static::$cache[$this->getId()] = $result;
253
254 return $result;
255 }
256
257 private function isConfigured()
258 {
259 return Loader::includeModule('extranet') && $this->getExtranetSiteID();
260 }
261
262 private function getExtranetSiteID()
263 {
264 $extranet_site_id = \COption::GetOptionString("extranet", "extranet_site");
265 if (
266 ($extranet_site_id !== '')
267 && \CSite::GetArrayByID($extranet_site_id)
268 )
269 {
270 return $extranet_site_id;
271 }
272
273 return false;
274 }
275
281 public function isAgreementAccepted()
282 {
283 if (!Integration\Bitrix24\Service::isCloud())
284 {
285 return true;
286 }
287
288 return Agreement::isAcceptedByUser($this->getId());
289 }
290
296 public function canEditPhp()
297 {
298 if (Integration\Bitrix24\Service::isCloud())
299 {
300 return false;
301 }
302
303 return $this->getObject()->canDoOperation('edit_php', $this->id);
304 }
305
311 public function canUseLpa()
312 {
313 if (Integration\Bitrix24\Service::isCloud())
314 {
315 return false;
316 }
317
318 return $this->getObject()->canDoOperation('lpa_template_edit', $this->id);
319 }
320
326 public function getObject()
327 {
328 if ($this->object)
329 {
330 return $this->object;
331 }
332
333 if ($this->isCurrent())
334 {
335 $this->object = (is_object($GLOBALS['USER']) && ($GLOBALS['USER'] instanceof \CUser)) ? $GLOBALS['USER'] : null;
336 }
337
338 if (!$this->object)
339 {
340 $this->object = new \CUser();
341 }
342
343 return $this->object;
344 }
345
346 private function isCurrent()
347 {
348 return !$this->id;
349 }
350}
static loadMessages($file)
Definition loc.php:64
static array $cache
Definition user.php:40
$GLOBALS['____1444769544']
Definition license.php:1