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

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

00001 <?php
00017 include_once(OPENBIZ_BIN.'data/private/BizRecord.php');
00018 include_once(OPENBIZ_BIN.'data/private/TableJoin.php');
00019 include_once(OPENBIZ_BIN.'data/private/ObjReference.php');
00020 include_once(OPENBIZ_BIN.'data/private/BizDataObj_Assoc.php');
00021 include_once(OPENBIZ_BIN.'data/private/BizDataObj_SQLHelper.php');
00022 include_once(OPENBIZ_BIN.'data/BizField.php');
00023 
00032 abstract class BizDataObj_Abstract extends MetaObject implements iSessionObject
00033 {
00034     // metadata vars are public, necessary for metadata inheritance
00035 
00041     public $m_Database;
00042 
00048     public $m_BaseSearchRule = null;    // support expression
00049 
00055     public $m_BaseSortRule = null;      // support expression
00056 
00062     public $m_BaseOtherSQLRule = null;  // support expression
00063 
00069     public $m_MainTable = "";
00070 
00076     public $m_BizRecord = null;
00077 
00083     public $m_InheritFrom;
00084     
00091     public $m_AccessRule = null;
00092     
00097     public $m_UpdateCondition = null;   // support expression
00098     
00103     public $m_DeleteCondition = null;   // support expression
00104     
00110     public $m_IdGeneration = null;
00111     
00117     public $m_ObjReferences = null;
00118 
00124     public $m_TableJoins = null;
00125 
00130     public $m_Parameters = null;
00131     public $m_Stateless = null;
00132     public $m_Uniqueness = null;
00133 
00139     public $m_SearchRule = null;        // support expression
00140 
00145     public $m_SortRule = null;          // support expression
00146 
00152     public $m_OtherSQLRule = null;      // support expression
00153 
00159     public $m_CacheLifeTime = null;           // set 0 to disbale cache function
00160 
00166     public $m_MessageFile = null;        // 
00167 
00175     protected $m_Limit = array();
00176 
00182     protected $m_Messages;
00183     
00184     public $m_DataPermControl;
00185     
00192     function __construct(&$xmlArr)
00193     {
00194         $this->readMetadata($xmlArr);
00195         $this->inheritParentObj();
00196     }
00197 
00204     protected function readMetadata(&$xmlArr)
00205     {
00206         parent::readMetaData($xmlArr);
00207         $this->m_InheritFrom = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["INHERITFROM"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["INHERITFROM"] : null;
00208         $this->m_SearchRule = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["SEARCHRULE"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["SEARCHRULE"] : null;
00209         $this->m_BaseSearchRule = $this->m_SearchRule;
00210         $this->m_SortRule = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["SORTRULE"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["SORTRULE"] : null;
00211         $this->m_BaseSortRule = $this->m_SortRule;
00212         $this->m_OtherSQLRule = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["OTHERSQLRULE"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["OTHERSQLRULE"] : null;
00213         $this->m_BaseOtherSQLRule = $this->m_OtherSQLRule;
00214         $this->m_AccessRule = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["ACCESSRULE"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["ACCESSRULE"] : null;
00215         $this->m_UpdateCondition = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["UPDATECONDITION"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["UPDATECONDITION"] : null;
00216         $this->m_DeleteCondition = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["DELETECONDITION"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["DELETECONDITION"] : null;
00217         $this->m_Database = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["DBNAME"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["DBNAME"] : null;
00218         if ($this->m_Database == null)
00219             $this->m_Database = "Default";
00220         $this->m_MainTable = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["TABLE"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["TABLE"] : null;
00221         $this->m_IdGeneration = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["IDGENERATION"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["IDGENERATION"] : null;
00222         $this->m_Stateless = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["STATELESS"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["STATELESS"] : null;
00223 
00224         // read in uniqueness attribute
00225         $this->m_Uniqueness = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["UNIQUENESS"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["UNIQUENESS"] : null;
00226 
00227         $this->m_CacheLifeTime = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["CACHELIFETIME"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["CACHELIFETIME"] : "0";
00228         $this->m_Name = $this->prefixPackage($this->m_Name);
00229         if ($this->m_InheritFrom == '@sourceMeta') $this->m_InheritFrom = '@'.$this->m_Name;
00230         else $this->m_InheritFrom = $this->prefixPackage($this->m_InheritFrom);
00231 
00232         // build BizRecord
00233         $this->m_BizRecord = new BizRecord($xmlArr["BIZDATAOBJ"]["BIZFIELDLIST"]["BIZFIELD"],"BizField",$this);
00234         // build TableJoins
00235         $this->m_TableJoins = new MetaIterator($xmlArr["BIZDATAOBJ"]["TABLEJOINS"]["JOIN"],"TableJoin",$this);
00236         // build ObjReferences
00237         $this->m_ObjReferences = new MetaIterator($xmlArr["BIZDATAOBJ"]["OBJREFERENCES"]["OBJECT"],"ObjReference",$this);
00238         // read in parameters
00239         $this->m_Parameters = new MetaIterator($xmlArr["BIZDATAOBJ"]["PARAMETERS"]["PARAMETER"],"Parameter");
00240 
00241         $this->m_MessageFile = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["MESSAGEFILE"]) ? $xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["MESSAGEFILE"] : null;
00242         $this->m_Messages = Resource::loadMessage($this->m_MessageFile , $this->m_Package);
00243         
00244         $this->m_DataPermControl = isset($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["DATAPERMCONTROL"]) ? strtoupper($xmlArr["BIZDATAOBJ"]["ATTRIBUTES"]["DATAPERMCONTROL"]) : 'N';
00245     }
00246 
00252     protected function inheritParentObj()
00253     {
00254         if (!$this->m_InheritFrom) return;
00255         $parentObj = BizSystem::getObject($this->m_InheritFrom);
00256 
00257         $this->m_Description  = $this->m_Description ? $this->m_Description : $parentObj->m_Description;
00258         $this->m_SearchRule   = $this->m_SearchRule ? $this->m_SearchRule : $parentObj->m_SearchRule;
00259         $this->m_BaseSearchRule = $this->m_SearchRule;
00260         $this->m_SortRule     = $this->m_SortRule ? $this->m_SortRule: $parentObj->m_SortRule;
00261         $this->m_BaseSortRule = $this->m_SortRule;
00262         $this->m_OtherSQLRule = $this->m_OtherSQLRule ? $this->m_OtherSQLRule: $parentObj->m_OtherSQLRule;
00263         $this->m_AccessRule   = $this->m_AccessRule ? $this->m_AccessRule: $parentObj->m_AccessRule;
00264         $this->m_UpdateCondition = $this->m_UpdateCondition ? $this->m_UpdateCondition: $parentObj->m_UpdateCondition;
00265         $this->m_DeleteCondition = $this->m_DeleteCondition ? $this->m_DeleteCondition: $parentObj->m_DeleteCondition;
00266         $this->m_Database     = $this->m_Database ? $this->m_Database: $parentObj->m_Database;
00267         $this->m_MainTable    = $this->m_MainTable ? $this->m_MainTable: $parentObj->m_MainTable;
00268         $this->m_IdGeneration = $this->m_IdGeneration ? $this->m_IdGeneration: $parentObj->m_IdGeneration;
00269         $this->m_Stateless    = $this->m_Stateless ? $this->m_Stateless: $parentObj->m_Stateless;
00270               $this->m_DataPermControl = $this->m_DataPermControl ? $this->m_DataPermControl : $parentObj->m_DataPermControl;
00271         $this->m_BizRecord->merge($parentObj->m_BizRecord);
00272 
00273         foreach ($this->m_BizRecord as $field)
00274             $field->adjustBizObjName($this->m_Name);
00275         
00276         $this->m_TableJoins->merge($parentObj->m_TableJoins);
00277         $this->m_ObjReferences->merge($parentObj->m_ObjReferences);
00278         $this->m_Parameters->merge($parentObj->m_Parameters);
00279     }
00280 
00288     protected function getMessage($msgid, $params=array())
00289     {
00290         $message = isset($this->m_Messages[$msgid]) ? $this->m_Messages[$msgid] : constant($msgid);
00291         //$message = I18n::getInstance()->translate($message);
00292         $message = I18n::t($message, $msgid, $this->getModuleName($this->m_Name));
00293         return vsprintf($message,$params);
00294     }
00295 
00301     public function getSessionVars($sessionContext)
00302     {}
00303 
00310     public function setSessionVars($sessCtxt)
00311     {}
00312 
00318     public function resetRules()
00319     {
00320         $this->m_SearchRule = $this->m_BaseSearchRule;
00321         $this->m_SortRule = $this->m_BaseSortRule;
00322         $this->m_OtherSQLRule = $this->m_BaseOtherSQLRule;
00323         return $this;
00324     }
00325 
00332     public function clearSearchRule()
00333     {
00334         $this->m_SearchRule = $this->m_BaseSearchRule;
00335         return $this;
00336     }
00337 
00344     public function clearSortRule()  // reset sortrule
00345 
00346     {
00347         $this->m_SortRule = $this->m_BaseSortRule;
00348         return $this;
00349     }
00350 
00357     public function clearOtherSQLRule()
00358 
00359     {
00360         $this->m_OtherSQLRule = $this->m_BaseOtherSQLRule;
00361         return $this;
00362     }
00363 
00369     public function clearAllRules()
00370     {
00371         $this->m_SearchRule = $this->m_BaseSearchRule;
00372         $this->m_SortRule = $this->m_BaseSortRule;
00373         $this->m_OtherSQLRule = $this->m_BaseOtherSQLRule;
00374         $this->m_Limit = array();
00375         return $this;
00376     }
00377 
00385     public function setSearchRule($rule, $overWrite=false)
00386     {
00387         if (!$rule || $rule == "")
00388             return;
00389         if (!$this->m_SearchRule || $overWrite == true)
00390         {
00391             $this->m_SearchRule = $rule;
00392         }
00393         elseif (strpos($this->m_SearchRule, $rule) === false)
00394         {
00395             $this->m_SearchRule .= " AND " . $rule;
00396         }
00397     }
00398 
00406     public function setQueryParam($queryStr, $paramValues)
00407     {
00408         $this->setSearchRule($queryStr);
00409         foreach ($paramValues as $param=>$value)
00410             $this->m_QueryParams[$param] = $value;
00411     }
00412 
00419     public function setSortRule($rule)
00420     {
00421         // sort rule has format "[fieldName] DESC|ASC", replace [fieldName] with table.column
00422         $this->m_SortRule = $rule;
00423     }
00424 
00431     public function setOtherSQLRule($rule)
00432     {
00433         // $rule has SQL format "GROUP BY [fieldName] HAVING ...". replace [fieldName] with table.column
00434         $this->m_OtherSQLRule = $rule;
00435     }
00436 
00444     public function setLimit($count, $offset=0)
00445     {
00446        if($count<0)
00447        {
00448               $count = 0;
00449        }      
00450         if($offset<0)
00451        {
00452               $offset = 0;
00453        }      
00454         $this->m_Limit['count'] = $count;
00455         $this->m_Limit['offset'] = $offset;
00456     }
00457 
00463        public function getDBConnection($type='default')
00464     {
00465        switch(strtolower($type))
00466        {
00467               case "default":
00468               case "read":
00469                      if($this->m_DatabaseforRead){
00470                             $dbName = $this->m_DatabaseforRead;       
00471                      }
00472                      else
00473                      {
00474                             $dbName = $this->m_Database;
00475                      }
00476                      break;
00477               case "write":
00478                      if($this->m_DatabaseforWrite){
00479                             $dbName = $this->m_DatabaseforWrite;      
00480                      }
00481                      else
00482                      {
00483                             $dbName = $this->m_Database;
00484                      }                    
00485                      break;
00486        }
00487         return BizSystem::dbConnection($dbName);
00488     }
00489 
00496     public function getProperty($propertyName)
00497     {
00498         $ret = parent::getProperty($propertyName);
00499         if ($ret) return $ret;
00500         if ($propertyName == "Table") return $this->m_Table;
00501         if ($propertyName == "SearchRule") return $this->m_SearchRule;
00502         // get control object if propertyName is "Field[fldname]"
00503         $pos1 = strpos($propertyName, "[");
00504         $pos2 = strpos($propertyName, "]");
00505         if ($pos1>0 && $pos2>$pos1)
00506         {
00507             $propType = substr($propertyName, 0, $pos1);
00508             $fieldName = substr($propertyName, $pos1+1,$pos2-$pos1-1);
00509             if ($propType == "param")
00510             {   // get parameter
00511                 return $this->m_Parameters->get($fieldName);
00512             }
00513             return $this->getField($fieldName);
00514         }
00515     }
00516 
00523     public function getParameter($paramName)
00524     {
00525         return $this->m_Parameters[$paramName]->m_Value;
00526     }
00527 
00534     public function getRefObject($objName)
00535     {
00536         // see if there is such object in the ObjReferences
00537         $objRef = $this->m_ObjReferences->get($objName);
00538         if (!$objRef)
00539             return null;
00540 
00541         // apply association on the object
00542         // $assc = $this->EvaluateExpression($objRef->m_Association);
00543 
00544         // get the object instance
00545         $obj = BizSystem::getObject($objName);
00546         $obj->setAssociation($objRef, $this);
00547         return $obj;
00548     }
00549 
00555     public function getAssociation()
00556     {
00557         return $this->m_Association;
00558     }
00559 
00567     protected function setAssociation($objRef, $asscObj)
00568     {
00569         $this->m_Association["AsscObjName"] = $asscObj->m_Name;
00570         $this->m_Association["Relationship"] = $objRef->m_Relationship;
00571         $this->m_Association["Table"] = $objRef->m_Table;
00572         $this->m_Association["Column"] = $objRef->m_Column;
00573         $this->m_Association["FieldRef"] = $objRef->m_FieldRef;
00574         $this->m_Association["FieldRefVal"] = $asscObj->getFieldValue($objRef->m_FieldRef);
00575         $this->m_Association["CondColumn"] = $objRef->m_CondColumn;
00576         $this->m_Association["CondValue"] = $objRef->m_CondValue;
00577         $this->m_Association["Condition"] = $objRef->m_Condition;        
00578         if ($objRef->m_Relationship == "M-M" || $objRef->m_Relationship  == "Self-Self")
00579         {
00580             $this->m_Association["XTable"] = $objRef->m_XTable;
00581             $this->m_Association["XColumn1"] = $objRef->m_XColumn1;
00582             $this->m_Association["XColumn2"] = $objRef->m_XColumn2;
00583             $this->m_Association["XKeyColumn"] = $objRef->m_XKeyColumn;
00584             $this->m_Association["XDataObj"] = $objRef->m_XDataObj;
00585         }
00586     }
00587 
00593     abstract public function newRecord();
00594 
00601     abstract public function insertRecord($recArr);
00602 
00610     abstract public function updateRecord($recArr, $oldRec=null);
00611 
00618     abstract public function deleteRecord($recArr);
00619 
00636     abstract public function fetch();
00637 
00655     abstract public function directFetch($searchRule="", $count=-1, $offset=0);
00656 
00678     abstract public function find();
00679 
00686     abstract public function count();
00687 }
00688 ?>

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