Show
Ignore:
Timestamp:
08/29/10 11:03:53 (21 months ago)
Author:
ort
Message:

update ORM by ajaxy

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/engine/classes/ModuleORM.class.php

    r983 r998  
    4141                } elseif ($res) { 
    4242                        // есть автоинкремент, устанавливаем его 
    43                         $oEntity->_setData(array($oEntity->_GetPrimatyKey() => $res)); 
     43                        $oEntity->_setData(array($oEntity->_GetPrimaryKey() => $res)); 
    4444                        return $oEntity; 
    4545                } 
     
    7474                        return $this->_UpdateEntity($oEntity); 
    7575                } 
     76        }        
     77         
     78         
     79        protected function _ReloadEntity($oEntity) { 
     80                if($sPrimaryKey=$oEntity->_getPrimaryKey()) { 
     81                        if($sPrimaryKeyValue=$oEntity->_getDataOne($sPrimaryKey)) { 
     82                                if($oEntityNew=$this->GetByFilter(array($sPrimaryKey=>$sPrimaryKeyValue),Engine::GetEntityName($oEntity))) { 
     83                                        $oEntity->_setData($oEntityNew->_getData()); 
     84                                        return $oEntity; 
     85                                } 
     86                        } 
     87                } 
     88                return false; 
    7689        } 
    7790         
     
    130143                                $sRelEntityName=Engine::GetEntityName($oRelEntityEmpty); 
    131144                                $sRelPluginPrefix=Engine::GetPluginPrefix($oRelEntityEmpty); 
    132                                 // ItemsByArrayId - id пока идет костылем, т.к. у стандартных сущностей нет метода _GetPrimatyKey() 
     145                                // ItemsByArrayId - id пока идет костылем, т.к. у стандартных сущностей нет метода _GetPrimaryKey() 
    133146                                $aRelData=Engine::GetInstance()->_CallModule("{$sRelPluginPrefix}{$sRelModuleName}_get{$sRelEntityName}ItemsByArrayId",array($aEntityKeys[$sRelKey])); 
    134147                                /** 
     
    158171                foreach ($aData as $oEntity) { 
    159172                        // здесь под вопросом какое поле использовать в качестве ключа, всегда примари или тот, который передан? 
    160                         $aEntities[$oEntity->_getDataOne($oEntity->_GetPrimatyKey())]=$oEntity; 
     173                        $aEntities[$oEntity->_getDataOne($oEntity->_GetPrimaryKey())]=$oEntity; 
    161174                } 
    162175                return $aEntities; 
    163176        } 
    164177         
    165         public function __call($sName,$aArgs) {          
     178        public function GetItemsByJoinTable($aJoinData=array(),$sEntityFull=null) { 
     179                if (is_null($sEntityFull)) { 
     180                        $sEntityFull=Engine::GetPluginPrefix($this).'Module'.Engine::GetModuleName($this).'_Entity'.Engine::GetModuleName(get_class($this)); 
     181                } elseif (!substr_count($sEntityFull,'_')) { 
     182                        $sEntityFull=Engine::GetPluginPrefix($this).'Module'.Engine::GetModuleName($this).'_Entity'.$sEntityFull; 
     183                } 
     184                return $this->oMapperORM->GetItemsByJoinTable($aJoinData,$sEntityFull); 
     185        } 
     186         
     187        public function __call($sName,$aArgs) { 
    166188                if (preg_match("@^add([\w]+)$@i",$sName,$aMatch)) { 
    167189                        return $this->_AddEntity($aArgs[0]); 
     
    178200                if (preg_match("@^delete([\w]+)$@i",$sName,$aMatch)) { 
    179201                        return $this->_DeleteEntity($aArgs[0]); 
     202                }        
     203                 
     204                if (preg_match("@^reload([\w]+)$@i",$sName,$aMatch)) { 
     205                        return $this->_ReloadEntity($aArgs[0]); 
    180206                } 
    181207                 
    182208                $sNameUnderscore=func_underscore($sName); 
    183                  
     209                $iEntityPosEnd=strlen($sNameUnderscore)-1;  
     210                if(substr_count($sNameUnderscore,'_items')) { 
     211                        $iEntityPosEnd=strpos($sNameUnderscore,'_items'); 
     212                } else if(substr_count($sNameUnderscore,'_by')) { 
     213                        $iEntityPosEnd=strpos($sNameUnderscore,'_by'); 
     214                } else if(substr_count($sNameUnderscore,'_all')) { 
     215                        $iEntityPosEnd=strpos($sNameUnderscore,'_all'); 
     216                } 
     217                $sEntityName=substr($sNameUnderscore,4,$iEntityPosEnd-4); 
     218                /** 
     219                 * getUserRoleJoinByUserIdAndRoleId() get_user-role-join_by_user_id_and_role_id 
     220                 */ 
     221                $sNameUnderscore=substr_replace($sNameUnderscore,str_replace('_','',$sEntityName),4,$iEntityPosEnd-4); 
     222                $sEntityName=func_camelize($sEntityName); 
    184223                /** 
    185224                 * getUserItemsByArrayId() get_user_items_by_array_id 
    186225                 */ 
    187226                if (preg_match("@^get_([a-z]+)_items_by_array_([_a-z]+)$@i",$sNameUnderscore,$aMatch)) { 
    188                         return $this->GetItemsByArray(array($aMatch[2]=>$aArgs[0]),$aMatch[1]); 
     227                        return $this->GetItemsByArray(array($aMatch[2]=>$aArgs[0]),$sEntityName); 
     228                } 
     229                /** 
     230                 * getUserItemsByJoinTable() get_user_items_by_join_table 
     231                 */ 
     232                if (preg_match("@^get_([a-z]+)_items_by_join_table$@i",$sNameUnderscore,$aMatch)) { 
     233                        return $this->GetItemsByJoinTable($aArgs[0],func_camelize($sEntityName)); 
    189234                } 
    190235                /** 
     
    198243                        $aFilter=array_combine(explode('_and_',$aMatch[5]),$aArgs); 
    199244                        if ($aMatch[2]=='_items') { 
    200                                 return $this->GetItemsByFilter($aFilter,$aMatch[1]); 
     245                                return $this->GetItemsByFilter($aFilter,$sEntityName); 
    201246                        } else {                                 
    202                                 return $this->GetByFilter($aFilter,$aMatch[1]); 
     247                                return $this->GetByFilter($aFilter,$sEntityName); 
    203248                        } 
    204249                } 
     
    211256                                $aFilter=$aArgs[0]; 
    212257                        } 
    213                         return $this->GetItemsByFilter($aFilter,$aMatch[1]); 
     258                        return $this->GetItemsByFilter($aFilter,$sEntityName); 
    214259                } 
    215260