1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
user.php
См. документацию.
1<?php
2namespace Bitrix\Im;
3
4use Bitrix\Im\Model\StatusTable;
5use Bitrix\Main\Localization\Loc;
6use Bitrix\Main\Type\DateTime;
7
8Loc::loadMessages(__FILE__);
9
10class User
11{
12 private static $instance = Array();
13 private $userId = 0;
14 private $userData = null;
15
16 static $formatNameTemplate = null;
17
18 const FILTER_LIMIT = 50;
19
20 const PHONE_ANY = 'phone_any';
21 const PHONE_WORK = 'work_phone';
22 const PHONE_PERSONAL = 'personal_phone';
23 const PHONE_MOBILE = 'personal_mobile';
24 const PHONE_INNER = 'uf_phone_inner';
25
26 const SERVICE_ANY = 'service_any';
27 const SERVICE_ZOOM = 'zoom';
28 const SERVICE_SKYPE = 'skype';
29
30 protected function __construct($userId = null)
31 {
32 global $USER;
33
34 $this->userId = (int)$userId;
35 if ($this->userId <= 0 && is_object($USER) && $USER->GetID() > 0)
36 {
37 $this->userId = (int)$USER->GetID();
38 }
39 }
40
45 public static function getInstance($userId = null): self
46 {
47 global $USER;
48
49 $userId = (int)$userId;
50 if ($userId <= 0 && is_object($USER) && $USER->GetID() > 0)
51 {
52 $userId = (int)$USER->GetID();
53 }
54
55 if (!isset(self::$instance[$userId]))
56 {
57 self::$instance[$userId] = new self($userId);
58 }
59
60 return self::$instance[$userId];
61 }
62
66 public function getId()
67 {
68 return $this->userId;
69 }
70
74 public function getFullName($safe = true)
75 {
76 $fields = $this->getFields();
77 if (!$fields)
78 return '';
79
80 return $safe? $fields['name']: htmlspecialcharsback($fields['name']);
81 }
82
86 public function getName($safe = true)
87 {
88 $fields = $this->getFields();
89 if (!$fields)
90 return '';
91
92 return $safe? $fields['first_name']: htmlspecialcharsback($fields['first_name']);
93 }
94
98 public function getLastName($safe = true)
99 {
100 $fields = $this->getFields();
101 if (!$fields)
102 return '';
103
104 return $safe? $fields['last_name']: htmlspecialcharsback($fields['last_name']);
105 }
106
110 public function getAvatar()
111 {
112 $fields = $this->getFields();
113
114 return $fields && $fields['avatar'] != '/bitrix/js/im/images/blank.gif'? $fields['avatar']: '';
115 }
116
120 public function getAvatarHr()
121 {
122 $fields = $this->getFields();
123 if (!$fields)
124 {
125 return '';
126 }
127
128 return $fields['avatar'];
129 }
130
134 public function getProfile()
135 {
136 $fields = $this->getFields();
137 if (!$fields)
138 {
139 return '';
140 }
141
142 return $fields['profile'];
143 }
144
148 public function getStatus()
149 {
150 $fields = $this->getFields();
151 if (!$fields)
152 {
153 return 'offline';
154 }
155
156 //return $fields['status']?: 'online';
157 return 'online';
158 }
159
163 public function getIdle()
164 {
165 //return $this->getOnlineFields()['idle'];
166 return false;
167 }
168
172 public function getLastActivityDate()
173 {
174 return $this->getOnlineFields()['last_activity_date'];
175 }
176
180 public function getMobileLastDate()
181 {
182 //return $this->getOnlineFields()['mobile_last_date'];
183 return false;
184 }
185
189 public function getBirthday()
190 {
191 $fields = $this->getFields();
192
193 return $fields? $fields['birthday']: '';
194 }
195
199 public function getAvatarId()
200 {
201 $fields = $this->getFields();
202
203 return $fields? $fields['avatar_id']: 0;
204 }
205
209 public function getWorkPosition($safe = false)
210 {
211 $fields = $this->getFields();
212
213 if ($fields)
214 {
215 return $safe? $fields['work_position']: htmlspecialcharsback($fields['work_position']);
216 }
217 else
218 {
219 return false;
220 }
221 }
222
226 public function getGender()
227 {
228 $fields = $this->getFields();
229
230 return $fields? $fields['gender']: '';
231 }
232
236 public function getExternalAuthId()
237 {
238 $fields = $this->getFields();
239
240 return $fields? $fields['external_auth_id']: '';
241 }
242
246 public function getWebsite()
247 {
248 $fields = $this->getFields();
249
250 return $fields? $fields['website']: '';
251 }
252
256 public function getEmail()
257 {
258 $fields = $this->getFields();
259
260 return $fields? $fields['email']: '';
261 }
262
267 public function getPhone($type = self::PHONE_ANY)
268 {
269 $fields = $this->getPhones();
270
271 $result = '';
272 if ($type == self::PHONE_ANY)
273 {
274 if (isset($fields[self::PHONE_MOBILE]))
275 {
276 $result = $fields[self::PHONE_MOBILE];
277 }
278 else if (isset($fields[self::PHONE_PERSONAL]))
279 {
280 $result = $fields[self::PHONE_PERSONAL];
281 }
282 else if (isset($fields[self::PHONE_WORK]))
283 {
284 $result = $fields[self::PHONE_WORK];
285 }
286 }
287 else if (isset($fields[$type]))
288 {
290 }
291
292 return $result;
293 }
294
299 public function getService($type = self::PHONE_ANY)
300 {
301 $fields = $this->getServices();
302
303 $result = '';
304 if ($type == self::SERVICE_ANY)
305 {
306 if (isset($fields[self::SERVICE_SKYPE]))
307 {
308 $result = $fields[self::SERVICE_SKYPE];
309 }
310 else if (isset($fields[self::SERVICE_ZOOM]))
311 {
312 $result = $fields[self::SERVICE_ZOOM];
313 }
314 }
315 else if (isset($fields[$type]))
316 {
318 }
319
320 return $result;
321 }
322
326 public function getColor()
327 {
328 $fields = $this->getFields();
329
330 return $fields? $fields['color']: '';
331 }
332
336 public function isOnline()
337 {
338 $fields = $this->getFields();
339
340 return $fields? $fields['status'] != 'offline': false;
341 }
342
345 public function isExtranet()
346 {
347 $fields = $this->getFields();
348
349 return $fields? (bool)$fields['extranet']: null;
350 }
351
355 public function isActive()
356 {
357 $fields = $this->getFields();
358
359 return $fields? (bool)$fields['active']: null;
360 }
361
365 public function isAbsent()
366 {
367 return \CIMContactList::formatAbsentResult($this->getId());
368 }
369
373 public function isNetwork()
374 {
375 $fields = $this->getFields();
376
377 return $fields? (bool)$fields['network']: null;
378 }
379
383 public function isBot()
384 {
385 $fields = $this->getFields();
386
387 return $fields? (bool)$fields['bot']: null;
388 }
389
393 public function isConnector()
394 {
395 $fields = $this->getFields();
396
397 return $fields? (bool)$fields['connector']: null;
398 }
399
403 public function isExists()
404 {
405 $fields = $this->getFields();
406
407 return $fields? true: false;
408 }
409
413 public function getFields()
414 {
415 $params = $this->getParams();
416
417 return $params? $params['user']: null;
418 }
419
423 public function getPhones()
424 {
425 $params = $this->getFields();
426
427 return $params? $params['phones']: null;
428 }
429
433 public function getServices()
434 {
435 $params = $this->getFields();
436
437 return $params? $params['services']: null;
438 }
439
443 public function getDepartments()
444 {
445 $params = $this->getFields();
446
447 return $params? $params['departments']: Array();
448 }
449
460 public function getArray($options = [])
461 {
462 if (!$this->isExists())
463 {
464 return null;
465 }
466
467 $hrPhotoOption = $options['HR_PHOTO'] ?? null;
468 $livechatOption = $options['LIVECHAT'] ?? null;
469 $jsonOption = $options['JSON'] ?? null;
470 $skipOnlineOption = $options['SKIP_ONLINE'] ?? null;
471
473 ->getArray(['WITHOUT_ONLINE' => $skipOnlineOption === 'Y'])
474 ;
475
476 foreach ($result as $key => $value)
477 {
478 if (
479 in_array($key, ['LAST_ACTIVITY_DATE', 'MOBILE_LAST_DATE', 'DESKTOP_LAST_DATE', 'ABSENT'])
480 && is_string($value)
481 && DateTime::isCorrect($value, \DateTimeInterface::RFC3339)
482 )
483 {
484 $result[$key] = (new DateTime($value, \DateTimeInterface::RFC3339));
485 }
486 }
487
488 //TODO: Live chat, open lines
489 //Just one call, here: \Bitrix\ImOpenLines\Connector::onStartWriting and \Bitrix\Im\Chat::getMessages
490 if ($livechatOption && !$this->isConnector())
491 {
492 $lineId = \Bitrix\ImOpenLines\Queue::getActualLineId(['LINE_ID' => $livechatOption, 'USER_CODE' => $options['USER_CODE']]);
493
494 $imolUserData = \Bitrix\ImOpenLines\Queue::getUserData($lineId, $this->getId());
495 if ($imolUserData)
496 {
497 $result = array_merge($result, $imolUserData);
498 $result['AVATAR_HR'] = $result['AVATAR'];
499 }
500 }
501 //TODO: END: Live chat, open lines
502
503 if ($jsonOption)
504 {
505 $result = self::formatLegacyJson($result);
506 }
507
508 return $result;
509 }
510
511 public static function formatLegacyJson(array $result): array
512 {
513 foreach ($result as $key => $value)
514 {
515 if ($value instanceof \Bitrix\Main\Type\DateTime)
516 {
517 $result[$key] = date('c', $value->getTimestamp());
518 }
519 else if (is_string($value) && is_string($key) && in_array($key, ['AVATAR', 'AVATAR_HR']) && is_string($value) && $value && mb_strpos($value, 'http') !== 0)
520 {
522 }
523 }
524
525 return array_change_key_case($result, CASE_LOWER);
526 }
527
532 public static function getArrayWithOnline(array $users, array $options = ['JSON' => 'Y', 'SKIP_ONLINE' => 'Y']): array
533 {
534 $result = [];
535
536 foreach ($users as $user)
537 {
538 $result[$user->getId()] = $user->getArray($options);
539 }
540
541 $ids = array_keys($result);
542
543 if (empty($ids))
544 {
545 return [];
546 }
547
548 $statuses = StatusTable::query()
549 ->setSelect(['USER_ID', 'IDLE', 'MOBILE_LAST_DATE', 'DESKTOP_LAST_DATE', 'LAST_ACTIVITY_DATE' => 'USER.LAST_ACTIVITY_DATE'])
550 ->whereIn('USER_ID', $ids)
551 ->fetchAll()
552 ;
553
554 foreach ($statuses as $status)
555 {
556 $id = (int)$status['USER_ID'];
557 $result[$id]['last_activity_date'] = $status['LAST_ACTIVITY_DATE'] ? $status['LAST_ACTIVITY_DATE']->format('c') : false;
558 $result[$id]['desktop_last_date'] = $status['DESKTOP_LAST_DATE'] ? $status['DESKTOP_LAST_DATE']->format('c') : false;
559 $result[$id]['mobile_last_date'] = $status['MOBILE_LAST_DATE'] ? $status['MOBILE_LAST_DATE']->format('c') : false;
560 $result[$id]['idle'] = $status['IDLE'] ? $status['IDLE']->format('c') : false;
561 }
562
563 return array_values($result);
564 }
565
569 private function getParams()
570 {
571 if (is_null($this->userData))
572 {
573 $userData = \CIMContactList::GetUserData(Array(
574 'ID' => $this->getId(),
575 'PHONES' => 'Y',
576 'EXTRA_FIELDS' => 'Y',
577 'DATE_ATOM' => 'N',
578 'SHOW_ONLINE' => 'N',
579 ));
580 if (isset($userData['users'][$this->getId()]))
581 {
582 $this->userData['user'] = $userData['users'][$this->getId()];
583 }
584 }
585 return $this->userData;
586 }
587
594 public static function uploadAvatar($avatarUrl = '', $hash = '')
595 {
596 if (!$ar = parse_url($avatarUrl))
597 {
598 return 0;
599 }
600
601 if (!preg_match('#\.(png|jpg|jpeg|gif|webp)$#i', $ar['path'], $matches))
602 {
603 return 0;
604 }
605
606 $hash = md5($hash. $avatarUrl);
607
608 $orm = \Bitrix\Im\Model\ExternalAvatarTable::getList([
609 'select' => ['*', 'FILE_EXISTS' => 'FILE.ID'],
610 'filter' => ['=LINK_MD5' => $hash]
611 ]);
612 if ($cache = $orm->fetch())
613 {
614 if ((int)$cache['FILE_EXISTS'] > 0)
615 {
616 return (int)$cache['AVATAR_ID'];
617 }
618 else
619 {
620 \Bitrix\Im\Model\ExternalAvatarTable::delete((int)$cache['ID']);
621 }
622 }
623
624 try
625 {
626 $tempPath = \CFile::GetTempName('', $hash.'.'.$matches[1]);
627
628 $http = new \Bitrix\Main\Web\HttpClient();
629 $http
630 ->setTimeout(10)
631 ->setStreamTimeout(10);
632
633 if (!defined('BOT_CLIENT_URL'))
634 {
635 $http->setPrivateIp(false);
636 }
637 if ($http->download($avatarUrl, $tempPath))
638 {
639 $recordFile = \CFile::MakeFileArray($tempPath);
640 }
641 else
642 {
643 return 0;
644 }
645 }
646 catch (\Bitrix\Main\IO\IoException $exception)
647 {
648 return 0;
649 }
650
651 if (!\CFile::IsImage($recordFile['name'], $recordFile['type']))
652 {
653 return 0;
654 }
655
656 if (is_array($recordFile) && $recordFile['size'] && $recordFile['size'] > 0 && $recordFile['size'] < 1000000)
657 {
658 $recordFile = array_merge($recordFile, ['MODULE_ID' => 'imbot']);
659 }
660 else
661 {
662 $recordFile = 0;
663 }
664
665 if ($recordFile)
666 {
667 $recordFile = \CFile::SaveFile($recordFile, 'botcontroller', true);
668 }
669
670 if ((int)$recordFile > 0)
671 {
672 \Bitrix\Im\Model\ExternalAvatarTable::add([
673 'LINK_MD5' => $hash,
674 'AVATAR_ID' => (int)$recordFile
675 ]);
676 }
677
678 return $recordFile;
679 }
680
684 public static function clearStaticCache()
685 {
686 self::$instance = Array();
687 return true;
688 }
689
690 public static function isOpenlinesOperator($userId = null)
691 {
692 $userId = \Bitrix\Im\Common::getUserId($userId);
693 if (!$userId)
694 {
695 return false;
696 }
697
698 return \Bitrix\ImOpenLines\Config::isOperator($userId);
699 }
700
701 private function getOnlineFields()
702 {
703 $online = \CIMStatus::GetList(Array('ID' => $this->getId()));
704 if (!$online || !isset($online['users'][$this->getId()]))
705 {
706 return null;
707 }
708
709 $online = $online['users'][$this->getId()];
710
711 return [
712 'id' => $this->getId(),
713 'color' => $online['color']?: '',
714 'idle' => $online['idle']?: false,
715 'last_activity_date' => $online['last_activity_date']?: false,
716 'mobile_last_date' => $online['mobile_last_date']?: false,
717 ];
718 }
719
720 public static function getList($params)
721 {
722 $params = is_array($params)? $params: Array();
723
724 if (!isset($params['CURRENT_USER']) && is_object($GLOBALS['USER']))
725 {
726 $params['CURRENT_USER'] = $GLOBALS['USER']->GetID();
727 }
728
729 $params['CURRENT_USER'] = intval($params['CURRENT_USER']);
730
731 $userId = $params['CURRENT_USER'];
732 if ($userId <= 0)
733 {
734 return false;
735 }
736
737 $enableLimit = false;
738 if (isset($params['OFFSET']))
739 {
740 $filterLimit = intval($params['LIMIT']);
741 $filterLimit = $filterLimit <= 0? self::FILTER_LIMIT: $filterLimit;
742
743 $filterOffset = intval($params['OFFSET']);
744
745 $enableLimit = true;
746 }
747 else
748 {
749 $filterLimit = false;
750 $filterOffset = false;
751 }
752
753 $ormParams = self::getListParams($params);
754 if (is_null($ormParams))
755 {
756 return false;
757 }
758
759 $filter = $ormParams['filter'];
760 $filter['=ACTIVE'] = 'Y';
761
762 $intranetInstalled = \Bitrix\Main\Loader::includeModule('intranet');
763 $voximplantInstalled = \Bitrix\Main\Loader::includeModule('voximplant');
764
765 $select = array(
766 "ID", "LAST_NAME", "NAME", "LOGIN", "PERSONAL_PHOTO", "SECOND_NAME", "PERSONAL_BIRTHDAY", "WORK_POSITION", "PERSONAL_GENDER", "EXTERNAL_AUTH_ID", "WORK_PHONE", "PERSONAL_PHONE", "PERSONAL_MOBILE", "ACTIVE", "LAST_ACTIVITY_DATE",
767 "COLOR" => "ST.COLOR", "STATUS" => "ST.STATUS", "IDLE" => "ST.IDLE", "MOBILE_LAST_DATE" => "ST.MOBILE_LAST_DATE",
768 );
769 if($intranetInstalled)
770 {
771 $select[] = 'UF_PHONE_INNER';
772 $select[] = 'UF_DEPARTMENT';
773 }
774 if ($voximplantInstalled)
775 {
776 $select[] = 'UF_VI_PHONE';
777 }
778
779 $ormParams = Array(
780 'select' => $select,
781 'filter' => $filter,
782 'runtime' => Array(
783 new \Bitrix\Main\Entity\ReferenceField(
784 'ST',
785 '\Bitrix\Im\Model\StatusTable',
786 array(
787 "=ref.USER_ID" => "this.ID",
788 ),
789 array("join_type"=>"LEFT")
790 )
791 ),
792 );
793 if ($enableLimit)
794 {
795 $ormParams['offset'] = $filterOffset;
796 $ormParams['limit'] = $filterLimit;
797 }
798
799 $orm = \Bitrix\Main\UserTable::getList($ormParams);
800 $bots = \Bitrix\Im\Bot::getListCache();
801
802 $users = array();
803 while ($user = $orm->fetch())
804 {
805 if (\CIMContactList::IsExtranet($user))
806 {
807 continue;
808 }
809
810 $color = false;
811 if (isset($user['COLOR']) && $user['COLOR'] <> '')
812 {
813 $color = \Bitrix\Im\Color::getColor($user['COLOR']);
814 }
815 if (!$color)
816 {
817 $color = \CIMContactList::GetUserColor($user["ID"], $user['PERSONAL_GENDER'] == 'M'? 'M': 'F');
818 }
819
820 $users[$user["ID"]] = Array(
821 'ID' => (int)$user["ID"],
824 'LAST_NAME' => $user['LAST_NAME'],
825 'WORK_POSITION' => $user['WORK_POSITION'],
826 'COLOR' => $color,
827 'AVATAR' => \CIMChat::GetAvatarImage($user["PERSONAL_PHOTO"], 200, false),
828 'GENDER' => $user['PERSONAL_GENDER'] == 'F'? 'F': 'M',
829 'BIRTHDAY' => $user['PERSONAL_BIRTHDAY'] instanceof \Bitrix\Main\Type\Date? $user['PERSONAL_BIRTHDAY']->format('d-m'): false,
830 'EXTRANET' => \CIMContactList::IsExtranet($user),
831 'NETWORK' => $user['EXTERNAL_AUTH_ID'] == \CIMContactList::NETWORK_AUTH_ID || $user['EXTERNAL_AUTH_ID'] == \Bitrix\Im\Bot::EXTERNAL_AUTH_ID && $bots[$user["ID"]]['TYPE'] == \Bitrix\Im\Bot::TYPE_NETWORK,
832 'BOT' => $user['EXTERNAL_AUTH_ID'] == \Bitrix\Im\Bot::EXTERNAL_AUTH_ID,
833 'CONNECTOR' => $user['EXTERNAL_AUTH_ID'] == "imconnector",
834 'EXTERNAL_AUTH_ID' => $user['EXTERNAL_AUTH_ID']? $user['EXTERNAL_AUTH_ID']: 'default',
835 'STATUS' => $user['STATUS'],
836 'IDLE' => $user['IDLE'] instanceof \Bitrix\Main\Type\DateTime? $user['IDLE']: false,
837 'LAST_ACTIVITY_DATE' => $user['MOBILE_LAST_DATE'] instanceof \Bitrix\Main\Type\DateTime? $user['MOBILE_LAST_DATE']: false,
838 'MOBILE_LAST_DATE' => $user['LAST_ACTIVITY_DATE'] instanceof \Bitrix\Main\Type\DateTime? $user['LAST_ACTIVITY_DATE']: false,
839 'DEPARTMENTS' => is_array($user['UF_DEPARTMENT']) && !empty($user['UF_DEPARTMENT'])? $user['UF_DEPARTMENT']: [],
840 'ABSENT' => \CIMContactList::formatAbsentResult($user["ID"]),
841 );
842 if ($params['HR_PHOTO'])
843 {
844 $users[$user["ID"]]['AVATAR_HR'] = $users[$user["ID"]]['avatar'];
845 }
846
847 if ($voximplantInstalled)
848 {
849 $user["WORK_PHONE"] = \CVoxImplantPhone::Normalize($user["WORK_PHONE"]);
850 if ($user["WORK_PHONE"])
851 {
852 $users[$user["ID"]]['PHONES']['WORK_PHONE'] = $user['WORK_PHONE'];
853 }
854 $user["PERSONAL_MOBILE"] = \CVoxImplantPhone::Normalize($user["PERSONAL_MOBILE"]);
855 if ($user["PERSONAL_MOBILE"])
856 {
857 $users[$user["ID"]]['PHONES']['PERSONAL_MOBILE'] = $user['PERSONAL_MOBILE'];
858 }
859 $user["PERSONAL_PHONE"] = \CVoxImplantPhone::Normalize($user["PERSONAL_PHONE"]);
860 if ($user["PERSONAL_PHONE"])
861 {
862 $users[$user["ID"]]['PHONES']['PERSONAL_PHONE'] = $user['PERSONAL_PHONE'];
863 }
864 $user["UF_PHONE_INNER"] = preg_replace("/[^0-9\#\*]/i", "", $user["UF_PHONE_INNER"]);
865 if ($user["UF_PHONE_INNER"])
866 {
867 $users[$user["ID"]]['PHONES']['INNER_PHONE'] = $user["UF_PHONE_INNER"];
868 }
869 }
870 else
871 {
872 $users[$user["ID"]]['PHONES']['WORK_PHONE'] = $user['WORK_PHONE'];
873 $users[$user["ID"]]['PHONES']['PERSONAL_MOBILE'] = $user['PERSONAL_MOBILE'];
874 $users[$user["ID"]]['PHONES']['PERSONAL_PHONE'] = $user['PERSONAL_PHONE'];
875 $users[$user["ID"]]['PHONES']['INNER_PHONE'] = $user["UF_PHONE_INNER"];
876 }
877 }
878
879 if ($params['JSON'])
880 {
881 foreach ($users as $key => $userData)
882 {
883 foreach ($userData as $field => $value)
884 {
885 if ($value instanceof \Bitrix\Main\Type\DateTime)
886 {
887 $users[$key][$field] = date('c', $value->getTimestamp());
888 }
889 else if (is_string($value) && $value && is_string($field) && in_array($field, Array('AVATAR', 'AVATAR_HR')) && mb_strpos($value, 'http') !== 0)
890 {
891 $users[$key][$field] = \Bitrix\Im\Common::getPublicDomain().$value;
892 }
893 else if (is_array($value))
894 {
895 $users[$key][$field] = array_change_key_case($value, CASE_LOWER);
896 }
897 }
898 $users[$key] = array_change_key_case($users[$key], CASE_LOWER);;
899 }
900 }
901
902 return $users;
903 }
904
905 public static function getListParams($params)
906 {
907 if (isset($params['FILTER']['SEARCH']))
908 {
909 $filter = \Bitrix\Main\UserUtils::getUserSearchFilter(Array('FIND' => $params['FILTER']['SEARCH']));
910 if (empty($filter))
911 {
912 return null;
913 }
914 }
915 else
916 {
917 $filter = Array();
918 }
919
920 $filter['=ACTIVE'] = 'Y';
921 $filter['=CONFIRM_CODE'] = false;
922 $filter['!=EXTERNAL_AUTH_ID'] = \Bitrix\Im\Model\UserTable::filterExternalUserTypes([\Bitrix\Im\Bot::EXTERNAL_AUTH_ID]);
923
924 $filterByUsers = [];
925
926 if (User::getInstance($params['CURRENT_USER'])->isExtranet())
927 {
929 if (is_array($groups))
930 {
931 foreach ($groups as $group)
932 {
933 foreach ($group['USERS'] as $userId)
934 {
935 $filterByUsers[$userId] = $userId;
936 }
937 }
938 $filterByUsers[$params['CURRENT_USER']] = $params['CURRENT_USER'];
939 }
940 }
941
942 if (
943 $params['FILTER']['BUSINESS'] == 'Y'
944 && \Bitrix\Main\Loader::includeModule('bitrix24')
945 && !\CBitrix24BusinessTools::isLicenseUnlimited()
946 )
947 {
948 $businessUsers = \CBitrix24BusinessTools::getUnlimUsers();
949
950 if (User::getInstance($params['CURRENT_USER'])->isExtranet())
951 {
952 $extranetBusinessResult = [];
953 foreach ($filterByUsers as $userId)
954 {
955 if (in_array($userId, $businessUsers))
956 {
957 $extranetBusinessResult[$userId] = $userId;
958 }
959 }
960 $filterByUsers = $extranetBusinessResult;
961 }
962 else
963 {
964 foreach ($businessUsers as $userId)
965 {
966 $filterByUsers[$userId] = $userId;
967 }
968 }
969 }
970
971 if ($filterByUsers)
972 {
973 $filter['=ID'] = array_keys($filterByUsers);
974 }
975
976 return ['filter' => $filter];
977 }
978
979 public static function getBusiness($userId = null, $options = array())
980 {
981 $userId = \Bitrix\Im\Common::getUserId($userId);
982 if (!$userId)
983 {
984 return false;
985 }
986
987 $pagination = isset($options['LIST'])? true: false;
988
989 $limit = isset($options['LIST']['LIMIT'])? intval($options['LIST']['LIMIT']): 50;
990 $offset = isset($options['LIST']['OFFSET'])? intval($options['LIST']['OFFSET']): 0;
991
992 $list = Array();
993
994 $businessUsersAvailable = false;
995 if (\Bitrix\Main\Loader::includeModule('bitrix24') && !\CBitrix24BusinessTools::isLicenseUnlimited())
996 {
997 $businessUsers = \CBitrix24BusinessTools::getUnlimUsers();
998
999 if (User::getInstance($userId)->isExtranet())
1000 {
1001 $extranetBusinessResult = [];
1003 if (is_array($groups))
1004 {
1005 foreach ($groups as $group)
1006 {
1007 foreach ($group['USERS'] as $uid)
1008 {
1009 if (in_array($uid, $businessUsers))
1010 {
1011 $extranetUserList[$uid] = $uid;
1012 }
1013 }
1014 }
1015 }
1016 $list = $extranetBusinessResult;
1017 }
1018 else
1019 {
1020 foreach ($businessUsers as $userId)
1021 {
1022 $list[$userId] = $userId;
1023 }
1024 }
1025
1026 $businessUsersAvailable = true;
1027 }
1028
1029 $count = count($list);
1030
1031 $list = array_slice($list, $offset, $limit);
1032
1033 if ($options['USER_DATA'] == 'Y')
1034 {
1035 $result = Array();
1036
1037 $getOptions = Array();
1038 if ($options['JSON'] == 'Y')
1039 {
1040 $getOptions['JSON'] = 'Y';
1041 }
1042
1043 foreach ($list as $userId)
1044 {
1045 $result[] = \Bitrix\Im\User::getInstance($userId)->getArray($getOptions);
1046 }
1047 }
1048 else
1049 {
1050 $result = array_values($list);
1051 }
1052
1053 if ($pagination)
1054 {
1055 $result = Array('TOTAL' => $count, 'RESULT' => $result, 'AVAILABLE' => $businessUsersAvailable);
1056
1057 if ($options['JSON'] == 'Y')
1058 {
1059 $result = array_change_key_case($result, CASE_LOWER);
1060 }
1061 }
1062 else
1063 {
1064 if (!$businessUsersAvailable)
1065 {
1066 $result = false;
1067 }
1068 }
1069
1070 return $result;
1071 }
1072
1073 public static function getMessages($userId = null, $options = Array())
1074 {
1075 $userId = \Bitrix\Im\Common::getUserId($userId);
1076 if (!$userId)
1077 {
1078 return false;
1079 }
1080
1081
1082 $filter = Array(
1083 '=AUTHOR_ID' => $userId
1084 );
1085
1086 if (isset($options['FIRST_ID']))
1087 {
1088 $order = array();
1089
1090 if (intval($options['FIRST_ID']) > 0)
1091 {
1092 $filter['>ID'] = $options['FIRST_ID'];
1093 }
1094 }
1095 else
1096 {
1097 $order = Array('ID' => 'DESC');
1098
1099 if (isset($options['LAST_ID']) && intval($options['LAST_ID']) > 0)
1100 {
1101 $filter['<ID'] = intval($options['LAST_ID']);
1102 }
1103 }
1104
1105 if (isset($options['LIMIT']))
1106 {
1107 $options['LIMIT'] = intval($options['LIMIT']);
1108 $limit = $options['LIMIT'] >= 500? 500: $options['LIMIT'];
1109 }
1110 else
1111 {
1112 $limit = 50;
1113 }
1114
1115 $skipMessage = isset($options['SKIP_MESSAGE']) && $options['SKIP_MESSAGE'] == 'Y';
1116
1117 $select = Array(
1118 'ID', 'CHAT_ID', 'DATE_CREATE',
1119 'CHAT_TITLE' => 'CHAT.TITLE'
1120 );
1121 if (!$skipMessage)
1122 {
1123 $select[] = 'MESSAGE';
1124 }
1125
1126 $orm = \Bitrix\Im\Model\MessageTable::getList(array(
1127 'filter' => $filter,
1128 'select' => $select,
1129 'order' => $order,
1130 'limit' => $limit
1131 ));
1132
1133 $messages = Array();
1134 $messagesChat = Array();
1135 while($message = $orm->fetch())
1136 {
1137 $messages[$message['ID']] = Array(
1138 'ID' => (int)$message['ID'],
1139 'DATE' => $message['DATE_CREATE'],
1140 'TEXT' => (string)$message['MESSAGE'],
1141 );
1142
1143 if ($skipMessage)
1144 {
1145 unset($messages[$message['ID']]['TEXT']);
1146 }
1147
1148 $messagesChat[$message['ID']] = Array(
1149 'ID' => (int)$message['ID'],
1150 'CHAT_ID' => (int)$message['CHAT_ID']
1151 );
1152 }
1153
1154 $params = \CIMMessageParam::Get(array_keys($messages));
1155
1156 $fileIds = Array();
1157 foreach ($params as $messageId => $param)
1158 {
1159 $messages[$messageId]['params'] = empty($param)? null: $param;
1160
1161 if (isset($param['FILE_ID']))
1162 {
1163 foreach ($param['FILE_ID'] as $fileId)
1164 {
1165 $fileIds[$messagesChat[$messageId]['CHAT_ID']][$fileId] = $fileId;
1166 }
1167 }
1168 }
1169
1171
1172 $files = array();
1173 foreach ($fileIds as $chatId => $fileId)
1174 {
1175 if ($result = \CIMDisk::GetFiles($chatId, $fileId))
1176 {
1177 $files = array_merge($files, $result);
1178 }
1179 }
1180
1181 $result = Array(
1182 'MESSAGES' => $messages,
1183 'FILES' => $files,
1184 );
1185
1186 if ($options['JSON'])
1187 {
1188 foreach ($result['MESSAGES'] as $key => $value)
1189 {
1190 if ($value['DATE'] instanceof \Bitrix\Main\Type\DateTime)
1191 {
1192 $result['MESSAGES'][$key]['DATE'] = date('c', $value['DATE']->getTimestamp());
1193 }
1194
1195 $result['MESSAGES'][$key] = array_change_key_case($result['MESSAGES'][$key], CASE_LOWER);
1196 }
1197 $result['MESSAGES'] = array_values($result['MESSAGES']);
1198
1199 foreach ($result['FILES'] as $key => $value)
1200 {
1201 if ($value['date'] instanceof \Bitrix\Main\Type\DateTime)
1202 {
1203 $result['FILES'][$key]['date'] = date('c', $value['date']->getTimestamp());
1204 }
1205
1206 foreach (['urlPreview', 'urlShow', 'urlDownload'] as $field)
1207 {
1208 $url = $result['FILES'][$key][$field];
1209 if (is_string($url) && $url && mb_strpos($url, 'http') !== 0)
1210 {
1211 $result['FILES'][$key][$field] = \Bitrix\Im\Common::getPublicDomain().$url;
1212 }
1213 }
1214 }
1215
1216 $result = array_change_key_case($result, CASE_LOWER);
1217 }
1218
1219 return $result;
1220 }
1221
1222 public static function formatNameFromDatabase($fields)
1223 {
1224 if (empty($fields['NAME']) && empty($fields['LAST_NAME']))
1225 {
1226 if (in_array($fields['EXTERNAL_AUTH_ID'], \Bitrix\Main\UserTable::getExternalUserTypes()))
1227 {
1228 return Loc::getMessage('IM_USER_GUEST_NAME');
1229 }
1230 else if (!empty($fields['LOGIN']))
1231 {
1232 return $fields['LOGIN'];
1233 }
1234 else
1235 {
1236 return Loc::getMessage('IM_USER_ANONYM_NAME');
1237 }
1238 }
1239
1240 return $fields['NAME'];
1241 }
1242
1243 public static function formatFullNameFromDatabase($fields)
1244 {
1245 if (is_null(self::$formatNameTemplate))
1246 {
1247 self::$formatNameTemplate = \CSite::GetNameFormat(false);
1248 }
1249
1250 if (empty($fields['NAME']) && empty($fields['LAST_NAME']))
1251 {
1252 if (in_array($fields['EXTERNAL_AUTH_ID'], \Bitrix\Main\UserTable::getExternalUserTypes()))
1253 {
1254 return Loc::getMessage('IM_USER_GUEST_NAME');
1255 }
1256 else if (!empty($fields['LOGIN']))
1257 {
1258 return $fields['LOGIN'];
1259 }
1260 else
1261 {
1262 return Loc::getMessage('IM_USER_ANONYM_NAME');
1263 }
1264 }
1265
1266 return \CUser::FormatName(self::$formatNameTemplate, $fields, true, false);
1267 }
1268
1269 public static function setInstance($userId, $instance)
1270 {
1271 $c = __CLASS__;
1272 if ($instance instanceof $c)
1273 {
1274 self::$instance[$userId] = $instance;
1275 }
1276 }
1277}
$count
Определения admin_tab.php:4
$hash
Определения ajax_redirector.php:8
$type
Определения options.php:106
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
Определения callback_ismscenter.php:26
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getColor($code)
Определения color.php:121
static getUserId($userId=null)
Определения common.php:73
static getPublicDomain()
Определения common.php:8
static getGroup($params, $userId=null, bool $filterActiveUser=true)
Определения extranet.php:15
static filterExternalUserTypes(array $skipTypes=[])
Определения user.php:31
getWorkPosition($safe=false)
Определения user.php:209
static getMessages($userId=null, $options=Array())
Определения user.php:1073
static formatFullNameFromDatabase($fields)
Определения user.php:1243
getEmail()
Определения user.php:256
const SERVICE_SKYPE
Определения user.php:28
getFullName($safe=true)
Определения user.php:74
static getList($params)
Определения user.php:720
getAvatar()
Определения user.php:110
getId()
Определения user.php:66
static isOpenlinesOperator($userId=null)
Определения user.php:690
isBot()
Определения user.php:383
isOnline()
Определения user.php:336
getAvatarId()
Определения user.php:199
static formatNameFromDatabase($fields)
Определения user.php:1222
const PHONE_WORK
Определения user.php:21
getName($safe=true)
Определения user.php:86
static uploadAvatar($avatarUrl='', $hash='')
Определения user.php:594
getServices()
Определения user.php:433
const PHONE_PERSONAL
Определения user.php:22
getBirthday()
Определения user.php:189
const FILTER_LIMIT
Определения user.php:18
const SERVICE_ZOOM
Определения user.php:27
isNetwork()
Определения user.php:373
getLastName($safe=true)
Определения user.php:98
const PHONE_MOBILE
Определения user.php:23
getPhones()
Определения user.php:423
getIdle()
Определения user.php:163
getLastActivityDate()
Определения user.php:172
static getInstance($userId=null)
Определения user.php:45
getDepartments()
Определения user.php:443
const PHONE_ANY
Определения user.php:20
isAbsent()
Определения user.php:365
static clearStaticCache()
Определения user.php:684
static getListParams($params)
Определения user.php:905
isConnector()
Определения user.php:393
const PHONE_INNER
Определения user.php:24
getStatus()
Определения user.php:148
const SERVICE_ANY
Определения user.php:26
static $formatNameTemplate
Определения user.php:16
isActive()
Определения user.php:355
getColor()
Определения user.php:326
isExtranet()
Определения user.php:345
getPhone($type=self::PHONE_ANY)
Определения user.php:267
static getBusiness($userId=null, $options=array())
Определения user.php:979
getAvatarHr()
Определения user.php:120
__construct($userId=null)
Определения user.php:30
getMobileLastDate()
Определения user.php:180
getProfile()
Определения user.php:134
static setInstance($userId, $instance)
Определения user.php:1269
static getArrayWithOnline(array $users, array $options=['JSON'=> 'Y', 'SKIP_ONLINE'=> 'Y'])
Определения user.php:532
getArray($options=[])
Определения user.php:460
isExists()
Определения user.php:403
getService($type=self::PHONE_ANY)
Определения user.php:299
getGender()
Определения user.php:226
static formatLegacyJson(array $result)
Определения user.php:511
getExternalAuthId()
Определения user.php:236
getWebsite()
Определения user.php:246
getFields()
Определения user.php:413
static getInstance(?int $id)
Определения User.php:72
static includeModule($moduleName)
Определения loader.php:67
static getList(array $parameters=array())
Определения datamanager.php:431
Определения date.php:9
static getUserSearchFilter(array $fields)
Определения userutils.php:18
static GetFiles($chatId, $fileId=false, $checkPermission=true)
Определения im_disk.php:1601
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$uid
Определения hot_keys_act.php:8
$select
Определения iblock_catalog_list.php:194
$filter
Определения iblock_catalog_list.php:54
global $USER
Определения csv_new_run.php:40
$groups
Определения options.php:30
$status
Определения session.php:10
htmlspecialcharsback($str)
Определения tools.php:2693
Определения ufield.php:9
Определения directory.php:3
Определения collection.php:2
$user
Определения mysql_to_pgsql.php:33
$files
Определения mysql_to_pgsql.php:30
$GLOBALS['____1690880296']
Определения license.php:1
$order
Определения payment.php:8
$message
Определения payment.php:8
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$messages
Определения template.php:8
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$matches
Определения index.php:22
$url
Определения iframe.php:7
$fields
Определения yandex_run.php:501