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

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

00001 <?PHP
00017 include_once(OPENBIZ_BIN.'data/BizDataObj_Abstract.php');
00018 
00027 class BizDataObj extends BizDataObj_Lite
00028 {
00035     function __construct(&$xmlArr)
00036     {
00037         parent::__construct($xmlArr);
00038     }
00039 
00046     public function validateInput()
00047     {
00048         $this->m_ErrorFields = array();
00049         foreach($this->m_BizRecord->m_InputFields as $fld)
00050         {
00051 
00052             /* @var $bizField BizField */
00053             $bizField = $this->m_BizRecord->get($fld);
00054             if($bizField->m_Encrypted=="Y"){
00055                    if ($bizField->checkRequired() == true &&
00056                            ($bizField->m_Value===null || $bizField->m_Value === ""))
00057                    {
00058                        $this->m_ErrorMessage = $this->getMessage("DATA_FIELD_REQUIRED",array($fld));
00059                        $this->m_ErrorFields[$bizField->m_Name] = $this->m_ErrorMessage;
00060                    }
00061               continue;
00062             }
00063             if ($bizField->checkRequired() == true &&
00064                     ($bizField->m_Value===null || $bizField->m_Value === ""))
00065             {
00066                 $this->m_ErrorMessage = $this->getMessage("DATA_FIELD_REQUIRED",array($fld));
00067                 $this->m_ErrorFields[$bizField->m_Name] = $this->m_ErrorMessage;
00068             }
00069             elseif ($bizField->m_Value!==null && $bizField->checkValueType() == false)
00070             {
00071                 $this->m_ErrorMessage = $this->getMessage("DATA_FIELD_INCORRECT_TYPE", array($fld, $bizField->m_Type));
00072                 $this->m_ErrorFields[$bizField->m_Name] = $this->m_ErrorMessage;
00073             }
00074             elseif ($bizField->m_Value!==null && $bizField->Validate() == false)
00075             {
00076 
00077                 /* @var $validateService validateService */
00078                 $validateService = BizSystem::getService(VALIDATE_SERVICE);
00079                 $this->m_ErrorMessage = $validateService->getErrorMessage($bizField->m_Validator, $bizField->m_Name);
00080                 if ($this->m_ErrorMessage == false)
00081                 { //Couldn't get a clear error message so let's try this
00082                     $this->m_ErrorMessage = $this->getMessage("DATA_FIELD_INVALID_INPUT",array($fld,$value,$bizField->m_Validator));                //
00083                 }
00084                 $this->m_ErrorFields[$bizField->m_Name] = $this->m_ErrorMessage;
00085             }
00086         }
00087         if (count($this->m_ErrorFields)>0)
00088         {
00089             //print_r($this->m_ErrorFields);
00090             throw new ValidationException($this->m_ErrorFields);
00091             return false;
00092         }
00093 
00094         // validate uniqueness
00095         if ($this->validateUniqueness() == false)
00096             return false;
00097 
00098         return true;
00099     }
00100 
00107     protected function validateUniqueness()
00108     {
00109         if (!$this->m_Uniqueness)
00110             return true;
00111         $groupList = explode(";",$this->m_Uniqueness);
00112         foreach ($groupList as $group)
00113         {
00114             $searchRule = "";
00115             $needCheck = true;
00116             $fields = explode(",",$group);
00117             foreach ($fields as $fld)
00118             {
00119                 $bizField = $this->m_BizRecord->get($fld);
00120                 if ($bizField->m_Value===null || $bizField->m_Value === "" || $bizField->m_Value==$bizField->m_OldValue)
00121                 {
00122                     $needCheck = false;
00123                     break;
00124                 }
00125                 if ($searchRule == "")
00126                     $searchRule = "[".$bizField->m_Name."]='".addslashes($bizField->m_Value)."'";
00127                 else
00128                     $searchRule .= " AND [".$bizField->m_Name."]='".addslashes($bizField->m_Value)."'";
00129             }
00130             if ($needCheck)
00131             {
00132                 $recordList = $this->directFetch($searchRule, 1);                
00133                 if ($recordList->count()>0)
00134                 {
00135                     $this->m_ErrorMessage = $this->getMessage("DATA_NOT_UNIQUE",array($group));
00136                     foreach ($fields as $fld)
00137                     {
00138                         $this->m_ErrorFields[$fld] = $this->m_ErrorMessage;
00139                     }
00140                 }
00141             }
00142         }
00143         if (count($this->m_ErrorFields)>0)
00144         {
00145             throw new ValidationException($this->m_ErrorFields);
00146             return false;
00147         }
00148         return true;
00149     }
00150 
00156     public function canUpdateRecord($record = null)
00157     {
00158        
00159        if($this->m_DataPermControl=='Y')
00160         {
00161                $svcObj = BizSystem::GetService(DATAPERM_SERVICE);
00162                if(!$record)
00163                {
00164                      $record = $this->getActiveRecord();
00165                }
00166                $result = $svcObj->checkDataPerm($record,2,$this);
00167                if($result == false)
00168                {
00169                      return false;
00170                }
00171         }
00172        
00173         $result = $this->canUpdateRecordCondition();
00174         return $result;
00175     }
00176     
00177     public function canUpdateRecordCondition()
00178     {         
00179         if ($this->m_UpdateCondition)
00180         {
00181             //return Expression::evaluateExpression($this->m_UpdateCondition,$this);
00182             return $this->allowAccess($this->m_UpdateCondition);
00183         }
00184         return true;
00185     }
00191     public function canDeleteRecord($record = null)
00192     {
00193        if($this->m_DataPermControl=='Y')
00194         {
00195                $svcObj = BizSystem::GetService(DATAPERM_SERVICE);
00196                if(!$record)
00197                {
00198                      $record = $this->getActiveRecord();
00199                }
00200                $result = $svcObj->checkDataPerm($record,3,$this);
00201                if($result == false)
00202                {
00203                      return false;
00204                }
00205         }
00206        
00207         $result = $this->canDeleteRecordCondition();
00208         return $result;
00209     }
00210 
00211     public function canDeleteRecordCondition()
00212     {         
00213         if ($this->m_DeleteCondition)
00214         {
00215             // return Expression::evaluateExpression($this->m_DeleteCondition,$this);
00216             return $this->allowAccess($this->m_DeleteCondition);
00217         }
00218         return true;
00219     }    
00227     public function updateRecord($recArr, $oldRecord=null)
00228     {
00229         if (!$this->canUpdateRecord($oldRecord))
00230         {
00231             $this->m_ErrorMessage = BizSystem::getMessage("DATA_NO_PERMISSION_UPDATE",$this->m_Name);
00232             throw new BDOException($this->m_ErrorMessage);
00233             return false;
00234         }
00235 
00236         if (!$oldRecord)
00237             $oldRecord = $this->getActiveRecord();
00238 
00239         if (!$recArr["Id"])
00240             $recArr["Id"] = $this->getFieldValue("Id");
00241 
00242         // save the old values
00243         $this->m_BizRecord->saveOldRecord($oldRecord);
00244         // set the new values
00245         $this->m_BizRecord->setInputRecord($recArr);
00246 
00247         if (!$this->validateInput()) return false;
00248         
00249         QueryStringParam::reset();
00250 
00251         $sql = $this->getSQLHelper()->buildUpdateSQL($this);
00252 
00253         if ($sql)
00254         {
00255             $db = $this->getDBConnection("WRITE");
00256             $db->beginTransaction();
00257             try
00258             {
00259                 $this->cascadeUpdate(); // cascade update
00260                 
00261                 $bindValues = QueryStringParam::getBindValues();
00262                 $bindValueString = QueryStringParam::getBindValueString();
00263                 BizSystem::log(LOG_DEBUG, "DATAOBJ", "Update Sql = $sql"."; BIND: $bindValueString");
00264                 QueryStringParam::reset();
00265                 $db->query($sql, $bindValues);
00266                 
00267                 $db->commit();
00268             }
00269             catch (Exception $e)
00270             {
00271                 $db->rollBack();
00272                 if ($e instanceof BDOException)
00273                     throw $e;
00274                 else {
00275                     BizSystem::log(LOG_ERR, "DATAOBJ", "Query error : ".$e->getMessage());
00276                     $this->m_ErrorMessage = $this->getMessage("DATA_ERROR_QUERY").": ".$sql.". ".$e->getMessage();
00277                     throw new BDOException($this->m_ErrorMessage);
00278                 }
00279                 return false;
00280             }
00281 
00282             $this->cleanCache(); //clean cached data
00283             $this->_postUpdateLobFields($recArr);
00284             $this->m_CurrentRecord = null; 
00285             $this->_postUpdateRecord($recArr);
00286         }
00287         return true;
00288     }
00289 
00290     public function updateRecords($setValue, $condition = null)
00291     {
00292         if (!$this->canUpdateRecordCondition())
00293         {
00294             $this->m_ErrorMessage = BizSystem::getMessage("DATA_NO_PERMISSION_UPDATE",$this->m_Name);
00295             return false;
00296         }
00297 
00298         $sql = $this->getSQLHelper()->buildUpdateSQLwithCondition($this,$setValue ,$condition);
00299         $db = $this->getDBConnection("WRITE");
00300 
00301         try
00302         {
00303             if($sql)
00304             {        // delete joint table first then delete main table's data'
00305                 BizSystem::log(LOG_DEBUG, "DATAOBJ", "Delete Sql = $sql");
00306                 $db->query($sql);
00307             }
00308         }
00309         catch (Exception $e)
00310         {
00311             BizSystem::log(LOG_ERR, "DATAOBJ", "Query error : ".$e->getMessage());
00312             $this->m_ErrorMessage = $this->getMessage("DATA_ERROR_QUERY").": ".$sql.". ".$e->getMessage();
00313             throw new BDOException($this->m_ErrorMessage);
00314             return false;
00315         }
00316 
00317         //clean cached data
00318         $this->cleanCache();
00319         return true;
00320     }
00328     private function _postUpdateLobFields(&$recArr)
00329     {
00330         $searchRule = $this->m_BizRecord->getKeySearchRule(false, true);
00331         foreach ($this->m_BizRecord as $field)
00332         {
00333             if (isset($recArr[$field->m_Name]) && $field->isLobField() && $field->m_Column != "")
00334             {
00335                 $db = $this->getDBConnection("WRITE");
00336                 $sql = "UPDATE " . $this->m_MainTable . " SET " . $field->m_Column . "=? WHERE $searchRule";
00337                 BizSystem::log(LOG_DEBUG, "DATAOBJ", "Update lob Sql = $sql");
00338                 $stmt = $db->prepare($sql);
00339 
00340                 $fp = fopen($recArr[$field->m_Name], 'rb');
00341                 $stmt->bindParam(1, $fp, PDO::PARAM_LOB);
00342 
00343                 try
00344                 {
00345                     $stmt->execute();
00346                 }
00347                 catch (Exception $e)
00348                 {
00349                     $this->m_ErrorMessage = $this->getMessage("DATA_ERROR_QUERY").": ".$sql.". ".$e->getMessage();
00350                     BizSystem::log(LOG_ERR, "DATAOBJ", "Update lob error = $sql");
00351                     fclose($fp);
00352                     throw new BDOException($this->m_ErrorMessage);
00353                     return null;
00354                 }
00355 
00356                 fclose($fp);
00357                 return true;
00358             }
00359         }
00360         return true;
00361     }
00362 
00369     private function _postUpdateRecord($recArr)
00370     {
00371         // run DO trigger
00372         $this->_runDOTrigger("UPDATE");
00373     }
00374 
00380     public function newRecord()
00381     {
00382         $recArr = $this->m_BizRecord->getEmptyRecordArr();
00383 
00384         // if association is 1-M, set the field (pointing to the column) value as the FieldRefVal
00385         if ($this->m_Association["Relationship"] == "1-M")
00386         {
00387             foreach ($this->m_BizRecord as $field)
00388             {
00389                 if ($field->m_Column == $this->m_Association["Column"] && !$field->m_Join)
00390                 {
00391                     $recArr[$field->m_Name] = $this->m_Association["FieldRefVal"];
00392                     break;
00393                 }
00394             }
00395         }
00396 
00397         return $recArr;
00398     }
00399 
00408     protected function generateId($isBeforeInsert=true, $tableName=null, $idCloumnName=null)
00409     {
00410         // Identity type id is generated after insert is done.
00411         // If this method is called before insert, return null.
00412         if ($isBeforeInsert && $this->m_IdGeneration == 'Identity')
00413             return null;
00414 
00415         if (!$isBeforeInsert && $this->m_IdGeneration != 'Identity')
00416         {
00417             $this->m_ErrorMessage = BizSystem::getMessage( "DATA_UNABLE_GET_ID",$this->m_Name);
00418             return false;
00419         }
00420 
00421         /* @var $genIdService genIdService */
00422         $genIdService = BizSystem::getService(GENID_SERVICE);
00423         if($this->m_db){
00424               $db = $this->m_db;
00425         }else{
00426               $db = $this->getDBConnection("READ");
00427         }
00428         $dbInfo = BizSystem::Configuration()->getDatabaseInfo($this->m_Database);
00429         $dbType = $dbInfo["Driver"];
00430         $table = $tableName ? $tableName : $this->m_MainTable;
00431         $column = $idCloumnName ? $idCloumnName : $this->getField("Id")->m_Column;
00432 
00433         try
00434         {
00435             $newId = $genIdService->getNewID($this->m_IdGeneration, $db, $dbType, $table, $column);
00436         }
00437         catch (Exception $e)
00438         {
00439             $this->m_ErrorMessage = $e->getMessage();
00440             return false;
00441         }
00442         return $newId;
00443     }
00444 
00451     public function insertRecord($recArr)
00452     {
00453         if ( $this->_isNeedGenerateId($recArr) )
00454             $recArr["Id"] = $this->generateId();    // for certain cases, id is generated before insert
00455 
00456         $this->m_BizRecord->setInputRecord($recArr);
00457 
00458         if (!$this->validateInput()) return false;
00459 
00460         $db = $this->getDBConnection("WRITE");
00461 
00462         try
00463         {
00464             $sql = $this->getSQLHelper()->buildInsertSQL($this, $joinValues);
00465             if($sql)
00466             {
00467                 $bindValues = QueryStringParam::getBindValues();
00468                 $bindValueString = QueryStringParam::getBindValueString();
00469                 BizSystem::log(LOG_DEBUG, "DATAOBJ", "Insert Sql = $sql"."; BIND: $bindValueString");
00470                 QueryStringParam::reset();
00471                 $db->query($sql, $bindValues);                
00472             }
00473             //$mainId = $db->lastInsertId();
00474             if ( $this->_isNeedGenerateId($recArr) )
00475             {
00476               $this->m_db = $db; //compatiable for CLI mode and also speed up of it running
00477                 $mainId = $this->generateId(false);
00478                 $recArr["Id"] = $mainId;
00479             }
00480             BizSystem::log(LOG_DEBUG, "DATAOBJ", "New record Id is ".$recArr["Id"]);
00481         }
00482         catch (Exception $e)
00483         {
00484             BizSystem::log(LOG_ERR, "DATAOBJ", "Query Error : " . $e->getMessage());
00485             $this->m_ErrorMessage = $this->getMessage("DATA_ERROR_QUERY").": ".$sql.". ".$e->getMessage();
00486             throw new BDOException($this->m_ErrorMessage);
00487             return null;
00488         }
00489 
00490         $this->m_BizRecord->setInputRecord($recArr);
00491 
00492         if ($this->_postUpdateLobFields($recArr) === false)
00493         {
00494             $this->m_ErrorMessage = $db->ErrorMsg();
00495             return false;
00496         }
00497 
00498         $this->cleanCache();
00499 
00500         $this->m_RecordId = $recArr["Id"];
00501         $this->m_CurrentRecord = null;
00502 
00503         $this->_postInsertRecord($recArr);
00504 
00505         return $recArr["Id"];
00506     }
00507 
00513     private function _postInsertRecord($recArr)
00514     {
00515         // do trigger
00516         $this->_runDOTrigger("INSERT");
00517     }
00518 
00525     public function deleteRecord($recArr)
00526     {         
00527         if (!$this->canDeleteRecord())
00528         {            
00529             $this->m_ErrorMessage = BizSystem::getMessage("DATA_NO_PERMISSION_DELETE",$this->m_Name);
00530             throw new BDOException($this->m_ErrorMessage);
00531             return false;
00532         }
00533 
00534         if ($recArr)
00535             $this->m_BizRecord->setInputRecord($recArr);
00536         else
00537             $this->m_BizRecord->setInputRecord($this->getActiveRecord());
00538 
00539         $sql = $this->getSQLHelper()->buildDeleteSQL($this);
00540         if ($sql)
00541         {
00542             $db = $this->getDBConnection("WRITE");
00543             $db->beginTransaction();
00544             try
00545             {
00546                 $this->cascadeDelete(); // cascade delete
00547 
00548                 BizSystem::log(LOG_DEBUG, "DATAOBJ", "Delete Sql = $sql");
00549                 $db->query($sql);
00550 
00551                 $db->commit();
00552             }
00553             catch (Exception $e)
00554             {
00555                 $db->rollBack();
00556                 if ($e instanceof BDOException)
00557                     throw $e;
00558                 else {
00559                     BizSystem::log(LOG_ERR, "DATAOBJ", "Query error : ".$e->getMessage());
00560                     $this->m_ErrorMessage = $this->getMessage("DATA_ERROR_QUERY").": ".$sql.". ".$e->getMessage();
00561                     throw new BDOException($this->m_ErrorMessage);
00562                 }
00563                 return false;
00564             }
00565         }
00566 
00567         //clean cached data
00568         $this->cleanCache();
00569 
00570         $this->_postDeleteRecord($this->m_BizRecord->getKeyValue());
00571         return true;
00572     }
00573 
00574     public function deleteRecords($condition = null)
00575     {
00576         if (!$this->canDeleteRecordCondition())
00577         {
00578             throw new BDOException( BizSystem::getMessage("DATA_NO_PERMISSION_DELETE",$this->m_Name) );
00579             return false;
00580         }
00581 
00582 
00583         $sql = $this->getSQLHelper()->buildDeleteSQLwithCondition($this,$condition);
00584         $db = $this->getDBConnection("WRITE");
00585 
00586         try
00587         {
00588             if($sql)
00589             {        // delete joint table first then delete main table's data'
00590                 BizSystem::log(LOG_DEBUG, "DATAOBJ", "Delete Sql = $sql");
00591                 $db->query($sql);
00592             }
00593         }
00594         catch (Exception $e)
00595         {
00596             BizSystem::log(LOG_ERR, "DATAOBJ", "Query error : ".$e->getMessage());
00597             $db->rollBack(); //if one failed then rollback all
00598             $this->m_ErrorMessage = $this->getMessage("DATA_ERROR_QUERY").": ".$sql.". ".$e->getMessage();
00599             throw new BDOException($this->m_ErrorMessage);
00600             return false;
00601         }
00602 
00603         //clean cached data
00604         $this->cleanCache();
00605         return true;
00606     }
00607 
00613     private function _postDeleteRecord()
00614     {
00615         // do trigger
00616         $this->_runDOTrigger("DELETE");
00617     }
00618     
00619     // $action: Delete, Update
00620     protected function processCascadeAction($objRef, $cascadeType)
00621     {
00622         if (($cascadeType=='Delete' && $objRef->m_OnDelete)
00623             || ($cascadeType=='Update' && $objRef->m_OnUpdate))
00624         {
00625             if ($objRef->m_Relationship == "1-M" || $objRef->m_Relationship == "1-1") {
00626                 $table = $objRef->m_Table;
00627                 $column = $objRef->m_Column;
00628                 $column2 = $objRef->m_Column2;
00629             }
00630             else if ($objRef->m_Relationship == "M-M" || $objRef->m_Relationship == "Self-Self") {
00631                 $table = $objRef->m_XTable;
00632                 $column = $objRef->m_XColumn1;
00633             }
00634             $refField = $this->getField($objRef->m_FieldRef);
00635             $fieldVal = $this->getFieldValue($objRef->m_FieldRef);
00636             
00637             $fieldVal2 = $this->getFieldValue($objRef->m_FieldRef2);
00638             if (!$fieldVal) return;      
00639             if($column2){     
00640               if (!$fieldVal2) return;
00641             }
00642 
00643             $db = $this->getDBConnection("WRITE");
00644             // get the cascade action sql
00645             if ($cascadeType=='Delete') {
00646                 if ($objRef->m_OnDelete == "Cascade") {
00647                     $sql = "DELETE FROM ".$table." WHERE ".$column."='".$fieldVal."'";
00648                     if($column2 && $fieldVal2){
00649                      $sql .= " AND ".$column2."='".$fieldVal2."'";    
00650                     }
00651                 }
00652                 else if ($objRef->m_OnDelete == "SetNull") {
00653                     $sql = "UPDATE ".$table." SET $column=null WHERE ".$column."='".$fieldVal."'";
00654                      if($column2 && $fieldVal2){
00655                      $sql .= " AND ".$column2."='".$fieldVal2."'";    
00656                     }
00657                 }
00658                 else if ($objRef->m_OnDelete == "Restrict") {
00659                     // check if objRef has records
00660                     $refObj = $this->getRefObject($objRef->m_Name);  
00661                      $sql = "`$column`='".$refField->m_Value."'";
00662                     if($column2 && $fieldVal2){
00663                      $sql .= " AND ".$column2."='".$fieldVal2."'";    
00664                     }                  
00665                     if (count($refObj->directFetch($sql,1)) == 1) {
00666                         throw new BDOException($this->getMessage("DATA_UNABLE_DEL_REC_CASCADE",array($objRef->m_Name)));
00667                     }
00668                     return;
00669                 }
00670             }
00671             else if ($cascadeType=='Update') {
00672                 // check if the column value is actually changed
00673                 if ($refField->m_OldValue == $refField->m_Value) return;
00674                 
00675                 if ($objRef->m_OnUpdate == "Cascade") {
00676                     $sql = "UPDATE ".$table." SET $column='".$refField->m_Value."' WHERE ".$column."='".$refField->m_OldValue."'";
00677                             if($column2 && $fieldVal2){
00678                      $sql .= " AND ".$column2."='".$fieldVal2."'";    
00679                     }
00680                 }
00681                 else if ($objRef->m_OnUpdate == "SetNull") {
00682                     $sql = "UPDATE ".$table." SET $column=null WHERE ".$column."='".$refField->m_OldValue."'";
00683                      if($column2 && $fieldVal2){
00684                      $sql .= " AND ".$column2."='".$fieldVal2."'";    
00685                     }
00686                 }
00687                 else if ($objRef->m_OnUpdate == "Restrict") {
00688                     // check if objRef has records
00689                     $refObj = BizSystem::getObject($objRef->m_Name);
00690                                    $sql = "[".$objRef->m_FieldRef."]='".$refField->m_OldValue."'";
00691                     if($column2 && $fieldVal2){
00692                      $sql .= " AND ".$column2."='".$fieldVal2."'";    
00693                     }
00694                     if (count($refObj->directFetch($sql,1)) == 1) {
00695                         throw new BDOException($this->getMessage("DATA_UNABLE_UPD_REC_CASCADE",array($objRef->m_Name)));
00696                     }
00697                     return;
00698                 }
00699             }
00700             try {
00701                 BizSystem::log(LOG_DEBUG, "DATAOBJ", "Cascade $cascadeType Sql = $sql");
00702                 $db->query($sql);
00703             }
00704             catch (Exception $e) {
00705                 BizSystem::log(LOG_Err, "DATAOBJ", "Cascade $cascadeType Error: ".$e->getMessage());
00706                 $this->m_ErrorMessage = $this->getMessage("DATA_ERROR_QUERY").": ".$sql.". ".$e->getMessage();
00707                 throw new BDOException($this->m_ErrorMessage);
00708             }
00709         }
00710     }
00711     
00716     protected function cascadeDelete()
00717     {
00718         foreach ($this->m_ObjReferences as $objRef) {
00719             $this->processCascadeAction($objRef, "Delete");
00720         }
00721     }
00722     
00727     protected function cascadeUpdate()
00728     {
00729         foreach ($this->m_ObjReferences as $objRef) {
00730             $this->processCascadeAction($objRef, "Update");
00731         }
00732     }
00733 
00739     public function getOnAuditFields()
00740     {
00741         $fieldList = array();
00742         foreach ($this->m_BizRecord as $field)
00743         {
00744             if ($field->m_OnAudit)
00745                 $fieldList[] = $field;
00746         }
00747         return $fieldList;
00748     }
00749 
00755     private function _runDOTrigger($triggerType)
00756     {
00757         // locate the trigger metadata file BOName_Trigger.xml
00758         $triggerServiceName = $this->m_Name."_Trigger";
00759         $xmlFile = BizSystem::GetXmlFileWithPath ($triggerServiceName);
00760         if (!$xmlFile) return;
00761 
00762         $triggerService = BizSystem::getObject($triggerServiceName);
00763         if ($triggerService == null)
00764             return;
00765         // invoke trigger service ExecuteTrigger($triggerType, $currentRecord)
00766 
00767         $triggerService->execute($this, $triggerType);
00768 
00769     }
00770 
00777     public function getJoinFields($joinDataObj)
00778     {
00779         // get the maintable of the joindataobj
00780         $joinTable = $joinDataObj->m_MainTable;
00781         $returnRecord = array();
00782 
00783         // find the proper join according to the maintable
00784         foreach ($this->m_TableJoins as $tableJoin)
00785         {
00786             if ($tableJoin->m_Table == $joinTable)
00787             {
00788                 // populate the column-fieldvalue to columnRef-fieldvalue
00789                 // get the field mapping to the column, then get the field value
00790                 $joinFieldName = $joinDataObj->m_BizRecord->getFieldByColumn($tableJoin->m_Column); // joined-main table
00791 
00792                 if (!$joinFieldName) continue;
00793 
00794                 $refFieldName = $this->m_BizRecord->getFieldByColumn($tableJoin->m_ColumnRef); // join table
00795                 $returnRecord[$refFieldName] = $joinFieldName;
00796 
00797                 // populate joinRecord's field to current record
00798                 foreach ($this->m_BizRecord as $field)
00799                 {
00800                     if ($field->m_Join == $tableJoin->m_Name)
00801                     {
00802                         // use join column to match joinRecord field's column
00803                         $jFieldName = $joinDataObj->m_BizRecord->getFieldByColumn($field->m_Column); // joined-main table
00804                         $returnRecord[$field->m_Name] = $jFieldName;
00805                     }
00806                 }
00807                 break;
00808             }
00809         }
00810         return $returnRecord;
00811     }
00812 
00820     public function joinRecord($joinDataObj, $joinName="")
00821     {
00822         // get the maintable of the joindataobj
00823         $joinTable = $joinDataObj->m_MainTable;
00824         $joinRecord = null;
00825         $returnRecord = array();
00826 
00827         // find the proper join according to join name and the maintable
00828         foreach ($this->m_TableJoins as $tableJoin)
00829         {
00830             if (($joinName == $tableJoin->m_Name || $joinName == "")
00831                     && $tableJoin->m_Table == $joinTable)
00832             {
00833                 // populate the column-fieldvalue to columnRef-fieldvalue
00834                 // get the field mapping to the column, then get the field value
00835                 $joinFieldName = $joinDataObj->m_BizRecord->getFieldByColumn($tableJoin->m_Column); // joined-main table
00836                 if (!$joinFieldName) continue;
00837                 if (!$joinRecord)
00838                     $joinRecord = $joinDataObj->getActiveRecord();
00839                 $refFieldName = $this->m_BizRecord->getFieldByColumn($tableJoin->m_ColumnRef); // join table
00840                 $returnRecord[$refFieldName] = $joinRecord[$joinFieldName];
00841                 // populate joinRecord's field to current record
00842                 foreach ($this->m_BizRecord as $fld)
00843                 {
00844                     if ($fld->m_Join == $tableJoin->m_Name)
00845                     {
00846                         // use join column to match joinRecord field's column
00847                         $jfldname = $joinDataObj->m_BizRecord->getFieldByColumn($fld->m_Column); // joined-main table
00848                         $returnRecord[$fld->m_Name] = $joinRecord[$jfldname];
00849                     }
00850                 }
00851                 break;
00852             }
00853         }
00854         // return a modified record with joined record data
00855         return $returnRecord;
00856     }
00857 
00865     public function addRecord($recArr, &$isParentObjUpdated)
00866     {
00867        $oldBaseSearchRule=$this->m_BaseSearchRule;
00868        $this->m_BaseSearchRule="";
00869         $result = BizDataObj_Assoc::addRecord($this, $recArr, $isParentObjUpdated);
00870         //$this->m_BaseSearchRule=$oldBaseSearchRule;
00871         return $result;
00872     }
00873 
00881     public function removeRecord($recArr, &$isParentObjUpdated)
00882     {
00883         return BizDataObj_Assoc::removeRecord($this, $recArr, $isParentObjUpdated);
00884     }
00885 
00892     public function cleanCache()
00893     {
00894         if($this->m_CacheLifeTime > 0)
00895         {
00896             $cacheSvc = BizSystem::getService(CACHE_SERVICE,1);
00897             $cacheSvc->init($this->m_Name, $this->m_CacheLifeTime);
00898             $cacheSvc->cleanAll();
00899             
00900         }
00901     }
00902 
00909     private function _isNeedGenerateId($recArr)
00910     {
00911         if ($this->m_IdGeneration != 'None' && (!$recArr["Id"] || $recArr["Id"] == "")) return true;
00912         if ($this->m_IdGeneration == 'Identity') return true;
00913     }
00914 
00915 }
00916 
00917 ?>

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