• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/landing/view.php
  • Класс: BitrixLandingLandingView
  • Вызов: View::inc
static function inc($lid, $uid = null)
{
	if (!$uid)
	{
		$uid = Manager::getUserId();
	}
	$lid = (int)$lid;
	$uid = (int)$uid;
	$date = new DateTime;

	if ($uid <= 0)
	{
		return;
	}
	if (!isset($_SESSION[self::SESSION_VIEWS_KEY]))
	{
		$_SESSION[self::SESSION_VIEWS_KEY] = [];
	}

	if (!in_array($lid, $_SESSION[self::SESSION_VIEWS_KEY]))
	{
		$res = ViewTable::getList([
			'select' => [
				'ID', 'VIEWS'
			],
			'filter' => [
				'LID' => $lid,
				'USER_ID' => $uid
			]
		]);
		if ($row = $res->fetch())
		{
			$result = ViewTable::update($row['ID'], [
				'VIEWS' => $row['VIEWS'] + 1,
				'LAST_VIEW' => $date
			]);
		}
		else
		{
			$result = ViewTable::add([
				'VIEWS' => 1,
				'LID' => $lid,
				'USER_ID' => $uid,
				'FIRST_VIEW' => $date,
				'LAST_VIEW' => $date,
			]);
		}
		if ($result->isSuccess())
		{
			self::incViewsPage($lid);
			$_SESSION[self::SESSION_VIEWS_KEY][] = $lid;
		}
	}
}