• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log_tools.php
  • Класс: CSocNetLogTools
  • Вызов: CSocNetLogTools::AddComment_Review_CheckIBlock_Blog
static function AddComment_Review_CheckIBlock_Blog($arElement)
{
	if (!CModule::IncludeModule("iblock"))
		return false;

	if (!CModule::IncludeModule("blog"))
		return false;

	$needProperty = array();
	$ELEMENT_IBLOCK_ID = intval($arElement["IBLOCK_ID"]);
	$ELEMENT_BLOG_POST_ID = intval($arElement["PROPERTY_BLOG_POST_ID_VALUE"]);
	$ELEMENT_BLOG_COMMENT_CNT = intval($arElement["PROPERTY_BLOG_COMMENT_CNT_VALUE"]);

	if ($ELEMENT_BLOG_POST_ID <= 0):
		$db_res = CIBlockElement::GetProperty($ELEMENT_IBLOCK_ID, $arElement["ID"], false, false, array("CODE" => "BLOG_POST_ID"));
		if (!($db_res && $res = $db_res->Fetch()))
			$needProperty[] = "BLOG_POST_ID";
	endif;
	if ($ELEMENT_BLOG_COMMENT_CNT <= 0):
		$db_res = CIBlockElement::GetProperty($ELEMENT_IBLOCK_ID, $arElement["ID"], false, false, array("CODE" => "BLOG_COMMENT_CNT"));
		if (!($db_res && $res = $db_res->Fetch()))
			$needProperty[] = "BLOG_COMMENT_CNT";
	endif;
	if (!empty($needProperty)):
		$obProperty = new CIBlockProperty;
		$res = true;
		foreach ($needProperty as $nameProperty)
		{
			$sName = trim($nameProperty == "BLOG_POST_ID" ? GetMessage("P_BLOG_POST_ID") : GetMessage("P_BLOG_COMMENTS_CNT"));
			$sName = (empty($sName) ? $nameProperty : $sName);
			$res = $obProperty->Add(array(
				"IBLOCK_ID" => $ELEMENT_IBLOCK_ID,
				"ACTIVE" => "Y",
				"PROPERTY_TYPE" => "N",
				"MULTIPLE" => "N",
				"NAME" => $sName,
				"CODE" => $nameProperty
				)
			);
		}
	endif;

	// Set NULL for post_id if it was deleted
	if ($ELEMENT_BLOG_POST_ID > 0):
		$arTopic = CBlogPost::GetByID($ELEMENT_BLOG_POST_ID);
		if (!$arTopic || !is_array($arTopic) || count($arTopic) <= 0)
		{
			CIBlockElement::SetPropertyValues($arElement["ID"], $ELEMENT_IBLOCK_ID, 0, "BLOG_POST_ID");
			$ELEMENT_BLOG_POST_ID = 0;
		}
	endif;

	return $ELEMENT_BLOG_POST_ID;
}