Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
linkcalendarindex.php
1<?php
2namespace Bitrix\Im\Model;
3
4use Bitrix\Im\V2\Common\IndexTableTrait;
12
39{
40 use IndexTableTrait
41 {
42 indexInBackground as private defaultIndexInBackground;
43 }
44
45 static private array $toIndexIds = [];
46
52 public static function getTableName()
53 {
54 return 'b_im_link_calendar_index';
55 }
56
62 public static function getMap()
63 {
64 return [
65 'ID' => new IntegerField(
66 'ID',
67 [
68 'primary' => true,
69 //'title' => Loc::getMessage('LINK_CALENDAR_INDEX_ENTITY_ID_FIELD'),
70 ]
71 ),
72 'SEARCH_CONTENT' => new TextField(
73 'SEARCH_CONTENT',
74 [
75 //'title' => Loc::getMessage('LINK_CALENDAR_INDEX_ENTITY_SEARCH_CONTENT_FIELD'),
76 ]
77 ),
78 ];
79 }
80
81 protected static function getBaseDataClass(): string
82 {
83 return LinkCalendarTable::class;
84 }
85
86 public static function indexInBackground(array $ids): void
87 {
88 if (!empty($ids))
89 {
90 array_push(static::$toIndexIds, ...$ids);
91 }
92
93 static::defaultIndexInBackground();
94 }
95
96 public static function index(array $ids = []): void
97 {
98 $toIndexIds = array_merge(static::$toIndexIds, $ids);
99 $toIndexIds = array_unique($toIndexIds);
100 if (empty($toIndexIds))
101 {
102 return;
103 }
104 $linkWithoutIndex = LinkCalendarTable::query()
105 ->setSelect(['*'])
106 ->whereIn('ID', $toIndexIds)
107 ->fetchCollection()
108 ;
109 $links = new CalendarCollection($linkWithoutIndex);
110 $links->fillCalendarData();
111 $inserts = [];
112 foreach ($links as $link)
113 {
114 $inserts[] = [
115 'ID' => $link->getId(),
116 'SEARCH_CONTENT' => static::generateSearchIndex($link),
117 ];
118 }
119 static::multiplyInsertWithoutDuplicate($inserts);
120 }
121
122 private static function generateSearchIndex(CalendarItem $link): string
123 {
124 return Content::prepareStringToken($link->getTitle());
125 }
126}