1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
helper.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Core\Role;
4
5use Bitrix\Calendar\Core\Base\BaseException;
6use Bitrix\Calendar\Core\Event\Tools\Dictionary;
7use Bitrix\Main\UserTable;
8use Bitrix\Main;
9
10class Helper
11{
17 public static function getRole(int $id, string $type): Role
18 {
19 switch ($type)
20 {
21 case Dictionary::CALENDAR_TYPE['open_event']:
22 case User::TYPE:
23 return self::getUserRole($id);
24 case Company::TYPE:
25 return self::getCompanyRole($id);
26 case Group::TYPE:
27 return self::getGroupRole($id);
28 default:
29 throw new BaseException('you should send type from Dictionary');
30 }
31 }
32
42 public static function getUserRole(int $id): Role
43 {
44 $user = User::$users[$id] ?? null;
45 if (!$user)
46 {
48 }
49
50 if ($user)
51 {
52 User::$users[$id] = $user;
53
54 $roleEntity = self::createUserRoleEntity($user);
55
56 return new Role($roleEntity);
57 }
58
59 throw new BaseException('we not find this user');
60 }
61
62 public static function getCompanyRole(int $id): Role
63 {
64 $company = new Company('');
65 return new Role($company);
66 }
67
68 public static function getGroupRole(int $id): Role
69 {
70 $group = new Group('');
71 $group->setId($id);
72 return new Role($group);
73 }
74
81 public static function getAttendeeRole(int $id): Attendee
82 {
83 if (! ($user = User::$users[$id]))
84 {
86 }
87
88 if ($user)
89 {
90 User::$users[$id] = $user;
91
92 $roleEntity = self::createUserRoleEntity($user);
93
94 return new Attendee($roleEntity);
95 }
96
97 throw new BaseException('we not find this user');
98 }
99
107 public static function getUserObject(int $id): ?Main\EO_User
108 {
109 if (isset(User::$users[$id]) && User::$users[$id])
110 {
111 return User::$users[$id];
112 }
113
114 return UserTable::query()
115 ->addFilter('=ID', $id)
116 ->setSelect(['NAME', 'LAST_NAME', 'ID', 'NOTIFICATION_LANGUAGE_ID', 'EMAIL', 'ACTIVE', 'EXTERNAL_AUTH_ID'])
117 ->exec()
118 ->fetchObject()
119 ;
120 }
121
126 public static function createUserRoleEntity(Main\EO_User $user): User
127 {
128 return (new User($user->getName()))
129 ->setLastName($user->getLastName())
130 ->setId($user->getId())
131 ->setLanguageId($user->get('NOTIFICATION_LANGUAGE_ID') ?? LANGUAGE_ID)
132 ;
133 }
134}
$type
Определения options.php:106
const TYPE
Определения group.php:7
static getCompanyRole(int $id)
Определения helper.php:62
static getGroupRole(int $id)
Определения helper.php:68
static getUserRole(int $id)
Определения helper.php:42
static getAttendeeRole(int $id)
Определения helper.php:81
static getRole(int $id, string $type)
Определения helper.php:17
static getUserObject(int $id)
Определения helper.php:107
static createUserRoleEntity(Main\EO_User $user)
Определения helper.php:126
const TYPE
Определения user.php:9
static array $users
Определения user.php:14
setLastName(string $lastName=null)
Определения user.php:65
Определения orm.php:16144
$user
Определения mysql_to_pgsql.php:33