5use Bitrix\Main\Localization\Loc;
6use Bitrix\Main\ORM\Fields\ArrayField;
7use Bitrix\Main\ORM\Fields\Relations\OneToMany;
8use Bitrix\Main\EventManager;
10use Bitrix\Rest\UserField\Callback;
13Loc::loadMessages(__FILE__);
61 private static $beforeDeleteList = [];
70 return 'b_rest_placement';
82 'data_type' =>
'integer',
84 'autocomplete' =>
true,
87 'data_type' =>
'integer',
90 'data_type' =>
'integer',
93 'data_type' =>
'string',
96 'PLACEMENT_HANDLER' =>
array(
97 'data_type' =>
'string',
104 'GROUP_NAME' =>
array(
105 'data_type' =>
'string',
108 'data_type' =>
'integer',
115 'data_type' =>
'string',
122 'data_type' =>
'string',
124 'DATE_CREATE' =>
array(
125 'data_type' =>
'datetime',
127 'ADDITIONAL' =>
array(
128 'data_type' =>
'string',
132 'data_type' =>
'Bitrix\Rest\AppTable',
133 'reference' =>
array(
'=this.APP_ID' =>
'ref.ID'),
139 ))->configureJoinType(
'left'),
143 private static function getUserFilter(
$userId)
148 if (
$USER instanceof \CUser)
157 static::DEFAULT_USER_ID_VALUE,
163 $result = static::DEFAULT_USER_ID_VALUE;
181 '=PLACEMENT' => $placement,
183 '=USER_ID' => static::getUserFilter(
$userId),
194 'INSTALLED' =>
'REST_APP.INSTALLED',
195 'APP_NAME' =>
'REST_APP.APP_NAME',
196 'APP_ACCESS' =>
'REST_APP.ACCESS',
216 $res = static::getList(
219 '=APP_ID' => (
int)$appId,
234 while ($placement =
$res->fetch())
236 $eventList[] =
new Event(
238 static::PREFIX_EVENT_ON_AFTER_DELETE . $placement[
'PLACEMENT'],
240 'ID' => $placement[
'ID'],
241 'PLACEMENT' => $placement[
'PLACEMENT'],
246 $queryResult =
$connection->query(
"DELETE FROM ".static::getTableName().
" WHERE APP_ID='".intval($appId).
"'");
248 foreach ($eventList as
$event)
250 EventManager::getInstance()->send(
$event);
253 static::clearHandlerCache();
268 if(!array_key_exists($placement, static::$handlersListCache))
270 static::$handlersListCache[$placement] =
array();
273 if($cache->read(static::CACHE_TTL, static::getCacheId($placement), static::CACHE_DIR))
275 static::$handlersListCache = $cache->get(static::getCacheId($placement));
280 foreach (
$res->fetchCollection() as $handler)
282 $id = $handler->getId();
283 $app = $handler->getRestApp();
286 'APP_ID' => $handler->getAppId(),
287 'USER_ID' => $handler->getUserId(),
288 'ICON_ID' => $handler->getIconId(),
289 'ADDITIONAL' => $handler->getAdditional(),
298 'OPTIONS' => $handler->getOptions(),
299 'INSTALLED' =>
$app->getInstalled(),
300 'APP_NAME' =>
$app->getAppName(),
301 'APP_ACCESS' =>
$app->getAccess(),
305 if ($placementItem[
'ICON_ID'] > 0 && ($file = \CFile::GetFileArray($placementItem[
'ICON_ID'])))
307 $placementItem[
'ICON'] = array_change_key_case($file, CASE_LOWER);
310 $handler->fillLangAll();
311 if (!is_null($handler->getLangAll()))
313 foreach ($handler->getLangAll() as
$lang)
315 $placementItem[
'LANG_ALL'][
$lang->getLanguageId()] = [
316 'TITLE' =>
$lang->getTitle(),
317 'DESCRIPTION' =>
$lang->getDescription(),
318 'GROUP_NAME' =>
$lang->getGroupName(),
322 static::$handlersListCache[$placement][] = $placementItem;
325 $cache->set(static::getCacheId($placement), static::$handlersListCache);
329 $result = static::$handlersListCache[$placement];
338 $placement !==
Api\UserFieldType::PLACEMENT_UF_TYPE
339 && !\CRestUtil::checkAppAccess($handler[
'APP_ID'],
array(
340 'ACCESS' => $handler[
'APP_ACCESS']
352 $result[
$key][
'TITLE'] = static::getDefaultTitle($handler[
'ID']);
371 return Loc::getMessage(
372 'REST_PLACEMENT_DEFAULT_TITLE',
374 '#ID#' => $placementId,
383 $cache->cleanDir(static::CACHE_DIR);
384 static::$handlersListCache =
array();
385 if (defined(
'BX_COMP_MANAGED_CACHE'))
409 $id =
$event->getParameter(
'id');
410 $id = (int)$id[
'ID'];
411 $res = static::getList(
428 if ($placement =
$res->fetch())
430 static::$beforeDeleteList[$placement[
'ID']] = $placement;
431 if ((
int)$placement[
'ICON_ID'] > 0)
433 \CFile::Delete((
int)$placement[
'ICON_ID']);
451 static::PREFIX_EVENT_ON_AFTER_ADD .
$fields[
'PLACEMENT'],
453 'ID' =>
$event->getParameter(
'id'),
454 'PLACEMENT' =>
$fields[
'PLACEMENT'],
457 EventManager::getInstance()->send(
$data);
461 static::clearHandlerCache();
466 static::clearHandlerCache();
471 $id =
$event->getParameter(
'id');
472 $id = (int)$id[
'ID'];
477 static::PREFIX_EVENT_ON_AFTER_DELETE . static::$beforeDeleteList[$id][
'PLACEMENT'],
480 'PLACEMENT' => static::$beforeDeleteList[$id][
'PLACEMENT'],
483 unset(static::$beforeDeleteList[$id]);
484 EventManager::getInstance()->send(
$data);
487 static::clearHandlerCache();
492 return 'rest_placement_list|'.$placement.
'|'.LANGUAGE_ID;
497 $result =
new Main\Entity\EventResult();
501 '=APP_ID' =>
$data[
'APP_ID'],
502 '=PLACEMENT' =>
$data[
'PLACEMENT'],
503 '=PLACEMENT_HANDLER' =>
$data[
'PLACEMENT_HANDLER'],
506 if(!empty(
$data[
'ADDITIONAL']))
517 'select' =>
array(
'ID')
523 "Handler already binded"
542 if (array_key_exists(
'ICON',
$data))
544 if (
$str = \CFile::CheckImageFile(
$data[
'ICON']))
550 \CFile::ResizeImage(
$data[
'ICON'], [
551 'width' =>
Main\Config\Option::get(
'rest',
'icon_size', 100),
552 'height' =>
Main\Config\Option::get(
'rest',
'icon_size', 100)]);
553 $data[
'ICON'][
'MODULE_ID'] =
'rest';
554 if ($id =
$event->getParameter(
'id'))
556 $id = is_integer($id) ? $id : $id[
'ID'];
557 if ($id > 0 && ($icon = PlacementTable::getById($id)->fetchObject()))
559 $data[
'ICON'][
'old_file'] = $icon->getIconId();
562 if (\CFile::SaveForDB(
$data,
'ICON',
'rest/placementicon'))
564 $fieldChanged[
'ICON_ID'] =
$data[
'ICON'];
570 if (array_key_exists(
'DESCRIPTION',
$data))
572 $fieldChanged[
'COMMENT'] =
$data[
'DESCRIPTION'];
573 $result->unsetField(
'DESCRIPTION');
576 if (!empty($fieldChanged))
578 $result->modifyFields(array_merge(
$result->getModified(), $fieldChanged));
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getConnection($name="")
static getByClientId($clientId)
static mergeFromLangAll($data)
static deleteByPlacement(int $placementId)
static deleteByApp(int $appId)
static getCacheId($placement)
static clearHandlerCache()
const ERROR_PLACEMENT_MAX_COUNT
static $handlersListCache
static onBeforeAdd(Main\Entity\Event $event)
static onAfterDelete(Main\Entity\Event $event)
static checkUniq(Main\Entity\Event $event, $add=false)
const PREFIX_EVENT_ON_AFTER_DELETE
static getDefaultTitle(int $placementId, $language=null)
static onBeforeDelete(Main\Entity\Event $event)
static onAfterUpdate(Main\Entity\Event $event)
static getHandlersList($placement, $skipInstallCheck=false, int $userId=null)
static onBeforeUpdate(Main\Entity\Event $event)
static deleteByApp($appId)
const ERROR_PLACEMENT_NOT_FOUND
static onAfterAdd(Main\Entity\Event $event)
const ERROR_PLACEMENT_USER_MODE
const PREFIX_EVENT_ON_AFTER_ADD
static getHandlers($placement, int $userId=null)
const DEFAULT_USER_ID_VALUE
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!defined('SITE_ID')) $lang
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key