1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
base.php
См. документацию.
1<?php
8
14class Base
15{
17 protected $id = null;
19 protected $fields = null;
21 protected $fieldMap = array();
22
24 protected static $instance = [];
28 protected static function getInstance($id)
29 {
30 $class = get_called_class();
31 if (!isset(static::$instance[$class]))
32 {
33 static::$instance[$class] = [];
34 }
35 if (!isset(static::$instance[$class][$id]))
36 {
37 static::$instance[$class][$id] = new static($id);
38 }
39 return static::$instance[$class][$id];
40 }
41
42
46 public function __construct($id)
47 {
48 $this->id = $id;
49 }
50
56 public function getId()
57 {
58 return $this->id;
59 }
60
68 public function resolve($entity)
69 {
70 if ($entity === "this")
71 return $this;
72 else
73 return new Base(0);
74 }
75
83 public function setFields(array $fields)
84 {
85 $this->fields = $fields;
86 }
87
95 public function getField($fieldName)
96 {
97 if (!$this->loadFromDatabase())
98 return "";
99
100 if (!isset($this->fieldMap[$fieldName]))
101 return "";
102
103 $fieldName = $this->fieldMap[$fieldName];
104 if (!isset($this->fields[$fieldName]))
105 return "";
106
107 $fieldValue = $this->fields[$fieldName];
108 if (is_array($fieldValue))
109 {
110 $result = array();
111 foreach($fieldValue as $key => $value)
112 {
113 if ($value instanceof LazyValueLoader)
114 $result[$key] = $value->getValue();
115 else
116 $result[$key] = $value;
117
118 }
119 return $result;
120 }
121 else
122 {
123 if ($fieldValue instanceof LazyValueLoader)
124 {
125 return $fieldValue->getValue();
126 }
127 return $this->fields[$fieldName];
128 }
129 }
130
137 protected function loadFromDatabase()
138 {
139 if (!isset($this->fields))
140 {
141 $this->fields = array();
142 }
143 return true;
144 }
145
156 protected function addField($fieldName, $internalName, $value)
157 {
158 if (!isset($this->fields[$internalName]))
159 $this->fields[$internalName] = $value;
160 $this->fieldMap[mb_strtolower($fieldName)] = $internalName;
161 }
162}
163
171{
172 protected $value = null;
173 protected $key = null;
174
179 {
180 $this->key = $key;
181 }
182
188 public function __toString()
189 {
190 if (!isset($this->value))
191 $this->value = $this->load();
192 return $this->value;
193 }
194
200 public function getValue()
201 {
202 if (!isset($this->value))
203 $this->value = $this->load();
204 return $this->value;
205 }
206
212 protected function load()
213 {
214 return "";
215 }
216}
217
__construct($id)
Определения base.php:46
resolve($entity)
Определения base.php:68
addField($fieldName, $internalName, $value)
Определения base.php:156
static getInstance($id)
Определения base.php:28
getField($fieldName)
Определения base.php:95
static $instance
Определения base.php:24
setFields(array $fields)
Определения base.php:83
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$entity
if(empty($signedUserToken)) $key
Определения quickway.php:257