1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
result.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\DB;
4
19abstract class Result implements \IteratorAggregate
20{
22 protected $connection;
24 protected $resource;
26 protected $trackerQuery = null;
27
29 protected $converters = array();
31 protected $serializedFields = array();
33 protected $replacedAliases = array();
36
38 protected $count;
39
45 public function __construct($result, Connection $dbConnection = null, \Bitrix\Main\Diag\SqlTrackerQuery $trackerQuery = null)
46 {
47 $this->resource = $result;
48 $this->connection = $dbConnection;
49 $this->trackerQuery = $trackerQuery;
50 $resultFields = $this->getFields();
51
52 if ($resultFields && $this->connection)
53 {
54 $helper = $this->connection->getSqlHelper();
55 foreach ($resultFields as $key => $type)
56 {
57 $converter = $helper->getConverter($type);
58 if (is_callable($converter))
59 {
60 $this->converters[$key] = $converter;
61 }
62 }
63 }
64
65 if ($this->trackerQuery)
66 {
67 $this->trackerQuery->setSelectedRowsCount((int) $this->getSelectedRowsCount());
68 $this->trackerQuery->setSelectedFieldsCount($this->getFieldsCount());
69 $this->trackerQuery->setHasBigFields($this->hasBigFields());
70 }
71 }
72
78 public function getResource()
79 {
80 return $this->resource;
81 }
82
93 {
94 $this->replacedAliases = $replacedAliases;
95 }
96
106 {
107 $this->replacedAliases = array_merge($this->replacedAliases, $replacedAliases);
108 }
109
118 {
119 $this->serializedFields = $serializedFields;
120 }
121
132 public function addFetchDataModifier($fetchDataModifier)
133 {
134 if (!is_callable($fetchDataModifier))
135 {
136 throw new \Bitrix\Main\ArgumentException('Data Modifier should be a callback');
137 }
138
139 $this->fetchDataModifiers[] = $fetchDataModifier;
140 }
141
147 public function fetchRaw()
148 {
149 $this->trackerQuery?->restartQuery();
150
151 $data = $this->fetchRowInternal();
152
153 if ($this->trackerQuery != null)
154 {
155 if ($data)
156 {
157 $this->trackerQuery->incrementFetched();
158 $this->trackerQuery->addLength($this->getLength());
159 }
160
161 $this->trackerQuery->refinishQuery();
162 }
163
164 if (!$data)
165 {
166 return false;
167 }
168
169 return $data;
170 }
171
179 public function fetch(\Bitrix\Main\Text\Converter $converter = null)
180 {
181 $data = $this->fetchRaw();
182
183 if (!$data)
184 {
185 return false;
186 }
187
188 if ($this->converters)
189 {
190 foreach ($this->converters as $field => $convertDataModifier)
191 {
192 $data[$field] = call_user_func_array($convertDataModifier, array($data[$field]));
193 }
194 }
195
196 if ($this->serializedFields)
197 {
198 foreach ($this->serializedFields as $field)
199 {
200 if (isset($data[$field]))
201 $data[$field] = unserialize($data[$field]);
202 }
203 }
204
205 if ($this->replacedAliases)
206 {
207 foreach ($this->replacedAliases as $tech => $human)
208 {
209 $data[$human] = $data[$tech];
210 unset($data[$tech]);
211 }
212 }
213
214 if ($this->fetchDataModifiers)
215 {
216 foreach ($this->fetchDataModifiers as $fetchDataModifier)
217 {
218 $result = call_user_func_array($fetchDataModifier, array(&$data));
219
220 if (is_array($result))
221 {
222 $data = $result;
223 }
224 }
225 }
226
227 if ($converter !== null)
228 {
229 foreach ($data as $key => $val)
230 {
231 $data[$key] = $converter->encode(
232 $val,
233 ($data[$key."_TYPE"] ?? \Bitrix\Main\Text\Converter::TEXT)
234 );
235 }
236 }
237
238 return $data;
239 }
240
249 public function fetchAll(\Bitrix\Main\Text\Converter $converter = null)
250 {
251 $res = array();
252 while ($ar = $this->fetch($converter))
253 {
254 $res[] = $ar;
255 }
256 return $res;
257 }
258
264 abstract public function getFields();
265
271 abstract public function getSelectedRowsCount();
272
278 abstract protected function fetchRowInternal();
279
285 public function getTrackerQuery()
286 {
287 return $this->trackerQuery;
288 }
289
293 public function getConverters()
294 {
295 return $this->converters;
296 }
297
301 public function setConverters($converters)
302 {
303 $this->converters = $converters;
304 }
305
310 public function setCount($n)
311 {
312 $this->count = (int)$n;
313 }
314
320 public function getCount()
321 {
322 if($this->count !== null)
323 {
324 return $this->count;
325 }
326 throw new \Bitrix\Main\ObjectPropertyException("count");
327 }
328
336 public function getIterator(): \Traversable
337 {
338 return new ResultIterator($this);
339 }
340
346 public function getFieldsCount(): int
347 {
348 return 0;
349 }
350
356 public function getLength(): int
357 {
358 return 0;
359 }
360
366 public function hasBigFields(): bool
367 {
368 return false;
369 }
370}
$type
Определения options.php:106
Определения result.php:20
$connection
Определения result.php:22
$converters
Определения result.php:29
setSerializedFields(array $serializedFields)
Определения result.php:117
fetchRaw()
Определения result.php:147
getConverters()
Определения result.php:293
getCount()
Определения result.php:320
__construct($result, Connection $dbConnection=null, \Bitrix\Main\Diag\SqlTrackerQuery $trackerQuery=null)
Определения result.php:45
setConverters($converters)
Определения result.php:301
fetch(\Bitrix\Main\Text\Converter $converter=null)
Определения result.php:179
$trackerQuery
Определения result.php:26
addFetchDataModifier($fetchDataModifier)
Определения result.php:132
setReplacedAliases(array $replacedAliases)
Определения result.php:92
hasBigFields()
Определения result.php:366
$fetchDataModifiers
Определения result.php:35
getIterator()
Определения result.php:336
setCount($n)
Определения result.php:310
getResource()
Определения result.php:78
getTrackerQuery()
Определения result.php:285
getLength()
Определения result.php:356
getFieldsCount()
Определения result.php:346
$resource
Определения result.php:24
addReplacedAliases(array $replacedAliases)
Определения result.php:105
$serializedFields
Определения result.php:31
$replacedAliases
Определения result.php:33
fetchAll(\Bitrix\Main\Text\Converter $converter=null)
Определения result.php:249
$count
Определения result.php:38
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
Определения cachetracker.php:2
Определения base32.php:2
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$val
Определения options.php:1793
$n
Определения update_log.php:107