1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
elementproperty.php
См. документацию.
1<?php
7namespace Bitrix\Iblock\Template\Entity;
8
9class ElementProperty extends Base
10{
11 protected $iblockId = 0;
12 protected $properties = array();
18 public function __construct($id)
19 {
20 parent::__construct($id);
21 }
22
30 public function setIblockId($iblockId)
31 {
32 $this->iblockId = intval($iblockId);
33 }
34
42 public function resolve($entity)
43 {
44 if ($this->loadFromDatabase())
45 {
46 if (isset($this->elementLinkProperties[$entity]))
47 {
48 if (!is_object($this->elementLinkProperties[$entity]))
49 $this->elementLinkProperties[$entity] = Element::getInstance($this->elementLinkProperties[$entity]);
50 return $this->elementLinkProperties[$entity];
51 }
52 elseif (isset($this->sectionLinkProperties[$entity]))
53 {
54 if (!is_object($this->sectionLinkProperties[$entity]))
55 $this->sectionLinkProperties[$entity] = Element::getInstance($this->sectionLinkProperties[$entity]);
56 return $this->sectionLinkProperties[$entity];
57 }
58 }
59 return parent::resolve($entity);
60 }
61
69 public function setFields(array $fields)
70 {
71 parent::setFields($fields);
72 if (
73 is_array($this->fields)
74 && $this->iblockId > 0
75 )
76 {
79 "select" => array("*"),
80 "filter" => array("=IBLOCK_ID" => $this->iblockId),
81 ));
82 while ($row = $propertyList->fetch())
83 {
84 if ($row["USER_TYPE_SETTINGS"])
85 {
86 $row["USER_TYPE_SETTINGS"] = unserialize(
87 $row["USER_TYPE_SETTINGS"],
88 array('allowed_classes' => false)
89 );
90 }
91
92 $properties[$row["ID"]] = $row;
93 if ($row["CODE"] != "")
94 $properties[$row["CODE"]] = &$properties[$row["ID"]];
95 }
96
97 foreach ($fields as $propertyCode => $propertyValues)
98 {
99 if (is_array($propertyValues))
100 {
101 foreach ($propertyValues as $i => $propertyValue)
102 {
103 if (is_array($propertyValue) && array_key_exists("VALUE", $propertyValue))
104 {
105 if ($propertyValue["VALUE"] != "")
106 $propertyValues[$i] = $propertyValue["VALUE"];
107 else
108 unset($propertyValues[$i]);
109 }
110 }
111 }
112
113 if (isset($properties[$propertyCode]))
114 {
115 $property = $properties[$propertyCode];
116 $fieldCode = mb_strtolower($propertyCode);
117
118 if ($property["PROPERTY_TYPE"] === "L")
119 {
120 if (is_numeric($propertyValues))
121 {
122 $value = new ElementPropertyEnum($propertyValues);
123 }
124 elseif (is_array($propertyValues))
125 {
126 $value = array();
127 foreach ($propertyValues as $propertyValue)
128 {
129 if (is_numeric($propertyValue))
130 $value[] = new ElementPropertyEnum($propertyValue);
131 }
132 }
133 else
134 {
135 $value = $propertyValues;
136 }
137 }
138 elseif ($property["PROPERTY_TYPE"] === "E")
139 {
140 if ($propertyValues instanceof Element)
141 {
142 $this->elementLinkProperties[$fieldCode] = $propertyValues;
143 $value = $propertyValues->getField("name");
144 }
145 elseif (is_numeric($propertyValues))
146 {
147 $this->elementLinkProperties[$fieldCode] = $propertyValues;
148 $value = new ElementPropertyElement($propertyValues);
149 }
150 elseif (is_array($propertyValues))
151 {
152 $value = array();
153 foreach ($propertyValues as $propertyValue)
154 {
155 if (is_numeric($propertyValue))
157 }
158 }
159 else
160 {
161 $value = $propertyValues;
162 }
163 }
164 elseif ($property["PROPERTY_TYPE"] === "G")
165 {
166 if ($propertyValues instanceof Section)
167 {
168 $this->sectionLinkProperties[$fieldCode] = $propertyValues;
169 $value = $propertyValues->getField("name");
170 }
171 elseif (is_numeric($propertyValues))
172 {
173 $this->sectionLinkProperties[$fieldCode] = $propertyValues;
174 $value = new ElementPropertySection($propertyValues);
175 }
176 elseif (is_array($propertyValues))
177 {
178 $value = array();
179 foreach ($propertyValues as $propertyValue)
180 {
181 if (is_numeric($propertyValue))
183 }
184 }
185 else
186 {
187 $value = $propertyValues;
188 }
189 }
190 else
191 {
192 if($property["USER_TYPE"] <> '')
193 {
194 if(is_array($propertyValues))
195 {
196 $value = array();
197 foreach($propertyValues as $propertyValue)
198 {
199 $value[] = new ElementPropertyUserField($propertyValue, $property);
200 }
201 }
202 else
203 {
204 $value = new ElementPropertyUserField($propertyValues, $property);
205 }
206 }
207 else
208 {
209 $value = $propertyValues;
210 }
211 }
212
213 $this->fieldMap[$fieldCode] = $property["ID"];
214 $this->fieldMap[$property["ID"]] = $property["ID"];
215 if ($property["CODE"] != "")
216 $this->fieldMap[mb_strtolower($property["CODE"])] = $property["ID"];
217
218 $this->fields[$property["ID"]] = $value;
219 }
220 }
221 }
222 }
223
230 protected function loadFromDatabase()
231 {
232 if (!isset($this->fields) && $this->iblockId > 0)
233 {
234 $this->fields = array();
235 $this->fieldMap = array();
236 $propertyList = \CIBlockElement::getProperty(
237 $this->iblockId,
238 $this->id,
239 array("sort" => "asc"),
240 array("EMPTY" => "N")
241 );
242 while ($property = $propertyList->fetch())
243 {
244 if ($property["VALUE_ENUM"] != "")
245 {
246 $value = $property["VALUE_ENUM"];
247 }
248 elseif ($property["PROPERTY_TYPE"] === "E")
249 {
250 $this->elementLinkProperties[$property["ID"]] = $property["VALUE"];
251 if ($property["CODE"] != "")
252 $this->elementLinkProperties[mb_strtolower($property["CODE"])] = $property["VALUE"];
253 $value = new ElementPropertyElement($property["VALUE"]);
254 }
255 elseif ($property["PROPERTY_TYPE"] === "G")
256 {
257 $this->sectionLinkProperties[$property["ID"]] = $property["VALUE"];
258 if ($property["CODE"] != "")
259 $this->sectionLinkProperties[mb_strtolower($property["CODE"])] = $property["VALUE"];
260 $value = new ElementPropertySection($property["VALUE"]);
261 }
262 else
263 {
264 if($property["USER_TYPE"] <> '')
265 {
266 $value = new ElementPropertyUserField($property["VALUE"], $property);
267 }
268 else
269 {
270 $value = $property["VALUE"];
271 }
272 }
273
274 $this->fieldMap[$property["ID"]] = $property["ID"];
275 if ($property["CODE"] != "")
276 $this->fieldMap[mb_strtolower($property["CODE"])] = $property["ID"];
277
278 if ($property["MULTIPLE"] == "Y")
279 $this->fields[$property["ID"]][] = $value;
280 else
281 $this->fields[$property["ID"]] = $value;
282 }
283 }
284 return is_array($this->fields);
285 }
286}
287
289{
291 private $property = null;
292
297 function __construct($key, $property)
298 {
299 parent::__construct($key);
300 if (is_array(($property)))
301 {
302 $this->property = $property;
303 }
304 }
305
310 protected function load()
311 {
312 $propertyFormatFunction = $this->getFormatFunction();
313 if ($propertyFormatFunction)
314 {
315 return call_user_func_array($propertyFormatFunction,
316 array(
317 $this->property,
318 array("VALUE" => $this->key),
319 array("MODE" => "ELEMENT_TEMPLATE"),
320 )
321 );
322 }
323 else
324 {
325 return $this->key;
326 }
327 }
328
334 protected function getFormatFunction()
335 {
336 static $propertyFormatFunction = array();
337 if (!isset($propertyFormatFunction[$this->property["ID"]]))
338 {
339 $propertyFormatFunction[$this->property["ID"]] = false;
340 if ($this->property && mb_strlen($this->property["USER_TYPE"]))
341 {
342 $propertyUserType = \CIBlockProperty::getUserType($this->property["USER_TYPE"]);
343 if(
344 array_key_exists("GetPublicViewHTML", $propertyUserType)
345 && is_callable($propertyUserType["GetPublicViewHTML"])
346 )
347 {
348 $propertyFormatFunction[$this->property["ID"]] = $propertyUserType["GetPublicViewHTML"];
349 }
350 }
351 }
352 return $propertyFormatFunction[$this->property["ID"]];
353 }
354}
355
357{
363 protected function load()
364 {
365 $enumList = \Bitrix\Iblock\PropertyEnumerationTable::getList(array(
366 "select" => array("VALUE"),
367 "filter" => array("=ID" => $this->key),
368 ));
369 $enum = $enumList->fetch();
370 if ($enum)
371 return $enum["VALUE"];
372 else
373 return "";
374 }
375}
376
378{
384 protected function load()
385 {
387 "select" => array("NAME"),
388 "filter" => array("=ID" => $this->key),
389 ));
390 $element = $elementList->fetch();
391 if ($element)
392 return $element["NAME"];
393 else
394 return "";
395 }
396}
397
399{
405 protected function load()
406 {
408 "select" => array("NAME"),
409 "filter" => array("=ID" => $this->key),
410 ));
411 $section = $sectionList->fetch();
412 if ($section)
413 return $section["NAME"];
414 else
415 return "";
416 }
417}
static getList(array $parameters=array())
Определения datamanager.php:431
</td ></tr ></table ></td ></tr ><?endif?><? $propertyIndex=0;foreach( $arGlobalProperties as $propertyCode=> $propertyValue
Определения file_new.php:729
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$entity
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$i
Определения factura.php:643
$fields
Определения yandex_run.php:501