oxattribute.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxAttribute extends oxI18n
00008 {
00014     protected $_sClassName = 'oxattribute';
00015 
00021     protected $_sCoreTbl = 'oxattribute';
00022 
00023 
00029     protected $_sActiveValue = null;
00030 
00036     protected $_sTitle = null;
00037 
00043     protected $_aValues = null;
00044 
00048     public function __construct()
00049     {
00050         parent::__construct();
00051         $this->init( $this->_sCoreTbl);
00052     }
00053 
00061     public function delete( $sOXID = null )
00062     {
00063         if( !$sOXID)
00064             $sOXID = $this->getId();
00065         if( !$sOXID)
00066             return false;
00067 
00068 
00069         // remove attributes from articles also
00070         $oDB = oxDb::getDb();
00071         $sOxidQuoted = $oDB->quote($sOXID);
00072         $sDelete = "delete from oxobject2attribute where oxattrid = ".$sOxidQuoted;
00073         $rs = $oDB->execute( $sDelete);
00074 
00075         // #657 ADDITIONAL removes attribute connection to category
00076         $sDelete = "delete from oxcategory2attribute where oxattrid = ".$sOxidQuoted;
00077         $rs = $oDB->execute( $sDelete);
00078 
00079         return parent::delete( $sOXID);
00080     }
00081 
00090     public function assignVarToAttribute( $aMDVariants, $aSelTitle )
00091     {
00092         $myLang    = oxLang::getInstance();
00093         $aConfLanguages = $myLang->getLanguageIds();
00094         $sAttrId = $this->_getAttrId( $aSelTitle[0] );
00095         if ( !$sAttrId ) {
00096             $sAttrId = $this->_createAttribute( $aSelTitle );
00097         }
00098         foreach ( $aMDVariants as $sVarId => $oValue ) {
00099             if ( strpos( $sVarId, "mdvar_" ) === 0 ) {
00100                 foreach ( $oValue as $sId ) {
00101                     //var_dump($sVarId, $oAttribute->oxattribute__oxid->value);
00102                     $sVarId = substr($sVarId, 6);
00103                     $oNewAssign = oxNew( "oxbase" );
00104                     $oNewAssign->init( "oxobject2attribute" );
00105                     $sNewId = oxUtilsObject::getInstance()->generateUID();
00106                     if ($oNewAssign->load($sId)) {
00107                         $oNewAssign->oxobject2attribute__oxobjectid = new oxField($sVarId);
00108                         $oNewAssign->setId($sNewId);
00109                         $oNewAssign->save();
00110                     }
00111                 }
00112             } else {
00113                 $oNewAssign = oxNew( "oxi18n" );
00114                 $oNewAssign->setEnableMultilang( false );
00115                 $oNewAssign->init( "oxobject2attribute" );
00116                 $oNewAssign->oxobject2attribute__oxobjectid = new oxField($sVarId);
00117                 $oNewAssign->oxobject2attribute__oxattrid   = new oxField($sAttrId);
00118                 foreach ($aConfLanguages as $sKey => $sLang) {
00119                     $sPrefix = $myLang->getLanguageTag($sKey);
00120                     $oNewAssign->{'oxobject2attribute__oxvalue'.$sPrefix} = new oxField($oValue[$sKey]->name);
00121                 }
00122                 $oNewAssign->save();
00123             }
00124         }
00125     }
00126 
00134     protected function _getAttrId( $sSelTitle )
00135     {
00136         $oDb = oxDb::getDB();
00137         $sAttViewName = getViewName('oxattribute');
00138         return $oDb->getOne("select oxid from $sAttViewName where LOWER(oxtitle) = " . $oDb->quote(getStr()->strtolower($sSelTitle)));
00139     }
00140 
00148     protected function _createAttribute( $aSelTitle )
00149     {
00150         $myLang = oxLang::getInstance();
00151         $aConfLanguages = $myLang->getLanguageIds();
00152         $oAttr = oxNew('oxI18n');
00153         $oAttr->setEnableMultilang( false );
00154         $oAttr->init('oxattribute');
00155         foreach ($aConfLanguages as $sKey => $sLang) {
00156            $sPrefix = $myLang->getLanguageTag($sKey);
00157            $oAttr->{'oxattribute__oxtitle'.$sPrefix} = new oxField($aSelTitle[$sKey]);
00158         }
00159         $oAttr->save();
00160         return $oAttr->getId();
00161     }
00162 
00170     public function getAttributeAssigns( $sArtId )
00171     {
00172         if ( $sArtId ) {
00173             $oDb = oxDb::getDb();
00174 
00175             $sSelect  = "select o2a.oxid from oxobject2attribute as o2a ";
00176             $sSelect .= "where o2a.oxobjectid = ".$oDb->quote( $sArtId )." order by o2a.oxpos";
00177 
00178             $aIds = array();
00179             $rs = $oDb->execute( $sSelect );
00180             if ($rs != false && $rs->recordCount() > 0) {
00181                 while (!$rs->EOF) {
00182                     $aIds[] = $rs->fields[0];
00183                     $rs->moveNext();
00184                 }
00185             }
00186             return $aIds;
00187         }
00188     }
00189 
00190 
00191 
00199     public function setTitle( $sTitle )
00200     {
00201         $this->_sTitle = getStr()->htmlspecialchars( $sTitle );
00202     }
00203 
00209     public function getTitle()
00210     {
00211         return $this->_sTitle;
00212     }
00213 
00221     public function addValue( $sValue )
00222     {
00223         $this->_aValues[] = getStr()->htmlspecialchars( $sValue );
00224     }
00225 
00233     public function setActiveValue( $sValue )
00234     {
00235         $this->_sActiveValue = getStr()->htmlspecialchars( $sValue );
00236     }
00237 
00243     public function getActiveValue()
00244     {
00245 
00246         return $this->_sActiveValue;
00247     }
00248 
00254     public function getValues()
00255     {
00256         return $this->_aValues;
00257     }
00258 
00259 }