Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
chatindex.php
1<?php
2
4
6
8{
9 private const CHARS_TO_REPLACE = ['(', ')', '[', ']', '{', '}', '<', '>', '-', '#', '"', '\''];
10
12 private $title;
13
15 private $chatId;
16
18 private $userList;
19
20 public static function create(): ChatIndex
21 {
22 return new static();
23 }
24
25 private function __construct()
26 {
27 }
28
32 public function isEmptyUsers(): bool
33 {
34 return empty($this->userList);
35 }
36
40 public function getRowTitle(): string
41 {
42 return $this->title;
43 }
44
45 public function getClearedTitle(): string
46 {
47 return ChatIndex::clearText($this->title);
48 }
49
54 public function setTitle(string $title): ChatIndex
55 {
56 $this->title = $title;
57
58 return $this;
59 }
60
64 public function getChatId(): int
65 {
66 return $this->chatId;
67 }
68
73 public function setChatId(int $chatId): ChatIndex
74 {
75 $this->chatId = $chatId;
76
77 return $this;
78 }
79
83 public function getRowUserNameList(): array
84 {
85 return $this->userList;
86 }
87
91 public function getClearedUserList(): array
92 {
93 $clearedUsers = [];
94 foreach ($this->userList as $user)
95 {
96 $clearedUsers[] = ChatIndex::clearText($user);
97 }
98
99 return $clearedUsers;
100 }
101
106 public function setUserList(array $users): ChatIndex
107 {
108 $this->userList = $users;
109
110 return $this;
111 }
112
120 public static function clearText(string $text): string
121 {
122 $clearedText = str_replace(static::CHARS_TO_REPLACE, ' ', $text);
123 $clearedText = preg_replace('/\s+/', ' ', $clearedText);
124
125 return trim($clearedText);
126 }
127
128 public static function matchAgainstWildcard($phrase, $leftWildcard = '+' , $rightWildcard = '*', $minTokenSize = null)
129 {
130 $ftMinTokenSize = $minTokenSize ?: \Bitrix\Main\ORM\Query\Filter\Helper::getMinTokenSize();
131
132 $orValues = [];
133
134 //split to words by any non-word symbols
135 $andValues = \Bitrix\Main\ORM\Query\Filter\Helper::splitWords($phrase);
136
137 if(!empty($andValues))
138 {
139 $andValues = array_filter(
140 $andValues,
141 static function($val) use ($ftMinTokenSize)
142 {
143 return (mb_strlen($val) >= $ftMinTokenSize);
144 }
145 );
146
147 if(!empty($andValues))
148 {
149 $orValues[] = $leftWildcard . implode($rightWildcard . " " . $leftWildcard, $andValues) . $rightWildcard;
150 }
151 }
152
153 if(!empty($orValues))
154 {
155 return "(".implode(") (", $orValues).")";
156 }
157
158 return '';
159 }
160}
static clearText(string $text)
static matchAgainstWildcard($phrase, $leftWildcard='+', $rightWildcard=' *', $minTokenSize=null)