Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
chatindex.php
1<?php
2namespace Bitrix\Im\Model;
3
9;
10
11
37class ChatIndexTable extends Main\Entity\DataManager
38{
39 use Main\ORM\Data\Internal\DeleteByFilterTrait;
40
46 public static function getTableName()
47 {
48 return 'b_im_chat_index';
49 }
50
56 public static function getMap()
57 {
58 return array(
59 'CHAT_ID' => array(
60 'data_type' => 'integer',
61 'primary' => true,
62 ),
63 'SEARCH_TITLE' => array(
64 'data_type' => 'string',
65 'validation' => array(__CLASS__, 'validateTitle'),
66 ),
67 'SEARCH_CONTENT' => array(
68 'data_type' => 'text',
69 ),
70 );
71 }
72
73 public static function validateTitle()
74 {
75 return array(
76 new Entity\Validator\Length(null, 255),
77 );
78 }
79
80 protected static function getMergeFields()
81 {
82 return array('CHAT_ID');
83 }
84
85 public static function merge(array $data)
86 {
87 $result = new Entity\AddResult();
88
89 $helper = Application::getConnection()->getSqlHelper();
90 $insertData = $data;
91 $updateData = $data;
92 $mergeFields = static::getMergeFields();
93
94 foreach ($mergeFields as $field)
95 {
96 unset($updateData[$field]);
97 }
98
99 $versionMain = \Bitrix\Main\ModuleManager::getVersion('main');
100 $isPgCompatible = (version_compare($versionMain, '24.0.0') >= 0);//todo: Remove it in future version
101
102 if (isset($updateData['SEARCH_CONTENT']))
103 {
104 if ($isPgCompatible)
105 {
106 $field = new SqlExpression('?v', 'SEARCH_CONTENT');
107 }
108 else
109 {
110 $field = 'SEARCH_CONTENT';
111 }
112 $updateData['SEARCH_CONTENT'] = new SqlExpression($helper->getConditionalAssignment($field, $updateData['SEARCH_CONTENT']));
113 }
114
115 if (isset($updateData['SEARCH_TITLE']))
116 {
117 if ($isPgCompatible)
118 {
119 $field = new SqlExpression('?v', 'SEARCH_TITLE');
120 }
121 else
122 {
123 $field = 'SEARCH_TITLE';
124 }
125 $updateData['SEARCH_TITLE'] = new SqlExpression($helper->getConditionalAssignment($field, $updateData['SEARCH_TITLE']));
126 }
127
128 $merge = $helper->prepareMerge(
129 static::getTableName(),
130 static::getMergeFields(),
131 $insertData,
132 $updateData
133 );
134
135 if ($merge[0] != "")
136 {
137 Application::getConnection()->query($merge[0]);
138 $id = Application::getConnection()->getInsertedId();
139 $result->setId($id);
140 $result->setData($data);
141 }
142 else
143 {
144 $result->addError(new Error('Error constructing query'));
145 }
146
147 return $result;
148 }
149
150 public static function updateIndex($id, $primaryField, array $updateData): Main\ORM\Data\UpdateResult
151 {
152 $result = new Main\ORM\Data\UpdateResult();
153 $helper = Application::getConnection()->getSqlHelper();
154
155 if (isset($updateData[$primaryField]))
156 {
157 unset($updateData[$primaryField]);
158 }
159
160 if (isset($updateData['SEARCH_CONTENT']))
161 {
162 $updateData['SEARCH_CONTENT'] = new SqlExpression($helper->getConditionalAssignment('SEARCH_CONTENT', $updateData['SEARCH_CONTENT']));
163 }
164
165 if (isset($updateData['SEARCH_TITLE']))
166 {
167 $updateData['SEARCH_TITLE'] = new SqlExpression($helper->getConditionalAssignment('SEARCH_TITLE', $updateData['SEARCH_TITLE']));
168 }
169
170 $update = $helper->prepareUpdate(
171 static::getTableName(),
172 $updateData
173 );
174
175 if ($update[0] !== '')
176 {
178 "UPDATE " . static::getTableName() . " SET " . $update[0] . " WHERE " . $primaryField . " = " . $id
179 );
180 }
181
182 return $result;
183 }
184}
static updateIndex($id, $primaryField, array $updateData)
static merge(array $data)
Definition chatindex.php:85
static getConnection($name="")