Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usertable.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 ),
91 'OATOKEN' => array(
92 'data_type' => '\\Bitrix\\Socialservices\\EncryptedToken\\CryptoField',
93 'encryption_complete' => static::cryptoEnabled('OATOKEN')
94 ),
95 'OATOKEN_EXPIRES' => array(
96 'data_type' => 'integer',
97 ),
98 'OASECRET' => array(
99 'data_type' => '\\Bitrix\\Socialservices\\EncryptedToken\\CryptoField',
100 'encryption_complete' => static::cryptoEnabled('OASECRET')
101 ),
102 'REFRESH_TOKEN' => array(
103 'data_type' => '\\Bitrix\\Socialservices\\EncryptedToken\\CryptoField',
104 'encryption_complete' => static::cryptoEnabled('REFRESH_TOKEN')
105 ),
106 'SEND_ACTIVITY' => array(
107 'data_type' => 'boolean',
108 'values' => array(self::DISALLOW, self::ALLOW)
109 ),
110 'SITE_ID' => array(
111 'data_type' => 'string',
112 ),
113 'INITIALIZED' => array(
114 'data_type' => 'boolean',
115 'values' => array(self::NOT_INITIALIZED, self::INITIALIZED)
116 ),
117 'USER' => array(
118 'data_type' => 'Bitrix\Main\UserTable',
119 'reference' => array('=this.USER_ID' => 'ref.ID'),
120 ),
121 );
122
123 return $fieldsMap;
124 }
125
126 public static function filterFields($fields, $oldValue = null)
127 {
128 $map = static::getMap();
129 foreach($fields as $key => $value)
130 {
131 if(!array_key_exists($key, $map))
132 {
133 unset($fields[$key]);
134 }
135 elseif(isset($map[$key]['required']) && $map[$key]['required'] && empty($fields[$key]))
136 {
137 unset($fields[$key]);
138 }
139 }
140
141 if(array_key_exists('PERSONAL_PHOTO', $fields) && is_array($fields['PERSONAL_PHOTO']))
142 {
143 $needUpdatePersonalPhoto = true;
144 $fields['PERSONAL_PHOTO']['MODULE_ID'] = 'socialservices';
145 $fields['PERSONAL_PHOTO']['external_id'] = md5_file($fields['PERSONAL_PHOTO']['tmp_name']);
146 if ($oldValue['PERSONAL_PHOTO'])
147 {
148 $oldPersonalPhoto = \CFile::GetByID($oldValue['PERSONAL_PHOTO'])->Fetch();
149 if ($oldPersonalPhoto['EXTERNAL_ID'] == $fields['PERSONAL_PHOTO']['external_id'])
150 {
151 $needUpdatePersonalPhoto = false;
152 }
153 $fields['PERSONAL_PHOTO']['del'] = 'Y';
154 $fields['PERSONAL_PHOTO']['old_file'] = $oldValue['PERSONAL_PHOTO'];
155 }
156 if ($needUpdatePersonalPhoto)
157 {
158 $fields['PERSONAL_PHOTO'] = \CFile::SaveFile($fields['PERSONAL_PHOTO'], 'socialservices');
159 }
160 else
161 {
162 unset($fields['PERSONAL_PHOTO']);
163 }
164 }
165
166 return $fields;
167 }
168
169 public static function onBeforeDelete(Event $event)
170 {
171 $primary = $event->getParameter("primary");
172 $ID = $primary["ID"];
173 $dbRes = static::getByPrimary($ID);
174 self::$deletedList[$ID] = $dbRes->fetch();
175 }
176
177 public static function onAfterDelete(Event $event)
178 {
179 $primary = $event->getParameter("primary");
180 $ID = $primary["ID"];
181 $userInfo = self::$deletedList[$ID];
182 if($userInfo)
183 {
184 UserLinkTable::deleteBySocserv($userInfo["USER_ID"], $userInfo["ID"]);
185
186 if($userInfo["EXTERNAL_AUTH_ID"] === \CSocServBitrix24Net::ID)
187 {
188 $interface = new \CBitrix24NetOAuthInterface();
189 $interface->setToken($userInfo["OATOKEN"]);
190 $interface->setAccessTokenExpires($userInfo["OATOKEN_EXPIRES"]);
191 $interface->setRefreshToken($userInfo["REFRESH_TOKEN"]);
192
193 if($interface->checkAccessToken() || $interface->getNewAccessToken())
194 {
195 $interface->RevokeAuth();
196 }
197 }
198
199 if($userInfo["PERSONAL_PHOTO"])
200 {
201 \CFile::Delete($userInfo["PERSONAL_PHOTO"]);
202 }
203 }
204 }
205}
getParameter($key)
Definition event.php:80
static filterFields($fields, $oldValue=null)
static onAfterDelete(Event $event)
static onBeforeDelete(Event $event)