• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List

E:/E/GEAMP/www/openbiz/openbiz/bin/data/BizField.php

00001 <?PHP
00025 class BizField extends MetaObject
00026 {
00032     public $m_BizObjName;
00033     public $m_Join = null;
00034     public $m_Column = null;
00035     public $m_Alias = null;
00036     public $m_Index;
00042     public $m_Type = null;
00043 
00049     public $m_Format = null;
00050 
00056     public $m_Length = null;
00057     public $m_ValueExpression = null;// support expression
00058 
00064     public $m_Required = null;       // support expression
00065     public $m_Validator = null;      // support expression
00066     public $m_SqlExpression = null;  // support expression
00067        public $m_Encrypted = "N";
00068        public $m_ClearText = null;
00074     public $m_DefaultValue = null;
00075     public $m_ValueOnCreate = null;
00076     public $m_ValueOnUpdate = null;
00077 
00083     public $m_OnAudit = false;
00084 
00090     public $m_Value = null; 
00091     public $m_OldValue = null; // the old value of the field
00092 
00100     function __construct(&$xmlArr, $bizObj)
00101     {
00102         $this->m_Name = isset($xmlArr["ATTRIBUTES"]["NAME"]) ? $xmlArr["ATTRIBUTES"]["NAME"] : null;
00103         $this->m_BizObjName = $bizObj->m_Name;
00104         $this->m_Package = $bizObj->m_Package;
00105         $this->m_Join = isset($xmlArr["ATTRIBUTES"]["JOIN"]) ? $xmlArr["ATTRIBUTES"]["JOIN"] : null;
00106         $this->m_Column = isset($xmlArr["ATTRIBUTES"]["COLUMN"]) ? $xmlArr["ATTRIBUTES"]["COLUMN"] : null;
00107         $this->m_Alias = isset($xmlArr["ATTRIBUTES"]["ALIAS"]) ? $xmlArr["ATTRIBUTES"]["ALIAS"] : null;
00108         $this->m_ValueExpression = isset($xmlArr["ATTRIBUTES"]["VALUE"]) ? $xmlArr["ATTRIBUTES"]["VALUE"] : null;
00109         $this->m_DefaultValue = isset($xmlArr["ATTRIBUTES"]["DEFAULTVALUE"]) ? $xmlArr["ATTRIBUTES"]["DEFAULTVALUE"] : null;
00110         $this->m_Type = isset($xmlArr["ATTRIBUTES"]["TYPE"]) ? $xmlArr["ATTRIBUTES"]["TYPE"] : null;
00111         $this->m_Format = isset($xmlArr["ATTRIBUTES"]["FORMAT"]) ? $xmlArr["ATTRIBUTES"]["FORMAT"] : null;
00112         $this->m_Length = isset($xmlArr["ATTRIBUTES"]["LENGTH"]) ? $xmlArr["ATTRIBUTES"]["LENGTH"] : null;
00113         $this->m_Required = isset($xmlArr["ATTRIBUTES"]["REQUIRED"]) ? $xmlArr["ATTRIBUTES"]["REQUIRED"] : null;
00114         $this->m_Encrypted = isset($xmlArr["ATTRIBUTES"]["ENCRYPTED"]) ? $xmlArr["ATTRIBUTES"]["ENCRYPTED"] :"N";
00115 //        if($this->m_Encrypted=='Y'){
00116 //            $this->m_ClearText="N";
00117 //        }else{
00118 //            $this->m_ClearText="Y";
00119 //        }
00120         $this->m_Validator = isset($xmlArr["ATTRIBUTES"]["VALIDATOR"]) ? $xmlArr["ATTRIBUTES"]["VALIDATOR"] : null;
00121         $this->m_SqlExpression = isset($xmlArr["ATTRIBUTES"]["SQLEXPR"]) ? $xmlArr["ATTRIBUTES"]["SQLEXPR"] : null;
00122         $this->m_ValueOnCreate = isset($xmlArr["ATTRIBUTES"]["VALUEONCREATE"]) ? $xmlArr["ATTRIBUTES"]["VALUEONCREATE"] : null;
00123         $this->m_ValueOnUpdate = isset($xmlArr["ATTRIBUTES"]["VALUEONUPDATE"]) ? $xmlArr["ATTRIBUTES"]["VALUEONUPDATE"] : null;
00124         if (isset($xmlArr["ATTRIBUTES"]["ONAUDIT"]) && $xmlArr["ATTRIBUTES"]["ONAUDIT"]=='Y')
00125             $this->m_OnAudit = true;
00126 
00127         $this->m_BizObjName = $this->prefixPackage($this->m_BizObjName);
00128 
00129         if (!$this->m_Format) $this->useDefaultFormat();
00130     }
00131 
00137     protected function useDefaultFormat()
00138     {
00139         if ($this->m_Type == "Date")
00140             $this->m_Format = '%Y-%m-%d';
00141         elseif ($this->m_Type == "Datetime")
00142             $this->m_Format = '%Y-%m-%d %H:%M:%S';
00143     }
00144 
00151     public function getProperty($propertyName)
00152     {
00153         $ret = parent::getProperty($propertyName);
00154         if ($ret) return $ret;
00155         //if ($propertyName == "Value") return $this->getValue();
00156               if ($propertyName == "Value") return $this->lookupValue();
00157         return $this->$propertyName;
00158     }
00159 
00168     public function adjustBizObjName($bizObjName)
00169     {
00170         if ($this->m_BizObjName != $bizObjName)
00171             $this->m_BizObjName = $bizObjName;
00172     }
00173 
00180     public function getSqlValue($input=null)
00181     {
00182         $value = ($input !== null) ? $input : $this->m_Value;
00183         if ($value === null)
00184         {
00185             return "";
00186         }
00187         /*
00188         if ($this->m_Type != 'Number')
00189         {
00190             if (get_magic_quotes_gpc() == 0) {
00191                 $val = addcslashes($value, "\000\n\r\\'\"\032");
00192             }
00193             return "'$value'";
00194         }
00195         */
00196 
00197         return $value;
00198     }
00199 
00205     public function isLobField()
00206     {
00207         return ($this->m_Type == 'Blob' || $this->m_Type == 'Clob');
00208     }
00209 
00217     public function getInsertLobValue($dbType)
00218     {
00219         if ($dbType == 'oracle' || $dbType == 'oci8')
00220         {
00221             if ($this->m_Type != 'Blob') return 'empty_blob()';
00222             if ($this->m_Type != 'Clob') return 'empty_clob()';
00223         }
00224         return 'null';
00225     }
00226 
00233        public function lookupValue()
00234        {
00235               $this->getDataObj()->getActiveRecord();
00236               return $this->getValue();
00237        }
00238        
00245     public function getValue($formatted=true)
00246     {
00247         // need to ensure that value are retrieved from source/cache
00248         //if ($this->getDataObj()->CheckDataRetrieved() == false)     
00249         //$this->getDataObj()->getActiveRecord();
00250         $value = stripcslashes($this->m_Value);
00251 
00252         $value = $this->m_Value;
00253         if ($this->m_ValueExpression && trim($this->m_Column) == "")
00254         {
00255             $value = Expression::evaluateExpression($this->m_ValueExpression,$this->getDataObj());
00256         }
00257         if ($this->m_Format && $formatted)
00258         {
00259             $value = BizSystem::typeManager()->valueToFormattedString($this->m_Type, $this->m_Format, $value);
00260         }
00261         return $value;
00262     }
00263 
00270     public function setValue($value)
00271     {         
00272         $this->m_Value = $value;
00273     }
00274 
00281     public function saveOldValue($oldValue=null)
00282     {
00283         if ($oldValue)
00284             $this->m_OldValue = $oldValue;
00285         else
00286             $this->m_OldValue = $this->m_Value;
00287     }
00288 
00294     public function getDefaultValue()
00295     {
00296         if($this->m_DefaultValue !== null)
00297             return Expression::evaluateExpression($this->m_DefaultValue, $this->getDataObj());
00298         return "";
00299     }
00300 
00306     public function getValueOnCreate()
00307     {
00308         if($this->m_ValueOnCreate !== null)
00309             return $this->getSqlValue(Expression::evaluateExpression($this->m_ValueOnCreate, $this->getDataObj()));
00310         return "";
00311     }
00312 
00318     public function getValueOnUpdate()
00319     {
00320         if($this->m_ValueOnUpdate !== null)
00321             return $this->getSqlValue(Expression::evaluateExpression($this->m_ValueOnUpdate, $this->getDataObj()));
00322         return "";
00323     }
00324 
00330     protected function getDataObj()
00331     {
00332         return BizSystem::getObject($this->m_BizObjName);
00333     }
00334 
00340     public function checkRequired()
00341     {
00342         if (!$this->m_Required || $this->m_Required == "")
00343             return false;
00344         elseif ($this->m_Required == "Y")
00345             $required = true;
00346         elseif($required != "N")
00347             $required = false;
00348         else
00349             $required = Expression::evaluateExpression($this->m_Required, $this->getDataObj());
00350 
00351         return $required;
00352     }
00353 
00360     public function checkValueType($value = null)
00361     {
00362         if(!$value)
00363         {
00364             $value = $this->m_Value;
00365         }
00366         $validator = BizSystem::getService(VALIDATE_SERVICE);
00367         switch ($this->m_Type)
00368         {
00369             case "Number":
00370                 $result = is_numeric($value);
00371                 break;
00372 
00373             case "Text":
00374                 $result = is_string($value);
00375                 break;
00376 
00377             case "Date":
00378                 $result = $validator->date($value);
00379                 break;
00380             /*
00381             case "Datetime":    // zend doesn't support date time
00382               $result = $validator->date($value); 
00383               break;
00384             
00385             case "Currency": 
00386               $result = $validator->date($value); 
00387               break;
00388             */
00389             case "Phone":
00390                 $result = $validator->phone($value);
00391                 break;
00392 
00393             default:
00394                 $result = true;
00395                 break;
00396         }
00397 
00398         return $result;
00399     }
00400 
00406     public function validate()
00407     {
00408         $ret = true;
00409         if ($this->m_Validator)
00410             $ret = Expression::evaluateExpression($this->m_Validator, $this->getDataObj());
00411         return $ret;
00412     }
00413 
00414 }
00415 ?>

Generated on Thu Apr 19 2012 17:09:13 for openbiz by  doxygen 1.7.2