attribute_main.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00004                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00005                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00006                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00007                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00008                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00009                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00010                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00011                                         ),
00012                      'container2' => array(
00013                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00014                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00015                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00016                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00017                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00018                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00019                                         array( 'oxid',     'oxobject2attribute', 0, 0, 1 )
00020                                         )
00021                     );
00022 
00023 
00027 class ajaxComponent extends ajaxListComponent
00028 {
00034     protected function _getQuery()
00035     {
00036         $myConfig = $this->getConfig();
00037         $oDb      = oxDb::getDb();
00038 
00039         $sArticleTable = getViewName('oxarticles');
00040         $sO2CView      = getViewName('oxobject2category');
00041 
00042         $sDelId      = oxConfig::getParameter( 'oxid' );
00043         $sSynchDelId = oxConfig::getParameter( 'synchoxid' );
00044 
00045         // category selected or not ?
00046         if ( !$sDelId) {
00047             // dodger performance
00048             $sQAdd  = " from $sArticleTable where 1 ";
00049             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00050         } else {
00051             // selected category ?
00052             if ( $sSynchDelId && $sDelId != $sSynchDelId ) {
00053                 $sQAdd  = " from $sO2CView as oxobject2category left join $sArticleTable on ";
00054                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArticleTable.oxid=oxobject2category.oxobjectid or $sArticleTable.oxparentid=oxobject2category.oxobjectid)":" $sArticleTable.oxid=oxobject2category.oxobjectid ";
00055                 $sQAdd .= " where oxobject2category.oxcatnid = " . $oDb->quote( $sDelId ) . " ";
00056             } else {
00057                 $sQAdd  = " from oxobject2attribute left join $sArticleTable on $sArticleTable.oxid=oxobject2attribute.oxobjectid ";
00058                 $sQAdd .= " where oxobject2attribute.oxattrid = " . $oDb->quote( $sDelId ) . " and $sArticleTable.oxid is not null ";
00059             }
00060         }
00061 
00062         if ( $sSynchDelId && $sSynchDelId != $sDelId ) {
00063             $sQAdd .= " and $sArticleTable.oxid not in ( select oxobject2attribute.oxobjectid from oxobject2attribute where oxobject2attribute.oxattrid = " . $oDb->quote( $sSynchDelId ) . " ) ";
00064         }
00065 
00066         return $sQAdd;
00067     }
00068 
00076     protected function _addFilter( $sQ )
00077     {
00078         $sQ = parent::_addFilter( $sQ );
00079 
00080         // display variants or not ?
00081         if ( $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00082             $sQ .= ' group by '.getViewName( 'oxarticles' ).'.oxid ';
00083 
00084             $oStr = getStr();
00085             if ( $oStr->strpos( $sQ, "select count( * ) " ) === 0 ) {
00086                 $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
00087             }
00088         }
00089         return $sQ;
00090     }
00091 
00097     public function removeattrarticle()
00098     {
00099         $aChosenCat = $this->_getActionIds( 'oxobject2attribute.oxid' );
00100         if ( oxConfig::getParameter( 'all' ) ) {
00101 
00102             $sQ = $this->_addFilter( "delete oxobject2attribute.* ".$this->_getQuery() );
00103             oxDb::getDb()->Execute( $sQ );
00104 
00105         } elseif ( is_array( $aChosenCat ) ) {
00106             $sQ = "delete from oxobject2attribute where oxobject2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00107             oxDb::getDb()->Execute( $sQ );
00108         }
00109     }
00110 
00116     public function addattrarticle()
00117     {
00118         $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00119         $soxId       = oxConfig::getParameter( 'synchoxid' );
00120 
00121         // adding
00122         if ( oxConfig::getParameter( 'all' ) ) {
00123             $sArticleTable = getViewName( 'oxarticles' );
00124             $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00125         }
00126 
00127         $oCategory = oxNew( "oxattribute" );
00128 
00129 
00130         if ( $oCategory->load( $soxId) && is_array( $aAddArticle ) ) {
00131             foreach ($aAddArticle as $sAdd) {
00132                 $oNewGroup = oxNew( "oxbase" );
00133                 $oNewGroup->init( "oxobject2attribute" );
00134                 $oNewGroup->oxobject2attribute__oxobjectid = new oxField($sAdd);
00135                 $oNewGroup->oxobject2attribute__oxattrid   = new oxField($oCategory->oxattribute__oxid->value);
00136                 $oNewGroup->save();
00137             }
00138         }
00139     }
00140 
00147     protected function _getQueryCols()
00148     {
00149         $myConfig = $this->getConfig();
00150         $sLangTag = oxLang::getInstance()->getLanguageTag();
00151 
00152         $sQ = '';
00153         $blSep = false;
00154         $aVisiblecols = $this->_getVisibleColNames();
00155         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00156             if ( $blSep )
00157                 $sQ .= ', ';
00158             $sViewTable = getViewName( $aCol[1] );
00159             // multilanguage
00160             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00161             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00162                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00163                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00164             } else {
00165                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00166             }
00167             $blSep = true;
00168         }
00169 
00170         $aIdentCols = $this->_getIdentColNames();
00171         foreach ( $aIdentCols as $iCnt => $aCol ) {
00172             if ( $blSep )
00173                 $sQ .= ', ';
00174 
00175             // multilanguage
00176             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00177             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00178         }
00179 
00180         return " $sQ ";
00181     }
00182 
00183 }