- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/lib/logsubscribe.php
- Класс: BitrixSocialnetworkLogSubscribeTable
- Вызов: LogSubscribeTable::set
static function set($params = array())
{
$userId = (isset($params['userId']) ? intval($params['userId']) : 0);
$logId = (isset($params['logId']) ? intval($params['logId']) : 0);
$type = (isset($params['type']) ? $params['type'] : '');
if (
$userId <= 0
|| $logId <= 0
)
{
return false;
}
if (is_array($type))
{
$typeList = $type;
foreach($typeList as $type)
{
$params['type'] = $type;
self::set($params);
}
return true;
}
if (!in_array($type, self::getTypes()))
{
return false;
}
$connection = Application::getConnection();
$helper = $connection->getSqlHelper();
$insertFields = array(
"USER_ID" => $userId,
"LOG_ID" => $logId,
"TYPE" => $helper->forSql($type),
);
$updateFields = array(
);
if (
isset($params['endDate'])
&& $params['endDate'] instanceof BitrixMainTypeDateTime
)
{
$insertFields["END_DATE"] = $params['endDate'];
$updateFields["END_DATE"] = $params['endDate'];
}
elseif (!empty($params['ttl']))
{
$endDate = BitrixMainTypeDateTime::createFromTimestamp(time() + self::TTL);
$insertFields["END_DATE"] = $endDate;
$updateFields["END_DATE"] = $endDate;
}
else
{
$updateFields["END_DATE"] = false;
}
$merge = $helper->prepareMerge(
static::getTableName(),
array("USER_ID", "LOG_ID", "TYPE"),
$insertFields,
$updateFields
);
if ($merge[0] != "")
{
$connection->query($merge[0]);
}
return true;
}