Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
callback.php
1<?php
10
11
15
17{
18 const USER_TYPE_ID_PREFIX = 'rest';
19
20 protected static $descriptionCache = null;
21
22 public static function __callStatic($handlerCode, $arguments)
23 {
24 $userTypeDescription = static::getUserTypeDescription($handlerCode);
25
26 if($userTypeDescription === null)
27 {
28 static::unbindByCode($handlerCode);
29 }
30
31 return $userTypeDescription;
32 }
33
34 public static function bind($fields)
35 {
36 global $USER_FIELD_MANAGER;
37
38 $eventManager = EventManager::getInstance();
39 $eventManager->registerEventHandlerCompatible('main', 'OnUserTypeBuildList', 'rest', __CLASS__, static::getUserTypeId($fields));
40
41 $USER_FIELD_MANAGER->CleanCache();
42 static::$descriptionCache = null;
43 \Bitrix\Rest\PlacementTable::clearHandlerCache();
44 }
45
46 public static function unbind($fields)
47 {
48 static::unbindByCode(static::getUserTypeId($fields));
49 }
50
51 public static function unbindByCode($handlerCode)
52 {
53 global $USER_FIELD_MANAGER;
54
55 $eventManager = EventManager::getInstance();
56 $eventManager->unRegisterEventHandler('main', 'OnUserTypeBuildList', 'rest', __CLASS__, $handlerCode);
57
58 $USER_FIELD_MANAGER->CleanCache();
59 static::$descriptionCache = null;
60 \Bitrix\Rest\PlacementTable::clearHandlerCache();
61 }
62
63 protected static function getUserTypeDescription($placementHandlerCode)
64 {
65 if(static::$descriptionCache === null)
66 {
67 static::$descriptionCache = array();
68
69 $placementHandlerList = PlacementTable::getHandlersList(UserFieldType::PLACEMENT_UF_TYPE, true);
70 foreach($placementHandlerList as $placementInfo)
71 {
72 static::$descriptionCache[static::getUserTypeId($placementInfo)] = array(
73 'USER_TYPE_ID' => static::getUserTypeId($placementInfo),
74 'CLASS_NAME' => '\Bitrix\Rest\UserField\Type',
75 'DESCRIPTION' => $placementInfo['TITLE'],
76 'BASE_TYPE' => \CUserTypeManager::BASE_TYPE_STRING,
77 'VIEW_CALLBACK' => array('\Bitrix\Rest\UserField\Type', 'getPublicView'),
78 'EDIT_CALLBACK' => array('\Bitrix\Rest\UserField\Type', 'getPublicEdit'),
79 );
80 }
81 }
82
83 return array_key_exists($placementHandlerCode, static::$descriptionCache)
84 ? static::$descriptionCache[$placementHandlerCode]
85 : null;
86 }
87
88 public static function getUserTypeId($userTypeInfo)
89 {
90 return static::USER_TYPE_ID_PREFIX.'_'.$userTypeInfo['APP_ID'].'_'.$userTypeInfo['ADDITIONAL'];
91 }
92}
static getHandlersList($placement, $skipInstallCheck=false, int $userId=null)
static getUserTypeId($userTypeInfo)
Definition callback.php:88
static unbindByCode($handlerCode)
Definition callback.php:51
static __callStatic($handlerCode, $arguments)
Definition callback.php:22
static getUserTypeDescription($placementHandlerCode)
Definition callback.php:63