Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
result.php
1<?php
9
11use Bitrix\Main\DB\Result as DbResult;
13
14class Result
15{
17 public $resource;
18
21
23 protected $fields;
24
27
29 protected $fieldsDisallowed = ['NAME', 'USER_ID'];
30
32 protected $dataTypeId = Recipient\Type::EMAIL;
33
37 public function __construct($resource)
38 {
39 if(is_array($resource))
40 {
41 $isSingleArray = false;
42 $arrayKeyList = array_keys($resource);
43 foreach($arrayKeyList as $key)
44 {
45 if(is_string($key))
46 {
47 $isSingleArray = true;
48 break;
49 }
50 }
51
52 if($isSingleArray)
53 {
54 $resource = array($resource);
55 }
56
57 $this->resource = new ArrayResult($resource);
58 }
59 elseif($resource instanceof DbResult)
60 {
61 $this->resource = $resource;
62 }
63 elseif($resource instanceof \CAllDBResult)
64 {
65 $this->resourceCDBResult = $resource;
66 }
67
68 $this->fieldsDisallowed = array_merge(
69 $this->fieldsDisallowed,
70 Recipient\Type::getCodes()
71 );
72 }
73
79 public function getDataTypeId()
80 {
81 return $this->dataTypeId;
82 }
83
90 public function setDataTypeId($dataTypeId)
91 {
92 $this->dataTypeId = $dataTypeId;
93 }
94
98 public function setFilterFields(array $fields)
99 {
100 $this->fields = $fields;
101 }
102
106 public function getFilterFields()
107 {
108 return $this->fields;
109 }
110
114 public function setAdditionalFields(array $additionalFields)
115 {
116 $this->additionalFields = $additionalFields;
117 }
118
122 public function fetchPlain()
123 {
124 $result = null;
125 if($this->resource)
126 {
127 $result = $this->resource->fetch();
128 }
129 elseif($this->resourceCDBResult)
130 {
131 $result = $this->resourceCDBResult->Fetch();
132 }
133
134 return (is_array($result) && count($result) > 0) ? $result : null;
135 }
136
140 public function fetch()
141 {
142 $result = $this->fetchPlain();
143 if($result)
144 {
145 $result = $this->fetchModifierFields($result);
146 }
147
148 return ($result && count($result) > 0) ? $result : null;
149 }
150
151 protected function fetchModifierFields(array $result)
152 {
153 $fieldsList = array();
154 foreach($result as $key => $value)
155 {
156 if(is_object($value))
157 {
158 $value = (string) $value;
159 $result[$key] = $value;
160 }
161
162 if(in_array($key, $this->fieldsDisallowed))
163 {
164 continue;
165 }
166
167 if($this->fields && in_array($key, $this->fields))
168 {
169 $fieldsList[$key] = $value;
170 }
171
172 unset($result[$key]);
173 }
174
175 if($this->additionalFields)
176 {
177 $fieldsList = $fieldsList + $this->additionalFields;
178 }
179
180 if(count($fieldsList) > 0)
181 {
182 $result['FIELDS'] = $fieldsList;
183 }
184
185 return $result;
186 }
187
191 public function getSelectedRowsCount()
192 {
193 if($this->resource)
194 {
195 return $this->resource->getSelectedRowsCount();
196 }
197 elseif($this->resourceCDBResult)
198 {
199 if(!($this->resourceCDBResult instanceof \CDBResultMysql))
200 {
201 $this->resourceCDBResult->NavStart(0);
202 }
203
204 return $this->resourceCDBResult->SelectedRowsCount();
205 }
206
207 return 0;
208 }
209
215 public function getQuerySql()
216 {
217 if (!$this->resource)
218 {
219 return null;
220 }
221
222 if (!$this->resource->getTrackerQuery())
223 {
224 return null;
225 }
226
227 return $this->resource->getTrackerQuery()->getSql();
228 }
229}
setAdditionalFields(array $additionalFields)
Definition result.php:114
setFilterFields(array $fields)
Definition result.php:98
fetchModifierFields(array $result)
Definition result.php:151