Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
user.php
1<?
3
4use \Bitrix\Main\Entity;
6use Bitrix\Socialservices\EncryptedToken\FieldValue;
7
8
25class UserTable extends Entity\DataManager
26{
27 const ALLOW = 'Y';
28 const DISALLOW = 'N';
29
30 const INITIALIZED = 'Y';
31 const NOT_INITIALIZED = 'N';
32
33 private static $deletedList = array();
34
35 public static function getFilePath()
36 {
37 return __FILE__;
38 }
39
40 public static function getTableName()
41 {
42 return 'b_socialservices_user';
43 }
44
45 public static function getMap()
46 {
47 $fieldsMap = array(
48 'ID' => array(
49 'data_type' => 'integer',
50 'primary' => true,
51 'autocomplete' => true,
52 ),
53 'LOGIN' => array(
54 'data_type' => 'string',
55 'required' => true,
56 ),
57 'NAME' => array(
58 'data_type' => 'string',
59 ),
60 'LAST_NAME' => array(
61 'data_type' => 'string',
62 ),
63 'EMAIL' => array(
64 'data_type' => 'string',
65 ),
66 'PERSONAL_PHOTO' => array(
67 'data_type' => 'string',
68 ),
69 'EXTERNAL_AUTH_ID' => array(
70 'data_type' => 'string',
71 'required' => true,
72 ),
73 'USER_ID' => array(
74 'data_type' => 'integer',
75 'required' => true,
76 ),
77 'XML_ID' => array(
78 'data_type' => 'string',
79 'required' => true,
80 ),
81 'CAN_DELETE' => array(
82 'data_type' => 'boolean',
83 'values' => array(self::DISALLOW, self::ALLOW)
84 ),
85 'PERSONAL_WWW' => array(
86 'data_type' => 'string',
87 ),
88 'PERMISSIONS' => array(
89 'data_type' => 'string',
90 'serizalized' => true,
91 ),
92 'OATOKEN' => array(
93 'data_type' => '\\Bitrix\\Socialservices\\EncryptedToken\\CryptoField',
94 'encryption_complete' => static::cryptoEnabled('OATOKEN')
95 ),
96 'OATOKEN_EXPIRES' => array(
97 'data_type' => 'integer',
98 ),
99 'OASECRET' => array(
100 'data_type' => '\\Bitrix\\Socialservices\\EncryptedToken\\CryptoField',
101 'encryption_complete' => static::cryptoEnabled('OASECRET')
102 ),
103 'REFRESH_TOKEN' => array(
104 'data_type' => '\\Bitrix\\Socialservices\\EncryptedToken\\CryptoField',
105 'encryption_complete' => static::cryptoEnabled('REFRESH_TOKEN')
106 ),
107 'SEND_ACTIVITY' => array(
108 'data_type' => 'boolean',
109 'values' => array(self::DISALLOW, self::ALLOW)
110 ),
111 'SITE_ID' => array(
112 'data_type' => 'string',
113 ),
114 'INITIALIZED' => array(
115 'data_type' => 'boolean',
116 'values' => array(self::NOT_INITIALIZED, self::INITIALIZED)
117 ),
118 'USER' => array(
119 'data_type' => 'Bitrix\Main\UserTable',
120 'reference' => array('=this.USER_ID' => 'ref.ID'),
121 ),
122 );
123
124 return $fieldsMap;
125 }
126
127 public static function filterFields($fields, $oldValue = null)
128 {
129 $map = static::getMap();
130 foreach($fields as $key => $value)
131 {
132 if(!array_key_exists($key, $map))
133 {
134 unset($fields[$key]);
135 }
136 elseif($map[$key]['required'] && empty($fields[$key]))
137 {
138 unset($fields[$key]);
139 }
140 }
141
142 if(array_key_exists('PERSONAL_PHOTO', $fields) && is_array($fields['PERSONAL_PHOTO']))
143 {
144 $needUpdatePersonalPhoto = true;
145 $fields['PERSONAL_PHOTO']['MODULE_ID'] = 'socialservices';
146 $fields['PERSONAL_PHOTO']['external_id'] = md5_file($fields['PERSONAL_PHOTO']['tmp_name']);
147 if ($oldValue['PERSONAL_PHOTO'])
148 {
149 $oldPersonalPhoto = \CFile::GetByID($oldValue['PERSONAL_PHOTO'])->Fetch();
150 if ($oldPersonalPhoto['EXTERNAL_ID'] == $fields['PERSONAL_PHOTO']['external_id'])
151 {
152 $needUpdatePersonalPhoto = false;
153 }
154 $fields['PERSONAL_PHOTO']['del'] = 'Y';
155 $fields['PERSONAL_PHOTO']['old_file'] = $oldValue['PERSONAL_PHOTO'];
156 }
157 if ($needUpdatePersonalPhoto)
158 {
159 $fields['PERSONAL_PHOTO'] = \CFile::SaveFile($fields['PERSONAL_PHOTO'], 'socialservices');
160 }
161 else
162 {
163 unset($fields['PERSONAL_PHOTO']);
164 }
165 }
166
167 return $fields;
168 }
169
170 public static function onBeforeDelete(Event $event)
171 {
172 $primary = $event->getParameter("primary");
173 $ID = $primary["ID"];
174 $dbRes = static::getByPrimary($ID);
175 self::$deletedList[$ID] = $dbRes->fetch();
176 }
177
178 public static function onAfterDelete(Event $event)
179 {
180 $primary = $event->getParameter("primary");
181 $ID = $primary["ID"];
182 $userInfo = self::$deletedList[$ID];
183 if($userInfo)
184 {
185 UserLinkTable::deleteBySocserv($userInfo["USER_ID"], $userInfo["ID"]);
186
187 if($userInfo["EXTERNAL_AUTH_ID"] === \CSocServBitrix24Net::ID)
188 {
189 $interface = new \CBitrix24NetOAuthInterface();
190 $interface->setToken($userInfo["OATOKEN"]);
191 $interface->setAccessTokenExpires($userInfo["OATOKEN_EXPIRES"]);
192 $interface->setRefreshToken($userInfo["REFRESH_TOKEN"]);
193
194 if($interface->checkAccessToken() || $interface->getNewAccessToken())
195 {
196 $interface->RevokeAuth();
197 }
198 }
199
200 if($userInfo["PERSONAL_PHOTO"])
201 {
202 \CFile::Delete($userInfo["PERSONAL_PHOTO"]);
203 }
204 }
205 }
206}
getParameter($key)
Definition event.php:80
static filterFields($fields, $oldValue=null)
Definition user.php:127
static onAfterDelete(Event $event)
Definition user.php:178
static onBeforeDelete(Event $event)
Definition user.php:170