oxfield.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxField // extends oxSuperCfg
00008 {
00009     const T_TEXT = 1;
00010     const T_RAW  = 2;
00011 
00022     public function __construct($value = null, $type = self::T_TEXT)
00023     {
00024         // duplicate content here is needed for performance.
00025         // as this function is called *many* (a lot) times, it is crucial to be fast here!
00026         switch ($type) {
00027             case self::T_TEXT:
00028             default:
00029                 $this->rawValue = $value;
00030                 break;
00031             case self::T_RAW:
00032                 $this->value = $value;
00033                 break;
00034         }
00035     }
00036 
00044     public function __isset( $sName )
00045     {
00046         switch ( $sName ) {
00047             case 'rawValue':
00048                 return ($this->rawValue !== null);
00049             case 'value':
00050                 return ($this->value !== null);
00051             //return true;
00052             }
00053         return false;
00054     }
00055 
00063     public function __get( $sName )
00064     {
00065         switch ( $sName ) {
00066             case 'rawValue':
00067                 return $this->value;
00068             case 'value':
00069                 if (is_string($this->rawValue)) {
00070                     $this->value = htmlspecialchars($this->rawValue);
00071                 } else {
00072                     // TODO: call htmlentities for each (recursive ???)
00073                     $this->value = $this->rawValue;
00074                 }
00075                 if ($this->rawValue == $this->value) {
00076                     unset($this->rawValue);
00077                 }
00078                 return $this->value;
00079             default:
00080                 return null;
00081             }
00082     }
00083 
00089     public function __toString()
00090     {
00091         return $this->value;
00092     }
00093 
00099     public function convertToFormattedDbDate()
00100     {
00101         $this->setValue(oxUtilsDate::getInstance()->formatDBDate( $this->rawValue ), self::T_RAW);
00102     }
00103 
00109     public function convertToPseudoHtml()
00110     {
00111         $this->setValue(str_replace("\r", '', nl2br(htmlentities($this->rawValue))), self::T_RAW);
00112     }
00113 
00122     protected function _initValue( $value = null, $type = self::T_TEXT)
00123     {
00124         switch ($type) {
00125             case self::T_TEXT:
00126                 $this->rawValue = $value;
00127                 break;
00128             case self::T_RAW:
00129                 $this->value = $value;
00130                 break;
00131         }
00132     }
00133 
00142     public function setValue($value = null, $type = self::T_TEXT)
00143     {
00144         unset($this->rawValue);
00145         unset($this->value);
00146         $this->_initValue($value, $type);
00147     }
00148 
00154     public function getRawValue()
00155     {
00156         if (null === $this->rawValue) {
00157             return $this->value;
00158         };
00159         return $this->rawValue;
00160     }
00161 }

Generated on Thu Dec 4 12:04:56 2008 for OXID eShop CE by  doxygen 1.5.5