Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
livefeed.php
1<?php
3
4use \Bitrix\Forum\MessageTable;
5use \Bitrix\Socialnetwork\Livefeed as SonetLivefeed;
6
7class LiveFeed extends Entity
8{
14 public static function getData(int $sourceId): ?array
15 {
16 if (
17 \Bitrix\Main\Loader::includeModule('socialnetwork') &&
18 \Bitrix\Main\Loader::includeModule('forum')
19 )
20 {
21 $provider = SonetLivefeed\Provider::init([
22 'ENTITY_TYPE' => 'FORUM_POST',
23 'ENTITY_ID' => $sourceId,
24 'CLONE_DISK_OBJECTS' => false
25 ]);
26 if (!$provider || !$provider->getSourceTitle())
27 {
28 return null;
29 }
30 $res = MessageTable::getList([
31 'select' => [
32 'POST_MESSAGE',
33 'TOPIC_TITLE' => 'TOPIC.TITLE'
34 ],
35 'filter' => [
36 'ID' => $sourceId,
37 '=APPROVED' => 'Y'
38 ],
39 'limit' => 1
40 ]);
41 if ($comment = $res->fetch())
42 {
43 $title = $provider->getSourceTitle();
44 $title = preg_replace('/\[[^\]]+\]/is', '', $title);
45 $params = [];
46 $blocks = [[
47 'type' => 'header',
48 'content' => $title
49 ]];
50 if (\Bitrix\Main\Loader::includeModule('disk'))
51 {
52 $params = [
53 'files' => self::getDiskFiles(
54 $sourceId,
55 \Bitrix\Disk\Uf\ForumMessageConnector::class,
56 'forum'
57 )
58 ];
59 }
60 $blocks = array_merge(
61 $blocks,
62 Parser::textToBlocks($comment['POST_MESSAGE'], $params)
63 );
64 return [
65 'TITLE' => \truncateText($title, self::TITLE_LENGTH),
66 'BLOCKS' => $blocks
67 ];
68 }
69 }
70
71 return null;
72 }
73}
static getDiskFiles(int $sourceId, string $entityType, string $module)
Definition entity.php:18
static getData(int $sourceId)
Definition livefeed.php:14
static textToBlocks(string $text, array $params=[])
Definition parser.php:212