Changeset 998 for trunk/engine/classes/ModuleORM.class.php
- Timestamp:
- 08/29/10 11:03:53 (21 months ago)
- Files:
-
- 1 modified
-
trunk/engine/classes/ModuleORM.class.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/engine/classes/ModuleORM.class.php
r983 r998 41 41 } elseif ($res) { 42 42 // есть автоинкремент, устанавливаем его 43 $oEntity->_setData(array($oEntity->_GetPrima tyKey() => $res));43 $oEntity->_setData(array($oEntity->_GetPrimaryKey() => $res)); 44 44 return $oEntity; 45 45 } … … 74 74 return $this->_UpdateEntity($oEntity); 75 75 } 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; 76 89 } 77 90 … … 130 143 $sRelEntityName=Engine::GetEntityName($oRelEntityEmpty); 131 144 $sRelPluginPrefix=Engine::GetPluginPrefix($oRelEntityEmpty); 132 // ItemsByArrayId - id пока идет костылем, т.к. у стандартных сущностей нет метода _GetPrima tyKey()145 // ItemsByArrayId - id пока идет костылем, т.к. у стандартных сущностей нет метода _GetPrimaryKey() 133 146 $aRelData=Engine::GetInstance()->_CallModule("{$sRelPluginPrefix}{$sRelModuleName}_get{$sRelEntityName}ItemsByArrayId",array($aEntityKeys[$sRelKey])); 134 147 /** … … 158 171 foreach ($aData as $oEntity) { 159 172 // здесь под вопросом какое поле использовать в качестве ключа, всегда примари или тот, который передан? 160 $aEntities[$oEntity->_getDataOne($oEntity->_GetPrima tyKey())]=$oEntity;173 $aEntities[$oEntity->_getDataOne($oEntity->_GetPrimaryKey())]=$oEntity; 161 174 } 162 175 return $aEntities; 163 176 } 164 177 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) { 166 188 if (preg_match("@^add([\w]+)$@i",$sName,$aMatch)) { 167 189 return $this->_AddEntity($aArgs[0]); … … 178 200 if (preg_match("@^delete([\w]+)$@i",$sName,$aMatch)) { 179 201 return $this->_DeleteEntity($aArgs[0]); 202 } 203 204 if (preg_match("@^reload([\w]+)$@i",$sName,$aMatch)) { 205 return $this->_ReloadEntity($aArgs[0]); 180 206 } 181 207 182 208 $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); 184 223 /** 185 224 * getUserItemsByArrayId() get_user_items_by_array_id 186 225 */ 187 226 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)); 189 234 } 190 235 /** … … 198 243 $aFilter=array_combine(explode('_and_',$aMatch[5]),$aArgs); 199 244 if ($aMatch[2]=='_items') { 200 return $this->GetItemsByFilter($aFilter,$ aMatch[1]);245 return $this->GetItemsByFilter($aFilter,$sEntityName); 201 246 } else { 202 return $this->GetByFilter($aFilter,$ aMatch[1]);247 return $this->GetByFilter($aFilter,$sEntityName); 203 248 } 204 249 } … … 211 256 $aFilter=$aArgs[0]; 212 257 } 213 return $this->GetItemsByFilter($aFilter,$ aMatch[1]);258 return $this->GetItemsByFilter($aFilter,$sEntityName); 214 259 } 215 260
