OXID eShop CE  4.9.7
 All Classes Files Functions Variables Pages
oxfield.php
Go to the documentation of this file.
1 <?php
2 
14 class oxField // extends oxSuperCfg
15 {
16 
20  const T_TEXT = 1;
21 
25  const T_RAW = 2;
26 
52  public function __construct($value = null, $type = self::T_TEXT)
53  {
54  // duplicate content here is needed for performance.
55  // as this function is called *many* (a lot) times, it is crucial to be fast here!
56  switch ($type) {
57  case self::T_TEXT:
58  default:
59  $this->rawValue = $value;
60  break;
61  case self::T_RAW:
62  $this->value = $value;
63  break;
64  }
65  }
66 
74  public function __isset($sName)
75  {
76  switch ($sName) {
77  case 'rawValue':
78  return ($this->rawValue !== null);
79  break;
80  case 'value':
81  return ($this->value !== null);
82  break;
83  //return true;
84  }
85  return false;
86  }
87 
95  public function __get($sName)
96  {
97  switch ($sName) {
98  case 'rawValue':
99  return $this->value;
100  break;
101  case 'value':
102  if (is_string($this->rawValue)) {
103  $this->value = getStr()->htmlspecialchars($this->rawValue);
104  } else {
105  // TODO: call htmlentities for each value (recursively?)
106  $this->value = $this->rawValue;
107  }
108  if ($this->rawValue == $this->value) {
109  unset($this->rawValue);
110  }
111 
112  return $this->value;
113  break;
114  default:
115  return null;
116  break;
117  }
118  }
119 
125  public function __toString()
126  {
127  return (string) $this->value;
128  }
129 
133  public function convertToFormattedDbDate()
134  {
135  $this->setValue(oxRegistry::get("oxUtilsDate")->formatDBDate($this->rawValue), self::T_RAW);
136  }
137 
141  public function convertToPseudoHtml()
142  {
143  $this->setValue(str_replace("\r", '', nl2br(getStr()->htmlspecialchars($this->rawValue))), self::T_RAW);
144  }
145 
152  protected function _initValue($value = null, $type = self::T_TEXT)
153  {
154  switch ($type) {
155  case self::T_TEXT:
156  $this->rawValue = $value;
157  break;
158  case self::T_RAW:
159  $this->value = $value;
160  break;
161  }
162  }
163 
170  public function setValue($value = null, $type = self::T_TEXT)
171  {
172  unset($this->rawValue);
173  unset($this->value);
174  $this->_initValue($value, $type);
175  }
176 
182  public function getRawValue()
183  {
184  if (null === $this->rawValue) {
185  return $this->value;
186  };
187 
188  return $this->rawValue;
189  }
190 }