Post::getById

  1. Bitrix24 API (v. 23.675.0)
  2. blog
  3. Post
  4. getById
  • Модуль: blog
  • Путь к файлу: ~/bitrix/modules/blog/lib/item/post.php
  • Класс: BitrixBlogItemPost
  • Вызов: Post::getById
static function getById($postId = 0, $params = array())
{
	static $cachedFields = array();

	$postItem = false;
	$postId = intval($postId);

	$useStaticCache = (
		!empty($params['USE_STATIC_CACHE'])
		&& $params['USE_STATIC_CACHE'] === true
	);

	if ($postId > 0)
	{
		$postItem = new Post;
		$postFields = array();

		if (
			$useStaticCache
			&& isset($cachedFields[$postId])
		)
		{
			$postFields = $cachedFields[$postId];
		}
		else
		{
			$select = array('*', 'UF_BLOG_POST_URL_PRV');

			if (
				BitrixMainConfigOption::get('disk', 'successfully_converted', false)
				&& MainModuleManager::isModuleInstalled('disk')
			)
			{
				$select[] = 'UF_BLOG_POST_FILE';
			}

			if (
				Loader::includeModule('vote')
				&& MainModuleManager::isModuleInstalled('socialnetwork')
			)
			{
				$select[] = 'UF_BLOG_POST_VOTE';
			}

			$res = PostTable::getList(array(
				'filter' => array('=ID' => $postId),
				'select' => $select
			));
			if ($fields = $res->fetch())
			{
				$postFields = $fields;

				if ($postFields['DATE_CREATE'] instanceof BitrixMainTypeDateTime)
				{
					$postFields['DATE_CREATE'] = $postFields['DATE_CREATE']->toString();
				}
				if ($postFields['DATE_PUBLISH'] instanceof BitrixMainTypeDateTime)
				{
					$postFields['DATE_PUBLISH'] = $postFields['DATE_PUBLISH']->toString();
				}
			}

			$cachedFields[$postId] = $postFields;
		}

		$postItem->setFields($postFields);
		if (
			isset($postFields['ID'])
			&& intval($postFields['ID']) > 0
		)
		{
			$postItem->setId(intval($postFields['ID']));
		}
	}

	return $postItem;
}

Добавить комментарий