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 
00026     public function __construct()
00027     {
00028         parent::__construct();
00029         $this->init( $this->_sCoreTbl);
00030     }
00031 
00039     public function delete( $sOXID = null )
00040     {
00041         if( !$sOXID)
00042             $sOXID = $this->getId();
00043         if( !$sOXID)
00044             return false;
00045 
00046 
00047         // remove attributes from articles also
00048         $oDB = oxDb::getDb();
00049         $sOxidQuoted = $oDB->quote($sOXID);
00050         $sDelete = "delete from oxobject2attribute where oxattrid = ".$sOxidQuoted;
00051         $rs = $oDB->execute( $sDelete);
00052 
00053         // #657 ADDITIONAL removes attribute connection to category
00054         $sDelete = "delete from oxcategory2attribute where oxattrid = ".$sOxidQuoted;
00055         $rs = $oDB->execute( $sDelete);
00056 
00057         return parent::delete( $sOXID);
00058     }
00059 
00068     public function assignVarToAttribute( $aMDVariants, $aSelTitle )
00069     {
00070         $myLang    = oxLang::getInstance();
00071         $aConfLanguages = $myLang->getLanguageIds();
00072         $sAttrId = $this->_getAttrId( $aSelTitle[0] );
00073         if ( !$sAttrId ) {
00074             $sAttrId = $this->_createAttribute( $aSelTitle );
00075         }
00076         foreach ( $aMDVariants as $sVarId => $oValue ) {
00077             if ( strpos( $sVarId, "mdvar_" ) === 0 ) {
00078                 foreach ( $oValue as $sId ) {
00079                     //var_dump($sVarId, $oAttribute->oxattribute__oxid->value);
00080                     $sVarId = substr($sVarId, 6);
00081                     $oNewAssign = oxNew( "oxbase" );
00082                     $oNewAssign->init( "oxobject2attribute" );
00083                     $sNewId = oxUtilsObject::getInstance()->generateUID();
00084                     if ($oNewAssign->load($sId)) {
00085                         $oNewAssign->oxobject2attribute__oxobjectid = new oxField($sVarId);
00086                         $oNewAssign->setId($sNewId);
00087                         $oNewAssign->save();
00088                     }
00089                 }
00090             } else {
00091                 $oNewAssign = oxNew( "oxbase" );
00092                 $oNewAssign->init( "oxobject2attribute" );
00093                 $oNewAssign->oxobject2attribute__oxobjectid = new oxField($sVarId);
00094                 $oNewAssign->oxobject2attribute__oxattrid   = new oxField($sAttrId);
00095                 foreach ($aConfLanguages as $sKey => $sLang) {
00096                     $sPrefix = $myLang->getLanguageTag($sKey);
00097                     $oNewAssign->{'oxobject2attribute__oxvalue'.$sPrefix} = new oxField($oValue[$sKey]->name);
00098                 }
00099                 $oNewAssign->save();
00100             }
00101         }
00102     }
00103 
00111     protected function _getAttrId( $sSelTitle )
00112     {
00113         $oDb = oxDb::getDB();
00114         $sAttViewName = getViewName('oxattribute');
00115         return $oDb->getOne("select oxid from $sAttViewName where LOWER(oxtitle) = " . $oDb->quote(getStr()->strtolower($sSelTitle)));
00116     }
00117 
00125     protected function _createAttribute( $aSelTitle )
00126     {
00127         $myLang    = oxLang::getInstance();
00128         $aConfLanguages = $myLang->getLanguageIds();
00129         $oAttr = oxNew('oxbase');
00130         $oAttr->init('oxattribute');
00131         foreach ($aConfLanguages as $sKey => $sLang) {
00132            $sPrefix = $myLang->getLanguageTag($sKey);
00133            $oAttr->{'oxattribute__oxtitle'.$sPrefix} = new oxField($aSelTitle[$sKey]);
00134         }
00135         $oAttr->save();
00136         return $oAttr->getId();
00137     }
00138 
00146     public function getAttributeAssigns( $sArtId)
00147     {
00148         if ( !$sArtId) {
00149             return;
00150         }
00151         $sSelect  = "select o2a.oxid ";
00152         $sSelect .= "from oxobject2attribute as o2a ";
00153         $sSelect .= "where o2a.oxobjectid = '$sArtId' ";
00154         $sSelect .= "order by o2a.oxpos";
00155 
00156         $aIds = array();
00157         $rs = oxDb::getDb()->Execute( $sSelect);
00158         if ($rs != false && $rs->recordCount() > 0) {
00159             while (!$rs->EOF) {
00160                 $aIds[] = $rs->fields[0];
00161                 $rs->moveNext();
00162             }
00163         }
00164         return $aIds;
00165     }
00166 }

Generated by  doxygen 1.6.2