OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxfield.php
Go to the documentation of this file.
1 <?php
2 
14 class oxField // extends oxSuperCfg
15 {
19  const T_TEXT = 1;
20 
24  const T_RAW = 2;
25 
51  public function __construct($value = null, $type = self::T_TEXT)
52  {
53  // duplicate content here is needed for performance.
54  // as this function is called *many* (a lot) times, it is crucial to be fast here!
55  switch ($type) {
56  case self::T_TEXT:
57  default:
58  $this->rawValue = $value;
59  break;
60  case self::T_RAW:
61  $this->value = $value;
62  break;
63  }
64  }
65 
73  public function __isset( $sName )
74  {
75  switch ( $sName ) {
76  case 'rawValue':
77  return ($this->rawValue !== null);
78  break;
79  case 'value':
80  return ($this->value !== null);
81  break;
82  //return true;
83  }
84  return false;
85  }
86 
94  public function __get( $sName )
95  {
96  switch ( $sName ) {
97  case 'rawValue':
98  return $this->value;
99  break;
100  case 'value':
101  if (is_string($this->rawValue)) {
102  $this->value = getStr()->htmlspecialchars( $this->rawValue );
103  } else {
104  // TODO: call htmlentities for each value (recursively?)
105  $this->value = $this->rawValue;
106  }
107  if ($this->rawValue == $this->value) {
108  unset($this->rawValue);
109  }
110  return $this->value;
111  break;
112  default:
113  return null;
114  break;
115  }
116  }
117 
123  public function __toString()
124  {
125  return (string)$this->value;
126  }
127 
133  public function convertToFormattedDbDate()
134  {
135  $this->setValue(oxRegistry::get("oxUtilsDate")->formatDBDate( $this->rawValue ), self::T_RAW);
136  }
137 
143  public function convertToPseudoHtml()
144  {
145  $this->setValue( str_replace( "\r", '', nl2br( getStr()->htmlspecialchars( $this->rawValue ) ) ), self::T_RAW );
146  }
147 
156  protected function _initValue( $value = null, $type = self::T_TEXT)
157  {
158  switch ($type) {
159  case self::T_TEXT:
160  $this->rawValue = $value;
161  break;
162  case self::T_RAW:
163  $this->value = $value;
164  break;
165  }
166  }
167 
176  public function setValue($value = null, $type = self::T_TEXT)
177  {
178  unset($this->rawValue);
179  unset($this->value);
180  $this->_initValue($value, $type);
181  }
182 
188  public function getRawValue()
189  {
190  if (null === $this->rawValue) {
191  return $this->value;
192  };
193  return $this->rawValue;
194  }
195 }