- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/lib/usercontentview.php
- Класс: BitrixSocialnetworkUserContentViewTable
- Вызов: UserContentViewTable::set
static function set($params = array())
{
static $controllerUser = array();
$userId = (isset($params['userId']) ? intval($params['userId']) : 0);
$typeId = (isset($params['typeId']) ? trim($params['typeId']) : false);
$entityId = (isset($params['entityId']) ? intval($params['entityId']) : 0);
$save = (isset($params['save']) ? !!$params['save'] : false);
if (
$userId <= 0
|| empty($typeId)
|| $entityId <= 0
)
{
throw new SystemException("Invalid input data.");
}
$saved = false;
if (ModuleManager::isModuleInstalled('bitrix24'))
{
if (!isset($controllerUser[$userId]))
{
$res = UserTable::getList(array(
'filter' => array(
'=ID' => $userId,
'=EXTERNAL_AUTH_ID' => '__controller'
),
'select' => array('ID')
));
if ($res->fetch())
{
$controllerUser[$userId] = true;
}
else
{
$controllerUser[$userId] = false;
}
}
if ($controllerUser[$userId])
{
return array(
'success' => true,
'savedInDB' => false
);
}
}
if ($save)
{
$listRes = self::getList([
'filter' => [
"=USER_ID" => $userId,
"=RATING_TYPE_ID" => $typeId,
"=RATING_ENTITY_ID" => $entityId,
]
]);
if (!$listRes->fetch())
{
$connection = BitrixMainApplication::getConnection();
$helper = $connection->getSqlHelper();
$nowDate = new SqlExpression($helper->getCurrentDateTimeFunction());
$insertFields = array(
"USER_ID" => $userId,
"RATING_TYPE_ID" => $typeId,
"RATING_ENTITY_ID" => $entityId,
"CONTENT_ID" => $typeId."-".$entityId,
"DATE_VIEW" => $nowDate
);
$tableName = static::getTableName();
list($prefix, $values) = $helper->prepareInsert($tableName, $insertFields);
$connection->queryExecute("INSERT IGNORE INTO {$tableName} ({$prefix}) VALUES ({$values})");
$saved = true;
}
}
return array(
'success' => true,
'savedInDB' => $saved
);
}