- Модуль: intranet
- Путь к файлу: ~/bitrix/modules/intranet/lib/component/userprofile/grats.php
- Класс: BitrixIntranetComponentUserProfileGrats
- Вызов: Grats::getGratitudePostListAction
public function getGratitudePostListAction(array $params = array())
{
$result = array();
$gratitudesData = $this->getGratitudes();
if (
empty($gratitudesData)
|| empty($gratitudesData['POSTS_ID'])
|| empty($gratitudesData['BADGES'])
|| !Loader::includeModule('socialnetwork')
)
{
return $result;
}
$postsData = [];
$filter = array(
'EVENT_ID' => 'blog_post_grat',
'@SOURCE_ID' => $gratitudesData['POSTS_ID'],
);
$result['POSTS_COUNT'] = CSocNetLog::getList(
array(),
$filter,
array(),
false,
array('ID'),
array(
'CHECK_RIGHTS' => 'Y',
'USE_FOLLOW' => 'N',
'USE_SUBSCRIBE' => 'N'
)
);
$res = CSocNetLog::getList(
array('LOG_DATE' => 'DESC'),
$filter,
false,
array(
'nPageSize' => $this->getPageSize(),
'iNumPage' => (!empty($params['pageNum']) && intval($params['pageNum']) > 0 ? intval($params['pageNum']) : 1)
),
array('SOURCE_ID'),
array(
'CHECK_RIGHTS' => 'Y',
'USE_FOLLOW' => 'N',
'USE_SUBSCRIBE' => 'N'
)
);
$postIdList = array();
while($logEntryFields = $res->fetch())
{
$postIdList[] = $logEntryFields['SOURCE_ID'];
}
if (
!empty($postIdList)
&& Loader::includeModule('blog')
)
{
$res = BitrixBlogPostTable::getList(array(
'filter' => array(
'@ID' => $postIdList
),
'select' => array('ID', 'AUTHOR_ID', 'UF_GRATITUDE', 'MICRO', 'TITLE', 'DETAIL_TEXT', 'DATE_PUBLISH')
));
while($postFields = $res->fetch())
{
$postsData[$postFields['ID']] = $postFields;
if ($postFields["MICRO"] === "Y")
{
$title = CTextParser::clearAllTags($postFields['DETAIL_TEXT']);
$parser = new CTextParser();
$parser->allow = [
'CLEAR_SMILES' => 'Y',
'NL2BR' => 'N'
];
$title = preg_replace("/ /is".BX_UTF_PCRE_MODIFIER, "", $parser->convertText($title));
$title = preg_replace("/\
/is".BX_UTF_PCRE_MODIFIER, " ", $title);
$postsData[$postFields['ID']]['TITLE'] = truncateText($title, 100);
}
unset($postsData[$postFields['ID']]['DETAIL_TEXT']);
$postsData[$postFields['ID']]['DATE_PUBLISH_TS'] = MakeTimeStamp($postFields['DATE_PUBLISH']);
$postsData[$postFields['ID']]['DATE_FORMATTED'] = CComponentUtil::getDateTimeFormatted(array(
'TIMESTAMP' => $postsData[$postFields['ID']]['DATE_PUBLISH_TS'],
'HIDE_TODAY' => false
));
$postsData[$postFields['ID']]['URL'] = CComponentEngine::MakePathFromTemplate($this->getPathToPost(), array(
"user_id" => $postFields["AUTHOR_ID"],
"post_id" => $postFields["ID"]
));
foreach($gratitudesData['BADGES'] as $badgeEnumId => $badgeData)
{
if (in_array(intval($postFields['UF_GRATITUDE']), $badgeData['ID']))
{
$postsData[$postFields['ID']]['BADGE_ID'] = $badgeEnumId;
break;
}
}
}
}
$postIdList = array_keys($postsData);
$contentIdList = array_map(function($val) { return 'BLOG_POST-'.$val; }, $postIdList);
$ratingDataList = CRatings::getRatingVoteResult("BLOG_POST", $postIdList);
foreach($ratingDataList as $entityId => $ratingData)
{
if (is_set($postsData[$entityId]))
{
$postsData[$entityId]['RATING_DATA'] = $ratingData;
}
}
$ratingDataList = CRatings::getEntityRatingData(array(
'entityTypeId' => "BLOG_POST",
'entityId' => $postIdList
));
foreach($ratingDataList as $entityId => $ratingData)
{
if (
is_set($postsData[$entityId])
&& is_set($postsData[$entityId]['RATING_DATA'])
)
{
$postsData[$entityId]['RATING_DATA']['TOP'] = $ratingData;
}
}
$res = BitrixSocialnetworkUserContentViewTable::getList(array(
'filter' => array(
'@CONTENT_ID' => $contentIdList
),
'select' => array('CNT', 'CONTENT_ID', 'RATING_TYPE_ID', 'RATING_ENTITY_ID'),
'runtime' => array(
new EntityExpressionField('CNT', 'COUNT(*)')
),
'group' => array('CONTENT_ID')
));
while($postContentViewData = $res->fetch())
{
$postId = intval($postContentViewData['RATING_ENTITY_ID']);
if (is_set($postsData[$postId]))
{
$postsData[$postId]['CONTENT_VIEW_CNT'] = intval($postContentViewData['CNT']);
}
}
$result['BADGES'] = $gratitudesData['BADGES'];
$result['POSTS'] = $postsData;
$result['AUTHORS'] = $gratitudesData['AUTHORS'];
return $result;
}