oxattribute.php

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