Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
8
14class Base
15{
17 protected $id = null;
19 protected $fields = null;
21 protected $fieldMap = array();
22
26 public function __construct($id)
27 {
28 $this->id = $id;
29 }
30
36 public function getId()
37 {
38 return $this->id;
39 }
40
48 public function resolve($entity)
49 {
50 if ($entity === "this")
51 return $this;
52 else
53 return new Base(0);
54 }
55
63 public function setFields(array $fields)
64 {
65 $this->fields = $fields;
66 }
67
75 public function getField($fieldName)
76 {
77 if (!$this->loadFromDatabase())
78 return "";
79
80 if (!isset($this->fieldMap[$fieldName]))
81 return "";
82
83 $fieldName = $this->fieldMap[$fieldName];
84 if (!isset($this->fields[$fieldName]))
85 return "";
86
87 $fieldValue = $this->fields[$fieldName];
88 if (is_array($fieldValue))
89 {
90 $result = array();
91 foreach($fieldValue as $key => $value)
92 {
93 if ($value instanceof LazyValueLoader)
94 $result[$key] = $value->getValue();
95 else
96 $result[$key] = $value;
97
98 }
99 return $result;
100 }
101 else
102 {
103 if ($fieldValue instanceof LazyValueLoader)
104 {
105 return $fieldValue->getValue();
106 }
107 return $this->fields[$fieldName];
108 }
109 }
110
117 protected function loadFromDatabase()
118 {
119 if (!isset($this->fields))
120 {
121 $this->fields = array();
122 }
123 return true;
124 }
125
136 protected function addField($fieldName, $internalName, $value)
137 {
138 if (!isset($this->fields[$internalName]))
139 $this->fields[$internalName] = $value;
140 $this->fieldMap[mb_strtolower($fieldName)] = $internalName;
141 }
142}
143
151{
152 protected $value = null;
153 protected $key = null;
154
159 {
160 $this->key = $key;
161 }
162
168 public function __toString()
169 {
170 if (!isset($this->value))
171 $this->value = $this->load();
172 return $this->value;
173 }
174
180 public function getValue()
181 {
182 if (!isset($this->value))
183 $this->value = $this->load();
184 return $this->value;
185 }
186
192 protected function load()
193 {
194 return "";
195 }
196}
197
addField($fieldName, $internalName, $value)
Definition base.php:136