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);
190 $this->_blUseSkipSaveFields = $blUseSkipSaveFields;
205 if ($this->_blUseLazyLoading) {
206 $this->_sCacheKey .=
$myConfig->getActiveView()->getClassName();
208 $this->_sCacheKey .=
'allviews';
213 $this->_sCacheKey = null;
225 public function __set($sName, $sValue)
227 $this->$sName = $sValue;
228 if ($this->_blUseLazyLoading && strpos($sName, $this->_sCoreTable .
'__') === 0) {
229 $sFieldName = str_replace($this->_sCoreTable .
"__",
'', $sName);
230 if ($sFieldName !=
'oxnid' && (!isset($this->_aFieldNames[$sFieldName]) || !$this->_aFieldNames[$sFieldName])) {
232 if (isset($aAllFields[strtolower($sFieldName)])) {
234 $this->
_addField($sFieldName, $iFieldStatus);
254 return $this->
getId();
264 if ($this->_blUseLazyLoading && stripos($sName, $this->_sCoreTable .
"__") === 0) {
266 if ($this->
getId()) {
269 $sFieldName = str_replace($this->_sCoreTable .
'__',
'', $sName);
270 $sCacheFieldName = strtoupper($sFieldName);
274 $sId = $this->
getId();
277 if ($this->_aInnerLazyCache === null) {
280 $sQ =
'SELECT * FROM ' . $sViewName .
' WHERE `oxid` = ' . $oDb->quote($sId);
281 $rs = $oDb->select($sQ);
282 if ($rs && $rs->RecordCount()) {
283 $this->_aInnerLazyCache = array_change_key_case($rs->fields, CASE_UPPER);
284 if (array_key_exists($sCacheFieldName, $this->_aInnerLazyCache)) {
285 $sFieldValue = $this->_aInnerLazyCache[$sCacheFieldName];
292 } elseif (array_key_exists($sCacheFieldName, $this->_aInnerLazyCache)) {
293 $sFieldValue = $this->_aInnerLazyCache[$sCacheFieldName];
298 $this->
_addField($sFieldName, $iFieldStatus);
302 if ($this->_sCacheKey) {
305 $aFieldNames = $myUtils->fromFileCache($sCacheKey);
306 $aFieldNames[$sFieldName] = $iFieldStatus;
307 $myUtils->toFileCache($sCacheKey, $aFieldNames);
315 self::$_blDisableFieldCaching[get_class($this)] =
true;
322 if (!isset($this->$sName)) {
323 $this->$sName = null;
326 return $this->$sName;
338 return isset($this->$mVar);
346 if (!$this->_blIsSimplyClonable) {
347 foreach ($this->_aFieldNames as $sField => $sVal) {
349 if (is_object($this->$sLongName)) {
350 $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) {
422 public function init($sTableName = null, $blForceAllFields =
false)
425 $this->_sCoreTable = $sTableName;
429 $this->_sViewTable =
false;
431 if (count($this->_aFieldNames) <= 1) {
445 if (!is_array($dbRecord)) {
451 while (list($sName, $sValue) = each($dbRecord)) {
462 $this->_sOXID = $this->$sOxidField->value;
503 public function setId($sOXID = null)
506 $this->_sOXID = $sOXID;
509 $sObjectId = $this->oxobject2category__oxobjectid;
510 $sCatId = $this->oxobject2category__oxcatnid;
511 $sShopID = $this->oxobject2category__oxshopid;
512 $this->_sOXID = md5($sObjectId . $sCatId . $sShopID);
531 $this->_iShopId = $iShopId;
553 if (!$this->_sViewTable || ($blForceCoreTableUsage !== null)) {
554 if ($blForceCoreTableUsage ===
true) {
559 if (($blForceCoreTableUsage !== null) && $blForceCoreTableUsage) {
566 if ($blForceCoreTableUsage !== null) {
569 $this->_sViewTable = $sViewName;
584 $this->_sCacheKey = $sCacheKey;
586 $this->_sCacheKey .= $sCacheKey;
595 $this->_blUseLazyLoading =
false;
618 $this->_blIsDerived = $blVal;
676 $sSelect =
"select $sGet from " . $this->
getViewName() .
' where 1 ';
680 while (list($name, $value) = each($aWhere)) {
681 $sSelect .=
' and ' . $name .
' = ' . $oDB->quote($value);
703 if ($rs !=
false && $rs->recordCount() > 0) {
705 $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);
749 return $sSelectFields;
759 public function delete($sOxId = null)
762 $sOxId = $this->
getId();
779 $sDelete =
"delete from {$sCoreTable} where oxid = " . $oDB->quote($sOxId);
780 $oDB->execute($sDelete);
781 if ($blDelete = (
bool) $oDB->affected_Rows()) {
782 $this->
onChange(ACTION_DELETE, $sOxId);
805 if (!is_array($this->_aFieldNames)) {
810 if ($this->
isAdmin() && !$this->
getConfig()->getConfigParam(
'blSkipFormatConversion')) {
811 foreach ($this->_aFieldNames as $sName => $sVal) {
813 if (isset($this->$sLongName->fldtype) && $this->$sLongName->fldtype ==
'datetime') {
814 oxRegistry::get(
'oxUtilsDate')->convertDBDateTime($this->$sLongName,
true);
815 } elseif (isset($this->$sLongName->fldtype) && $this->$sLongName->fldtype ==
'timestamp') {
816 oxRegistry::get(
'oxUtilsDate')->convertDBTimestamp($this->$sLongName,
true);
817 } elseif (isset($this->$sLongName->fldtype) && $this->$sLongName->fldtype ==
'date') {
818 oxRegistry::get(
'oxUtilsDate')->convertDBDate($this->$sLongName,
true);
830 $sAction = ACTION_UPDATE;
833 $sAction = ACTION_INSERT;
839 return $this->
getId();
875 $sOXID = $this->
getId();
883 $sSelect =
"select {$this->_sExistKey} from {$sViewName} where {$this->_sExistKey} = " . $oDb->quote($sOXID);
885 return (
bool ) $oDb->getOne($sSelect,
false,
false);
901 if (isset($this->_aFieldNames[
'oxactive'])) {
902 $sQ =
" $sTable.oxactive = 1 ";
906 if (isset($this->_aFieldNames[
'oxactivefrom']) && isset($this->_aFieldNames[
'oxactiveto'])) {
908 $sDate = date(
'Y-m-d H:i:s',
oxRegistry::get(
'oxUtilsDate')->getTime());
910 $sQ = $sQ ?
" $sQ or " :
'';
911 $sQ =
" ( $sQ ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
935 public function onChange($iAction = null, $sOXID = null)
945 $this->_blIsInList =
true;
987 $sCacheKey = $sTable .
'_allfields_' . $blReturnSimple;
988 $aMetaFields = $myUtils->fromFileCache($sCacheKey);
996 if (!$blReturnSimple) {
997 $myUtils->toFileCache($sCacheKey, $aMetaFields);
1004 if (is_array($aMetaFields)) {
1005 foreach ($aMetaFields as $oVal) {
1006 $aRet[strtolower($oVal->name)] = 0;
1010 $myUtils->toFileCache($sCacheKey, $aRet);
1046 $aFieldNames = null;
1049 $aFieldNames = $myUtils->fromFileCache($sFullCacheKey);
1052 if (!$aFieldNames) {
1055 $myUtils->toFileCache($sFullCacheKey, $aFieldNames);
1059 if ($aFieldNames !==
false) {
1060 foreach ($aFieldNames as $sField => $sStatus) {
1081 startProfile(
'!__CACHABLE__!');
1086 foreach ($aMetaFields as $oField) {
1087 if ($oField->max_length == -1) {
1088 $oField->max_length = 10;
1091 if ($oField->type ==
'datetime') {
1092 $oField->max_length = 20;
1095 $this->
_addField($oField->name, $this->_getFieldStatus($oField->name), $oField->type, $oField->max_length);
1097 stopProfile(
'!__CACHABLE__!');
1103 if ($blForceFullStructure || !$this->_blUseLazyLoading) {
1109 stopProfile(
'!__CACHABLE__!');
1111 return $aMetaFields;
1115 stopProfile(
'!__CACHABLE__!');
1117 return array(
'oxid' => 0);
1143 protected function _addField($sName, $iStatus, $sType = null, $sLength = null)
1146 $sName = strtolower($sName);
1149 $this->_aFieldNames[$sName] = $iStatus;
1153 if (isset($this->$sLongName)) {
1160 if (isset($sType)) {
1162 $oField->fldtype = $sType;
1165 $this->_blIsSimplyClonable =
false;
1168 if (isset($sLength)) {
1172 $oField->fldmax_length = $sLength;
1173 $this->_blIsSimplyClonable =
false;
1176 $this->$sLongName = $oField;
1190 if ($sFieldName[2] == $sCoreTableName[2] && strpos($sFieldName, $sCoreTableName .
'__') === 0) {
1194 return $sCoreTableName .
'__' . strtolower($sFieldName);
1220 if (!$this->_blUseLazyLoading && !isset($this->$sLongFieldName)) {
1222 if (isset($aFields[strtolower($sFieldName)])) {
1227 if (isset($this->$sLongFieldName) && isset($this->$sLongFieldName->fldtype) && $this->$sLongFieldName->fldtype ==
'double') {
1228 $sValue = str_replace(
',',
'.', $sValue);
1232 if (isset($this->$sLongFieldName) && is_object($this->$sLongFieldName)) {
1233 $this->$sLongFieldName->setValue($sValue, $iDataType);
1235 $this->$sLongFieldName =
new oxField($sValue, $iDataType);
1250 foreach ($aMetaData as $oMetaInfo) {
1251 if (strcasecmp($oMetaInfo->name, $sFieldName) == 0) {
1252 return !$oMetaInfo->not_null;
1269 foreach ($aMetaData as $oMetaInfo) {
1270 if (strcasecmp($oMetaInfo->name, $sFieldName) == 0) {
1271 return $oMetaInfo->default_value;
1289 if ($oField instanceof
oxField) {
1290 $mValue = $oField->getRawValue();
1291 } elseif (isset($oField->value)) {
1292 $mValue = $oField->value;
1297 if ((null === $mValue)) {
1301 return $oDb->quote($mValue);
1305 return $oDb->quote($mValue);
1321 foreach (array_keys($this->_aFieldNames) as $sKey) {
1323 $oField = $this->$sLongName;
1326 if (!$blUseSkipSaveFields || ($blUseSkipSaveFields && !in_array(strtolower($sKey), $this->_aSkipSaveFields))) {
1352 if (!$this->
getId()) {
1356 $oEx =
oxNew(
'oxObjectException');
1357 $oEx->setMessage(
'EXCEPTION_OBJECT_OXIDNOTSET');
1358 $oEx->setObject($this);
1368 .
" where {$sCoreTableName}.oxid = " . $oDb->quote($this->
getId());
1373 $blRet = (bool) $oDb->execute($sUpdate);
1393 if (!$this->
getId()) {
1399 $sInsert =
"Insert into {$this->getCoreTableName()} set ";
1402 $sShopField = $myUtils->getArrFldName($this->
getCoreTableName() .
'.oxshopid');
1404 if (isset($this->$sShopField) && !$this->$sShopField->value) {
1410 $blRet = (bool) $oDb->execute($sInsert);
1425 $sClass = get_class($this);
1426 if (isset(self::$_blDisableFieldCaching[$sClass]) && self::$_blDisableFieldCaching[$sClass]) {
1454 $sOxId = $this->
getId();
1455 if ($sOxId[0] ==
'o' && $sOxId[1] ==
'x') {
1479 $this->_blReadOnly = $blReadOnly;
1489 return array_keys($this->_aFieldNames);
1500 $sName = strtolower($sName);
1501 $this->_aFieldNames[$sName] = 0;