Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
helper.php
1<?php
2
4
8
9class Helper
10{
16 public static function getRole(int $id, string $type): Role
17 {
18 switch ($type)
19 {
20 case User::TYPE:
21 return self::getUserRole($id);
22 case Company::TYPE:
23 return self::getCompanyRole($id);
24 case Group::TYPE:
25 return self::getGroupRole($id);
26 default:
27 throw new BaseException('you should send type from Dictionary');
28 }
29 }
30
40 public static function getUserRole(int $id): Role
41 {
42 $user = User::$users[$id] ?? null;
43 if (!$user)
44 {
45 $user = self::getUserObject($id);
46 }
47
48 if ($user)
49 {
50 User::$users[$id] = $user;
51
52 $roleEntity = self::createUserRoleEntity($user);
53
54 return new Role($roleEntity);
55 }
56
57 throw new BaseException('we not find this user');
58 }
59
60 public static function getCompanyRole(int $id): Role
61 {
62 $company = new Company('');
63 return new Role($company);
64 }
65
66 public static function getGroupRole(int $id): Role
67 {
68 $group = new Group('');
69 $group->setId($id);
70 return new Role($group);
71 }
72
79 public static function getAttendeeRole(int $id): Attendee
80 {
81 if (! ($user = User::$users[$id]))
82 {
83 $user = self::getUserObject($id);
84 }
85
86 if ($user)
87 {
88 User::$users[$id] = $user;
89
90 $roleEntity = self::createUserRoleEntity($user);
91
92 return new Attendee($roleEntity);
93 }
94
95 throw new BaseException('we not find this user');
96 }
97
105 public static function getUserObject(int $id): ?Main\EO_User
106 {
107 if (isset(User::$users[$id]) && User::$users[$id])
108 {
109 return User::$users[$id];
110 }
111
112 return UserTable::query()
113 ->addFilter('=ID', $id)
114 ->setSelect(['NAME', 'LAST_NAME', 'ID', 'NOTIFICATION_LANGUAGE_ID', 'EMAIL', 'ACTIVE', 'EXTERNAL_AUTH_ID'])
115 ->exec()
116 ->fetchObject()
117 ;
118 }
119
124 public static function createUserRoleEntity(Main\EO_User $user): User
125 {
126 return (new User($user->getName()))
127 ->setLastName($user->getLastName())
128 ->setId($user->getId())
129 ->setLanguageId($user->get('NOTIFICATION_LANGUAGE_ID') ?? LANGUAGE_ID)
130 ;
131 }
132}
static getCompanyRole(int $id)
Definition helper.php:60
static getGroupRole(int $id)
Definition helper.php:66
static getUserRole(int $id)
Definition helper.php:40
static getAttendeeRole(int $id)
Definition helper.php:79
static getRole(int $id, string $type)
Definition helper.php:16
static getUserObject(int $id)
Definition helper.php:105
static createUserRoleEntity(Main\EO_User $user)
Definition helper.php:124
setLastName(string $lastName=null)
Definition user.php:65