7 private static $arUpdate = Array();
8 private static $arInsert = Array();
9 private static array $tagCache = [];
11 public static function Add(
$userId, $tag, $immediate =
false)
27 SELECT ID, USER_ID, TAG, ".$DB->DatetimeToTimestampFunction(
"DATE_CREATE").
" AS DATE_CREATE
29 WHERE USER_ID = ".intval(
$userId).
"
40 if (
$arResult[$tag][
'DATE_CREATE']+1860 > time())
53 self::$arInsert[trim($tag)] = trim($tag);
55 if ($immediate || defined(
'BX_CHECK_AGENT_START') && !defined(
'BX_WITH_ON_AFTER_EPILOG'))
60 self::cleanCacheByTag((
string)$tag);
68 if (empty(self::$arUpdate) && empty(self::$arInsert))
74 if (defined(
'PULL_USER_ID'))
82 else if (intval($_SESSION[
"SESS_SEARCHER_ID"]) <= 0 && intval($_SESSION[
"SESS_GUEST_ID"]) > 0 && \CPullOptions::GetGuestStatus())
84 $userId = intval($_SESSION[
"SESS_GUEST_ID"])*-1;
97 if (!empty(self::$arUpdate))
101 SET DATE_CREATE = ".
$DB->CurrentTimeFunction().
", CHANNEL_ID = '".
$DB->ForSQL($arChannel[
'CHANNEL_ID']).
"'
102 WHERE ID IN (".(implode(
',', self::$arUpdate)).
")
106 if (
$DB->type ==
"MYSQL")
108 if (!empty(self::$arInsert))
110 $strSqlPrefix =
"INSERT INTO b_pull_watch (USER_ID, CHANNEL_ID, TAG, DATE_CREATE) VALUES ";
111 $maxValuesLen = 2048;
114 foreach(self::$arInsert as $tag)
116 $strSqlValues .=
",\n(".intval(
$userId).
", '".
$DB->ForSql($arChannel[
'CHANNEL_ID']).
"', '".
$DB->ForSql($tag).
"', ".
$DB->CurrentTimeFunction().
")";
117 if(mb_strlen($strSqlValues) > $maxValuesLen)
119 $DB->Query($strSqlPrefix.mb_substr($strSqlValues, 2));
123 if($strSqlValues <>
'')
125 $DB->Query($strSqlPrefix.mb_substr($strSqlValues, 2));
129 else if (!empty(self::$arInsert))
131 foreach(self::$arInsert as $tag)
133 $DB->Query(
"INSERT INTO b_pull_watch (USER_ID, CHANNEL_ID, TAG, DATE_CREATE) VALUES (".intval(
$userId).
", '".
$DB->ForSql($arChannel[
'CHANNEL_ID']).
"', '".
$DB->ForSql($tag).
"', ".
$DB->CurrentTimeFunction().
")");
137 self::$arInsert = Array();
138 self::$arUpdate = Array();
147 $strSql =
"DELETE FROM b_pull_watch WHERE USER_ID = ".intval(
$userId).(!is_null($tag)?
" AND TAG = '".$DB->ForSQL($tag).
"'":
"");
154 self::cleanCacheByUserId((
int)
$userId);
158 self::cleanCacheByTag((
string)$tag);
185 $searchTag = trim($tags);
186 if ($searchTag ==
'')
192 $tags = Array($searchTag);
197 foreach ($tags as $id => $tag)
200 $tags[$id] =
$DB->ForSQL($tag);
203 $updateIds = Array();
204 $strSql =
"SELECT ID, TAG FROM b_pull_watch WHERE USER_ID = ".intval(
$userId).
" AND TAG IN ('".implode(
"', '", $tags).
"')";
208 $updateIds[] =
$arRes[
'ID'];
214 $DB->Query(
"UPDATE b_pull_watch SET DATE_CREATE = ".
$DB->CurrentTimeFunction().
" WHERE ID IN (".implode(
', ', $updateIds).
")");
241 $userIds = array_unique(array_merge(...self::getUsersByTags($tag)));
243 if (isset($parameters[
'skip_users']) && !empty($parameters[
'skip_users']) && is_array($parameters[
'skip_users']))
245 $userIds = array_diff($userIds, $parameters[
'skip_users']);
248 if (!empty($userIds))
258 $userIds = $nonCachedTags = [];
260 foreach ($tags as $tag)
262 if (array_key_exists($tag, self::$tagCache))
264 if (is_array(self::$tagCache[$tag]))
266 $userIds[] = self::$tagCache[$tag];
272 $nonCachedTags[] = $tag;
275 if (!empty($nonCachedTags))
277 $userIds[] = self::getUsersByTagsInternal($nonCachedTags);
287 return self::$tagCache[$tag] ?? [];
290 private static function getUsersByTagsInternal(
array $tags):
array
293 ->setSelect([
'USER_ID',
'TAG'])
294 ->whereIn(
'TAG', $tags)
298 $usersByTag = $users = [];
306 foreach ($tags as $tag)
308 self::$tagCache[$tag] = $usersByTag[$tag] ??
null;
316 $userIds = \CPullWatch::getUsersByTag($tag);
318 return array_map(
'strval', $userIds);
323 self::$tagCache = [];
326 private static function cleanCacheByTag(
string $tag): void
328 unset(self::$tagCache[$tag]);
331 private static function cleanCacheByUserId(
int $userId): void
333 foreach (self::$tagCache as $tag => $userIds)
335 if (is_array($userIds) && in_array(
$userId, $userIds,
true))
337 unset(self::$tagCache[$tag]);
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
static DeferredSql($userId=false)
static Extend($userId, $tags)
static AddToStack($tag, $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
static Delete($userId, $tag=null)
static getUsersByTags(array $tags)
static Add($userId, $tag, $immediate=false)
static getUsersByTag(string $tag)
static Get(int $userId, $cache=true, $reOpen=false, $channelType=self::TYPE_PRIVATE)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$GLOBALS['_____370096793']