• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log_tools_photo.php
  • Класс: CSocNetLogToolsPhoto
  • Вызов: CSocNetLogToolsPhoto::OnAfterPhotoDrop
static function OnAfterPhotoDrop($arFields, $arComponentParams)
{
	if (
		array_key_exists("IS_SOCNET", $arComponentParams)
		&& $arComponentParams["IS_SOCNET"] == "Y"
		&& array_key_exists("USER_ALIAS", $arComponentParams)
		&& $arComponentParams["USER_ALIAS"] <> ''
	)
	{
		$arTmp = explode("_", $arComponentParams["USER_ALIAS"]);
		if (
			is_array($arTmp)
			&& count($arTmp) == 2
		)
		{
			$entity_type = $arTmp[0];
			$entity_id = $arTmp[1];

			if ($entity_type == "group")
				$entity_type = SONET_ENTITY_GROUP;
			elseif ($entity_type == "user")
				$entity_type = SONET_ENTITY_USER;
		}

		if (
			(
				!in_array($entity_type, array(SONET_ENTITY_GROUP, SONET_ENTITY_USER))
				|| intval($entity_id) <= 0
			)
			&& intval($arFields["SECTION_ID"]) > 0
		)
		{
			$rsPath = CIBlockSection::GetNavChain(intval($arFields["IBLOCK_ID"]), $arFields["SECTION_ID"]);
			if($arPath = $rsPath->Fetch())
			{
				$entity_type = SONET_ENTITY_USER;
				$entity_id = $arPath["CREATED_BY"];
			}
		}

		if (
			!in_array($entity_type, array(SONET_ENTITY_GROUP, SONET_ENTITY_USER))
			|| intval($entity_id) <= 0
		)
			return;
	}
	else
		return;

	$db_res = CSocNetLog::GetList(
		array(),
		array(
			"ENTITY_TYPE" => $entity_type,
			"ENTITY_ID" => $entity_id,
			"EVENT_ID" => "photo",
			"SOURCE_ID" => $arFields["SECTION_ID"]
		)
	);
	while ($db_res && $res = $db_res->Fetch())
	{
		if ($res["PARAMS"] <> '')
		{
			$arResParams = unserialize($res["PARAMS"], [ 'allowed_classes' => false ]);
		}
		else
		{
			continue;
		}

		if (is_array($arResParams) && in_array($arFields["ID"], $arResParams["arItems"]))
		{
			$arResParams["arItems"] = array_diff($arResParams["arItems"], array($arFields["ID"]));
		}
		else
		{
			continue;
		}

		if (count($arResParams["arItems"]) <= 0)
		{
			CSocNetLog::Delete($res["ID"]);
		}
		else
		{
			$arResParams["COUNT"]--;
			$arSonetFields = array(
				"PARAMS" => serialize($arResParams),
				"LOG_UPDATE" => $res["LOG_UPDATE"]
			);

			CSocNetLog::Update($res["ID"], $arSonetFields);
//				CSocNetLogRights::SetForSonet($res["ID"], $entity_type, $entity_id, "photo", "view");
		}
	}

	$db_res = CSocNetLog::GetList(
		array(),
		array(
			"ENTITY_TYPE" => $entity_type,
			"ENTITY_ID" => $entity_id,
			"EVENT_ID" => "photo_photo",
			"SOURCE_ID" => $arFields["ID"]
		)
	);
	while ($db_res && $res = $db_res->Fetch())
		CSocNetLog::Delete($res["ID"]);
}