Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
fairlimitselector.php
1<?php
9namespace Bitrix\Iblock\ORM;
10
14
20{
29 public static function fetchCollection($query)
30 {
31 $select = $query->getSelect();
32
33 $query->setSelect([new ExpressionField('DISTINCT_ID', 'DISTINCT %s', 'ID')]);
34 $query->addGroup('ID');
35
36 // get elements data
37 $ids = [];
38
39 foreach ($query->exec()->fetchAll() as $row)
40 {
41 $ids[] = $row['DISTINCT_ID'];
42 }
43
45 $dataClass = $query->getEntity()->getDataClass();
46 $elements = $dataClass::createCollection();
47
48 if (!empty($ids))
49 {
50
51 $query = $dataClass::query();
52
53 $query->setSelect($select);
54
55 $query->whereIn('ID', $ids);
56
57 $resultElements = [];
58
59 foreach ($query->fetchCollection() as $elementObject)
60 {
62 $resultElements[$elementObject->getId()] = $elementObject;
63 }
64
65 // original sort
66 foreach ($ids as $id)
67 {
68 $elements->sysAddActual($resultElements[$id]);
69 }
70 }
71
72 return $elements;
73 }
74}