• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log_tools_photo.php
  • Класс: CSocNetLogToolsPhoto
  • Вызов: CSocNetLogToolsPhoto::OnAfterSectionEdit
static function OnAfterSectionEdit($arFields, $arComponentParams, $arComponentResult)
{
	if (!CModule::IncludeModule("iblock"))
		return;

	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
		)
		{
			$rsPath = CIBlockSection::GetNavChain(intval($arFields["IBLOCK_ID"]), $arComponentResult["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;

	if (
		trim($arComponentResult["SECTION"]["PASSWORD"] ?? '') == ''
		&& $arFields["UF_PASSWORD"] <> ''
	)
	{
		// hide photos

		$dbSection = CIBlockSection::GetList(
			array("BS.LEFT_MARGIN"=>"ASC"),
			array(
				"IBLOCK_ID" => $arFields["IBLOCK_ID"],
				">=LEFT_MARGIN" => $arComponentResult["SECTION"]["LEFT_MARGIN"],
				"<=RIGHT_MARGIN" => $arComponentResult["SECTION"]["RIGHT_MARGIN"],
			),
			false,
			array("ID", "CREATED_BY")
		);

		while ($arSection = $dbSection->Fetch())
		{
			$db_res = CSocNetLog::GetList(
				array(),
				array(
					"ENTITY_TYPE" => $entity_type,
					"ENTITY_ID" => $entity_id,
					"EVENT_ID"	=> "photo",
					"SOURCE_ID" => $arSection["ID"]
				)
			);
			while ($db_res && $res = $db_res->Fetch())
			{
				CSocNetLogRights::DeleteByLogID($res["ID"]);
				CSocNetLogRights::Add($res["ID"], array("U".$arSection["CREATED_BY"], "SA"));
			}
		}
		
		$dbElement = CIBlockElement::GetList(
			array(),
			array(
				"IBLOCK_ID" => $arFields["IBLOCK_ID"],
				"SECTION_ID" => $arComponentResult["SECTION"]["ID"],
				"INCLUDE_SUBSECTIONS" => "Y"
			),
			false,
			false,
			array("ID", "CREATED_BY")
		);

		while ($arElement = $dbElement->Fetch())
		{
			$db_res = CSocNetLog::GetList(
				array(),
				array(
					"EVENT_ID"	=> "photo_photo",
					"SOURCE_ID" => $arElement["ID"]
				)
			);
			while ($db_res && $res = $db_res->Fetch())
			{
				CSocNetLogRights::DeleteByLogID($res["ID"]);
				CSocNetLogRights::Add($res["ID"], array("U".$arElement["CREATED_BY"], "SA"));
			}
		}
	}
	elseif (
		trim($arComponentResult["SECTION"]["PASSWORD"] ?? '') <> ''
		&& $arFields["UF_PASSWORD"] == ''
	)
	{
		// show photos

		$dbSection = CIBlockSection::GetList(
			array("BS.LEFT_MARGIN"=>"ASC"),
			array(
				"IBLOCK_ID" => $arFields["IBLOCK_ID"],
				">=LEFT_MARGIN" => $arComponentResult["SECTION"]["LEFT_MARGIN"],
				"<=RIGHT_MARGIN" => $arComponentResult["SECTION"]["RIGHT_MARGIN"],
			),
			false,
			array("ID", "CREATED_BY")
		);

		while ($arSection = $dbSection->Fetch())
		{
			$db_res = CSocNetLog::GetList(
				array(),
				array(
					"ENTITY_TYPE" => $entity_type,
					"ENTITY_ID" => $entity_id,
					"EVENT_ID"	=> "photo",
					"SOURCE_ID" => $arSection["ID"]
				)
			);
			while ($db_res && $res = $db_res->Fetch())
			{
				CSocNetLogRights::DeleteByLogID($res["ID"]);
				CSocNetLogRights::SetForSonet($res["ID"], $entity_type, $entity_id, "photo", "view");
			}
		}
		
		$dbElement = CIBlockElement::GetList(
			array(),
			array(
				"IBLOCK_ID" => $arFields["IBLOCK_ID"],
				"SECTION_ID" => $arComponentResult["SECTION"]["ID"],
				"INCLUDE_SUBSECTIONS" => "Y"
			),
			false,
			false,
			array("ID", "CREATED_BY")
		);

		while ($arElement = $dbElement->Fetch())
		{
			$db_res = CSocNetLog::GetList(
				array(),
				array(
					"EVENT_ID"	=> "photo_photo",
					"SOURCE_ID" => $arElement["ID"]
				)
			);
			while ($db_res && $res = $db_res->Fetch())
			{
				CSocNetLogRights::DeleteByLogID($res["ID"]);
				CSocNetLogRights::SetForSonet($res["ID"], $entity_type, $entity_id, "photo", "view");
			}
		}
	}
	else
	{
		return;
	}
}