Object.class.php
1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Cpeople\Classes\Infoblock;
class Object extends \Cpeople\Classes\Base\Object
{
protected $properties;
protected $fields;
static $standardFields = array(
'ID', 'CODE', 'EXTERNAL_ID', 'XML_ID', 'NAME',
'IBLOCK_ID', 'IBLOCK_SECTION_ID',
'ACTIVE', 'DATE_ACTIVE_FROM', 'DATE_ACTIVE_TO',
'SORT', 'PREVIEW_PICTURE', 'PREVIEW_TEXT', 'PREVIEW_TEXT_TYPE',
'DETAIL_PICTURE', 'DETAIL_TEXT', 'DETAIL_TEXT_TYPE',
'MODIFIED_BY', 'TAGS'
);
public function getProperties()
{
if (!isset($this->properties))
{
$this->properties = array();
$rs = \CIBlockProperty::GetList(array('sort' => 'asc'), array('IBLOCK_ID' => $this->id));
while($ar = $rs->Fetch())
{
$this->properties[$ar['CODE']] = new Property($ar);
}
}
return $this->properties;
}
public function getProperty($key)
{
$this->getProperties();
if (!array_key_exists($key, $this->properties))
{
throw new \Exception("Infoblock $this->id does not have property $key");
}
return $this->properties[$key];
}
public function getFields()
{
if (!isset($this->fields))
{
$this->fields = array();
$res = \CIBlock::GetFields($this->id);
foreach ($res as $k => $element)
{
$this->fields[$k] = new Field($k, $element);
}
foreach (self::$standardFields as $field)
{
if (!array_key_exists($field, $this->fields))
{
$this->fields[$field] = array('CODE' => $field);
}
}
}
return $this->fields;
}
public function addProperty($propData)
{
$ibp = new \CIBlockProperty;
return (bool) $ibp->Add($propData);
}
}