6 DEFINE(
'ACTION_NA', 0);
 
    7 DEFINE(
'ACTION_DELETE', 1);
 
    8 DEFINE(
'ACTION_INSERT', 2);
 
    9 DEFINE(
'ACTION_UPDATE', 3);
 
   10 DEFINE(
'ACTION_UPDATE_STOCK', 4);
 
  186         $this->_blUseSkipSaveFields = $blUseSkipSaveFields;
 
  199         if ( $this->_blUseLazyLoading ) {
 
  200             $this->_sCacheKey .= 
$myConfig->getActiveView()->getClassName();
 
  202             $this->_sCacheKey .= 
'allviews';
 
  207             $this->_sCacheKey = null;
 
  221     public function __set( $sName, $sValue )
 
  223         $this->$sName = $sValue;
 
  224         if ( $this->_blUseLazyLoading && strpos( $sName, $this->_sCoreTable . 
'__' ) === 0 ) {
 
  225             $sFieldName = str_replace( $this->_sCoreTable . 
"__", 
'', $sName );
 
  226             if ( $sFieldName != 
'oxnid' && ( !isset( $this->_aFieldNames[$sFieldName] ) || !$this->_aFieldNames[$sFieldName] ) ) {
 
  228                 if ( isset( $aAllFields[strtolower($sFieldName)] ) ) {
 
  230                     $this->
_addField( $sFieldName, $iFieldStatus );
 
  250                 return $this->
getId();
 
  260         if ( $this->_blUseLazyLoading && stripos( $sName, $this->_sCoreTable . 
"__" ) === 0 ) {
 
  262             if ( $this->
getId() ) {
 
  265                 $sFieldName      = str_replace( $this->_sCoreTable . 
'__', 
'', $sName );
 
  266                 $sCacheFieldName = strtoupper( $sFieldName );
 
  270                 $sId = $this->
getId();
 
  273                     if ( $this->_aInnerLazyCache === null ) {
 
  276                         $sQ = 
'SELECT * FROM ' . $sViewName . 
' WHERE `oxid` = ' . $oDb->quote( $sId );
 
  277                         $rs = $oDb->select( $sQ );
 
  278                         if ( $rs && $rs->RecordCount() ) {
 
  279                             $this->_aInnerLazyCache = array_change_key_case( $rs->fields, CASE_UPPER );
 
  280                             if ( array_key_exists( $sCacheFieldName, $this->_aInnerLazyCache ) ) {
 
  281                                 $sFieldValue = $this->_aInnerLazyCache[$sCacheFieldName];
 
  288                     } elseif ( array_key_exists( $sCacheFieldName, $this->_aInnerLazyCache ) ) {
 
  289                         $sFieldValue = $this->_aInnerLazyCache[$sCacheFieldName];
 
  294                     $this->
_addField( $sFieldName, $iFieldStatus );
 
  298                     if ($this->_sCacheKey) {
 
  301                         $aFieldNames = $myUtils->fromFileCache( $sCacheKey );
 
  302                         $aFieldNames[$sFieldName] = $iFieldStatus;
 
  303                         $myUtils->toFileCache( $sCacheKey, $aFieldNames );
 
  311                 self::$_blDisableFieldCaching[get_class( $this )] = 
true;
 
  318         if (!isset( $this->$sName ) ) {
 
  319             $this->$sName = null;
 
  322         return $this->$sName;
 
  334         return isset($this->$mVar);
 
  344         if (!$this->_blIsSimplyClonable) {
 
  345             foreach ( $this->_aFieldNames as $sField => $sVal ) {
 
  347                 if ( is_object($this->$sLongName)) {
 
  348                     $this->$sLongName = clone $this->$sLongName;
 
  363         $aClasVars = get_object_vars( $oObject );
 
  364         while (list($name, $value) = each( $aClasVars )) {
 
  365             if ( is_object( $oObject->$name ) ) {
 
  366                 $this->$name = clone $oObject->$name;
 
  368                 $this->$name = $oObject->$name;
 
  390         $this->_blUpdateSeo = $blUpdateSeo;
 
  405             $sQuotedOxid = $oDb->quote($this->
getId());
 
  406             $sTitle = $oDb->getOne(
"select `{$sField}` from `{$sTableName}` where `oxid` = {$sQuotedOxid}");
 
  407             $sFieldValue = 
"{$sTableName}__{$sField}";
 
  408             $sCurrentTitle = $this->$sFieldValue->value;
 
  410             if ($sTitle == $sCurrentTitle) {
 
  424     public function init( $sTableName = null, $blForceAllFields = 
false )
 
  427             $this->_sCoreTable = $sTableName;
 
  431         $this->_sViewTable = 
false;
 
  433         if ( count( $this->_aFieldNames ) <= 1 ) {
 
  447         if ( !is_array( $dbRecord ) ) {
 
  453         while ( list( $sName, $sValue ) = each( $dbRecord ) ) {
 
  464         $this->_sOXID = $this->$sOxidField->value;
 
  505     public function setId( $sOXID = null )
 
  508             $this->_sOXID = $sOXID;
 
  513         $sIdVarName = $this->_sCoreTable . 
'__oxid';
 
  528         $this->_iShopId = $iShopId;
 
  550         if (!$this->_sViewTable || ( $blForceCoreTableUsage !== null )) {
 
  551             if ( $blForceCoreTableUsage === 
true ) {
 
  556             if ( ( $blForceCoreTableUsage !== null ) && $blForceCoreTableUsage ) {
 
  562             $sViewName = 
getViewName( $this->_sCoreTable, $this->_blEmployMultilanguage == 
false ? -1 : $this->
getLanguage(), $iShopId );
 
  563             if ( $blForceCoreTableUsage !== null ) {
 
  566             $this->_sViewTable = $sViewName;
 
  582             $this->_sCacheKey = $sCacheKey;
 
  584             $this->_sCacheKey .= $sCacheKey;
 
  595         $this->_blUseLazyLoading = 
false;
 
  620         $this->_blIsDerived = $blVal;
 
  677         $sSelect = 
"select $sGet from " . $this->
getViewName() . 
' where 1 ';
 
  681             while (list($name, $value) = each($aWhere)) {
 
  682                 $sSelect .=  
' and ' . $name . 
' = '.$oDB->quote($value);
 
  704         if ($rs != 
false && $rs->recordCount() > 0) {
 
  706             $this->
assign( $rs->fields);
 
  722             return $this->$sLongFieldName->value;
 
  734         $aSelectFields = array();
 
  736         $sViewName = $this->
getViewName( $blForceCoreTableUsage );
 
  738         foreach ( $this->_aFieldNames as $sKey => $sField ) {
 
  740                 $aSelectFields[] = 
"`$sViewName`.`$sKey`";
 
  742                 $aSelectFields[] = 
".`$sKey`";
 
  747         $sSelectFields = join( 
', ', $aSelectFields );
 
  748         return $sSelectFields;
 
  758     public function delete( $sOXID = null)
 
  761             $sOXID = $this->
getId();
 
  775         $sDelete = 
"delete from $this->_sCoreTable where oxid = " . $oDB->quote( $sOXID );
 
  776         $oDB->execute( $sDelete );
 
  777         if ( $blDelete = ( 
bool ) $oDB->affected_Rows() ) {
 
  778             $this->
onChange( ACTION_DELETE, $sOXID );
 
  792         if ( !is_array( $this->_aFieldNames ) ) {
 
  797         if ( $this->
isAdmin() && !$this->
getConfig()->getConfigParam( 
'blSkipFormatConversion' ) ) {
 
  798             foreach ($this->_aFieldNames as $sName => $sVal) {
 
  800                 if ( isset($this->$sLongName->fldtype) && $this->$sLongName->fldtype == 
'datetime' ) {
 
  801                     oxRegistry::get(
'oxUtilsDate')->convertDBDateTime( $this->$sLongName, 
true );
 
  802                 } elseif ( isset($this->$sLongName->fldtype) && $this->$sLongName->fldtype == 
'timestamp' ) {
 
  803                     oxRegistry::get(
'oxUtilsDate')->convertDBTimestamp( $this->$sLongName, 
true );
 
  804                 } elseif ( isset($this->$sLongName->fldtype) && $this->$sLongName->fldtype == 
'date' ) {
 
  805                     oxRegistry::get(
'oxUtilsDate')->convertDBDate( $this->$sLongName, 
true );
 
  816             $sAction = ACTION_UPDATE;
 
  819             $sAction = ACTION_INSERT;
 
  825             return $this->
getId();
 
  861             $sOXID = $this->
getId();
 
  869         $sSelect= 
"select {$this->_sExistKey} from {$sViewName} where {$this->_sExistKey} = " . $oDb->quote( $sOXID );
 
  871         return ( 
bool ) $oDb->getOne( $sSelect, 
false, 
false );
 
  887         if ( isset( $this->_aFieldNames[
'oxactive'] ) ) {
 
  888             $sQ = 
" $sTable.oxactive = 1 ";
 
  892         if ( isset( $this->_aFieldNames[
'oxactivefrom'] ) && isset( $this->_aFieldNames[
'oxactiveto'] ) ) {
 
  894             $sDate = date( 
'Y-m-d H:i:s', 
oxRegistry::get(
'oxUtilsDate')->getTime() );
 
  896             $sQ = $sQ ? 
" $sQ or " : 
'';
 
  897             $sQ = 
" ( $sQ ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
 
  925     public function onChange( $iAction = null, $sOXID = null )
 
  937         $this->_blIsInList = 
true;
 
  978         $sCacheKey   = $sTable . 
'_allfields_' . $blReturnSimple;
 
  979         $aMetaFields = $myUtils->fromFileCache( $sCacheKey );
 
  981         if ( $aMetaFields ) {
 
  987         if ( !$blReturnSimple ) {
 
  988             $myUtils->toFileCache( $sCacheKey, $aMetaFields );
 
  994         if (is_array($aMetaFields)) {
 
  995             foreach ( $aMetaFields as $oVal ) {
 
  996                 $aRet[strtolower( $oVal->name )] = 0;
 
 1000         $myUtils->toFileCache( $sCacheKey, $aRet);
 
 1018         if (!$this->_sCoreTable) {
 
 1037         $aFieldNames = null;
 
 1040             $aFieldNames = $myUtils->fromFileCache( $sFullCacheKey );
 
 1043         if (!$aFieldNames) {
 
 1046                 $myUtils->toFileCache( $sFullCacheKey, $aFieldNames );
 
 1050         if ( $aFieldNames !== 
false ) {
 
 1051             foreach ( $aFieldNames as $sField => $sStatus ) {
 
 1072         startProfile(
'!__CACHABLE__!');
 
 1077             foreach ( $aMetaFields as $oField ) {
 
 1078                 if ( $oField->max_length == -1 ) {
 
 1079                     $oField->max_length = 10;      
 
 1082                 if ( $oField->type == 
'datetime' ) {
 
 1083                     $oField->max_length = 20;
 
 1086                 $this->
_addField( $oField->name, $this->_getFieldStatus($oField->name), $oField->type, $oField->max_length );
 
 1088             stopProfile(
'!__CACHABLE__!');
 
 1093         if ( $blForceFullStructure || !$this->_blUseLazyLoading ) {
 
 1099             stopProfile(
'!__CACHABLE__!');
 
 1100             return $aMetaFields;
 
 1104         stopProfile(
'!__CACHABLE__!');
 
 1105         return array(
'oxid' => 0);
 
 1131     protected function _addField($sName, $iStatus, $sType = null, $sLength = null )
 
 1134         $sName = strtolower( $sName );
 
 1137         $this->_aFieldNames[$sName] = $iStatus;
 
 1141         if ( isset($this->$sLongName) ) {
 
 1148         if ( isset( $sType ) ) {
 
 1150             $oField->fldtype = $sType;
 
 1153             $this->_blIsSimplyClonable = 
false;
 
 1156         if ( isset( $sLength ) ) {
 
 1160             $oField->fldmax_length = $sLength;
 
 1161             $this->_blIsSimplyClonable = 
false;
 
 1164         $this->$sLongName = $oField;
 
 1177         if ( $sFieldName[2] == $this->_sCoreTable[2] && strpos( $sFieldName, $this->_sCoreTable . 
'__' ) === 0 ) {
 
 1181         return $this->_sCoreTable . 
'__' . strtolower( $sFieldName );
 
 1207         if (!$this->_blUseLazyLoading && !isset( $this->$sLongFieldName )) {
 
 1209             if ( isset( $aFields[strtolower( $sFieldName )] ) ) {
 
 1214         if (isset($this->$sLongFieldName) && isset( $this->$sLongFieldName->fldtype ) && $this->$sLongFieldName->fldtype == 
'double') {
 
 1215             $sValue = str_replace( 
',', 
'.', $sValue );
 
 1219         if ( isset( $this->$sLongFieldName ) && is_object( $this->$sLongFieldName ) ) {
 
 1220             $this->$sLongFieldName->setValue( $sValue, $iDataType );
 
 1222             $this->$sLongFieldName = 
new oxField( $sValue, $iDataType );
 
 1237         foreach ( $aMetaData as $oMetaInfo ) {
 
 1238             if ( strcasecmp( $oMetaInfo->name, $sFieldName ) == 0 ) {
 
 1239                 return !$oMetaInfo->not_null;
 
 1255         foreach ( $aMetaData as $oMetaInfo ) {
 
 1256             if ( strcasecmp( $oMetaInfo->name, $sFieldName ) == 0 ) {
 
 1257                 return $oMetaInfo->default_value;
 
 1274         if ( $oField instanceof 
oxField ) {
 
 1275             $mValue = $oField->getRawValue();
 
 1276         } elseif ( isset( $oField->value ) ) {
 
 1277             $mValue = $oField->value;
 
 1282         if ( ( null === $mValue ) ) {
 
 1286                 return $oDb->quote( $mValue );
 
 1290         return $oDb->quote( $mValue );
 
 1306         foreach ( array_keys( $this->_aFieldNames ) as $sKey ) {
 
 1308             $oField = $this->$sLongName;
 
 1311             if ( !$blUseSkipSaveFields || ( $blUseSkipSaveFields && !in_array( strtolower( $sKey ), $this->_aSkipSaveFields ) ) ) {
 
 1312                 $sSql .= (( $blSep) ? 
',' : 
'' ) . $sKey . 
' = ' . $this->
_getUpdateFieldValue( $sKey, $oField );
 
 1337         if ( !$this->
getId() ) {
 
 1341             $oEx = 
oxNew( 
'oxObjectException' );
 
 1342             $oEx->setMessage( 
'EXCEPTION_OBJECT_OXIDNOTSET' );
 
 1343             $oEx->setObject($this);
 
 1352                  .
" where {$this->_sCoreTable}.oxid = " . $oDb->quote( $this->
getId() );
 
 1357         $blRet = (bool) $oDb->execute( $sUpdate );
 
 1377         if ( !$this->
getId()) {
 
 1381         $sIDKey = $myUtils->getArrFldName( $this->_sCoreTable . 
'.oxid' );
 
 1383         $sInsert = 
"Insert into {$this->_sCoreTable} set ";
 
 1386         $sShopField = $myUtils->getArrFldName( $this->_sCoreTable . 
'.oxshopid' );
 
 1388         if ( isset( $this->$sShopField ) && !$this->$sShopField->value ) {
 
 1395         $blRet = (bool) $oDb->execute( $sInsert );
 
 1408         $sClass = get_class( $this );
 
 1409         if ( isset( self::$_blDisableFieldCaching[$sClass] ) && self::$_blDisableFieldCaching[$sClass] ) {
 
 1423         $sOxId = $this->
getId();
 
 1424         if ( $sOxId[0] == 
'o' && $sOxId[1] == 
'x' ) {
 
 1449         $this->_blReadOnly = $blReadOnly;
 
 1459         return array_keys( $this->_aFieldNames );
 
 1472         $sName = strtolower( $sName );
 
 1473         $this->_aFieldNames[$sName] = 0;