Go to the documentation of this file.00001 <?php
00002
00007 class oxAttribute extends oxI18n
00008 {
00014 protected $_sClassName = 'oxattribute';
00015
00021 protected $_sActiveValue = null;
00022
00028 protected $_sTitle = null;
00029
00035 protected $_aValues = null;
00036
00040 public function __construct()
00041 {
00042 parent::__construct();
00043 $this->init('oxattribute');
00044 }
00045
00053 public function delete( $sOXID = null )
00054 {
00055 if( !$sOXID)
00056 $sOXID = $this->getId();
00057 if( !$sOXID)
00058 return false;
00059
00060
00061
00062 $oDb = oxDb::getDb();
00063 $sOxidQuoted = $oDb->quote($sOXID);
00064 $sDelete = "delete from oxobject2attribute where oxattrid = ".$sOxidQuoted;
00065 $rs = $oDb->execute( $sDelete);
00066
00067
00068 $sDelete = "delete from oxcategory2attribute where oxattrid = ".$sOxidQuoted;
00069 $rs = $oDb->execute( $sDelete);
00070
00071 return parent::delete( $sOXID);
00072 }
00073
00082 public function assignVarToAttribute( $aMDVariants, $aSelTitle )
00083 {
00084 $myLang = oxLang::getInstance();
00085 $aConfLanguages = $myLang->getLanguageIds();
00086 $sAttrId = $this->_getAttrId( $aSelTitle[0] );
00087 if ( !$sAttrId ) {
00088 $sAttrId = $this->_createAttribute( $aSelTitle );
00089 }
00090 foreach ( $aMDVariants as $sVarId => $oValue ) {
00091 if ( strpos( $sVarId, "mdvar_" ) === 0 ) {
00092 foreach ( $oValue as $sId ) {
00093
00094 $sVarId = substr($sVarId, 6);
00095 $oNewAssign = oxNew( "oxbase" );
00096 $oNewAssign->init( "oxobject2attribute" );
00097 $sNewId = oxUtilsObject::getInstance()->generateUID();
00098 if ($oNewAssign->load($sId)) {
00099 $oNewAssign->oxobject2attribute__oxobjectid = new oxField($sVarId);
00100 $oNewAssign->setId($sNewId);
00101 $oNewAssign->save();
00102 }
00103 }
00104 } else {
00105 $oNewAssign = oxNew( "oxi18n" );
00106 $oNewAssign->setEnableMultilang( false );
00107 $oNewAssign->init( "oxobject2attribute" );
00108 $oNewAssign->oxobject2attribute__oxobjectid = new oxField($sVarId);
00109 $oNewAssign->oxobject2attribute__oxattrid = new oxField($sAttrId);
00110 foreach ($aConfLanguages as $sKey => $sLang) {
00111 $sPrefix = $myLang->getLanguageTag($sKey);
00112 $oNewAssign->{'oxobject2attribute__oxvalue'.$sPrefix} = new oxField($oValue[$sKey]->name);
00113 }
00114 $oNewAssign->save();
00115 }
00116 }
00117 }
00118
00126 protected function _getAttrId( $sSelTitle )
00127 {
00128 $oDb = oxDb::getDB();
00129 $sAttViewName = getViewName('oxattribute');
00130 return $oDb->getOne("select oxid from $sAttViewName where LOWER(oxtitle) = " . $oDb->quote(getStr()->strtolower($sSelTitle)));
00131 }
00132
00140 protected function _createAttribute( $aSelTitle )
00141 {
00142 $myLang = oxLang::getInstance();
00143 $aConfLanguages = $myLang->getLanguageIds();
00144 $oAttr = oxNew('oxI18n');
00145 $oAttr->setEnableMultilang( false );
00146 $oAttr->init('oxattribute');
00147 foreach ($aConfLanguages as $sKey => $sLang) {
00148 $sPrefix = $myLang->getLanguageTag($sKey);
00149 $oAttr->{'oxattribute__oxtitle'.$sPrefix} = new oxField($aSelTitle[$sKey]);
00150 }
00151 $oAttr->save();
00152 return $oAttr->getId();
00153 }
00154
00162 public function getAttributeAssigns( $sArtId )
00163 {
00164 if ( $sArtId ) {
00165 $oDb = oxDb::getDb();
00166
00167 $sSelect = "select o2a.oxid from oxobject2attribute as o2a ";
00168 $sSelect .= "where o2a.oxobjectid = ".$oDb->quote( $sArtId )." order by o2a.oxpos";
00169
00170 $aIds = array();
00171 $rs = $oDb->select( $sSelect );
00172 if ($rs != false && $rs->recordCount() > 0) {
00173 while (!$rs->EOF) {
00174 $aIds[] = $rs->fields[0];
00175 $rs->moveNext();
00176 }
00177 }
00178 return $aIds;
00179 }
00180 }
00181
00182
00183
00191 public function setTitle( $sTitle )
00192 {
00193 $this->_sTitle = getStr()->htmlspecialchars( $sTitle );
00194 }
00195
00201 public function getTitle()
00202 {
00203 return $this->_sTitle;
00204 }
00205
00213 public function addValue( $sValue )
00214 {
00215 $this->_aValues[] = getStr()->htmlspecialchars( $sValue );
00216 }
00217
00225 public function setActiveValue( $sValue )
00226 {
00227 $this->_sActiveValue = getStr()->htmlspecialchars( $sValue );
00228 }
00229
00235 public function getActiveValue()
00236 {
00237
00238 return $this->_sActiveValue;
00239 }
00240
00246 public function getValues()
00247 {
00248 return $this->_aValues;
00249 }
00250
00251 }