oxfield.php

Go to the documentation of this file.
00001 <?php
00002 
00014 class oxField // extends oxSuperCfg
00015 {
00016 
00020     const T_TEXT = 1;
00021 
00025     const T_RAW = 2;
00026 
00052     public function __construct($value = null, $type = self::T_TEXT)
00053     {
00054         // duplicate content here is needed for performance.
00055         // as this function is called *many* (a lot) times, it is crucial to be fast here!
00056         switch ($type) {
00057             case self::T_TEXT:
00058             default:
00059                 $this->rawValue = $value;
00060                 break;
00061             case self::T_RAW:
00062                 $this->value = $value;
00063                 break;
00064         }
00065     }
00066 
00074     public function __isset($sName)
00075     {
00076         switch ($sName) {
00077             case 'rawValue':
00078                 return ($this->rawValue !== null);
00079                 break;
00080             case 'value':
00081                 return ($this->value !== null);
00082                 break;
00083             //return true;
00084         }
00085         return false;
00086     }
00087 
00095     public function __get($sName)
00096     {
00097         switch ($sName) {
00098             case 'rawValue':
00099                 return $this->value;
00100                 break;
00101             case 'value':
00102                 if (is_string($this->rawValue)) {
00103                     $this->value = getStr()->htmlspecialchars($this->rawValue);
00104                 } else {
00105                     // TODO: call htmlentities for each value (recursively?)
00106                     $this->value = $this->rawValue;
00107                 }
00108                 if ($this->rawValue == $this->value) {
00109                     unset($this->rawValue);
00110                 }
00111 
00112                 return $this->value;
00113                 break;
00114             default:
00115                 return null;
00116                 break;
00117         }
00118     }
00119 
00125     public function __toString()
00126     {
00127         return (string) $this->value;
00128     }
00129 
00133     public function convertToFormattedDbDate()
00134     {
00135         $this->setValue(oxRegistry::get("oxUtilsDate")->formatDBDate($this->rawValue), self::T_RAW);
00136     }
00137 
00141     public function convertToPseudoHtml()
00142     {
00143         $this->setValue(str_replace("\r", '', nl2br(getStr()->htmlspecialchars($this->rawValue))), self::T_RAW);
00144     }
00145 
00152     protected function _initValue($value = null, $type = self::T_TEXT)
00153     {
00154         switch ($type) {
00155             case self::T_TEXT:
00156                 $this->rawValue = $value;
00157                 break;
00158             case self::T_RAW:
00159                 $this->value = $value;
00160                 break;
00161         }
00162     }
00163 
00170     public function setValue($value = null, $type = self::T_TEXT)
00171     {
00172         unset($this->rawValue);
00173         unset($this->value);
00174         $this->_initValue($value, $type);
00175     }
00176 
00182     public function getRawValue()
00183     {
00184         if (null === $this->rawValue) {
00185             return $this->value;
00186         };
00187 
00188         return $this->rawValue;
00189     }
00190 }