category_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( 'oxprice',  'oxarticles', 0, 0, 0 ),
00008                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00009                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00010                                         ),
00011                      'container2' => array(
00012                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00013                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00014                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00015                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00016                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00017                                         array( 'oxid',     'oxobject2category', 0, 0, 1 )
00018                                         )
00019                     );
00020 
00021 
00025 class ajaxComponent extends ajaxListComponent
00026 {
00032     protected function _getQuery()
00033     {
00034         $myConfig = $this->getConfig();
00035 
00036         $sArticleTable = getViewName('oxarticles');
00037         $sO2CView      = getViewName('oxobject2category');
00038 
00039         $sOxid      = oxConfig::getParameter( 'oxid' );
00040         $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00041 
00042         $sShopID    = $myConfig->getShopId();
00043 
00044         // category selected or not ?
00045         if ( !$sOxid && $sSynchOxid ) {
00046 
00047             // dodger performance
00048             $sQAdd  = ' from '.$sArticleTable.' where 1 ';
00049         } else {
00050 
00051             // copied from oxadminview (not sure if this works)
00052             $sJoin = $myConfig->getConfigParam( 'blVariantsSelection' )? ' ('.$sArticleTable.'.oxparentid='.$sO2CView.'.oxobjectid or '.$sArticleTable.'.oxid='.$sO2CView.'.oxobjectid ) ' : ' '.$sArticleTable.'.oxid='.$sO2CView.'.oxobjectid ';
00053 
00054             $sSubSelect = '';
00055             if ( $sSynchOxid && $sOxid != $sSynchOxid) {
00056 
00057                 $sSubSelect  = ' and '.$sArticleTable.'.oxid not in ( ';
00058                 $sSubSelect .= "select $sArticleTable.oxid from $sO2CView left join $sArticleTable ";
00059                 $sSubSelect .= "on $sJoin where $sO2CView.oxcatnid = '$sSynchOxid' ";
00060                 $sSubSelect .= 'and '.$sArticleTable.'.oxid is not null ) ';
00061             }
00062 
00063             $sQAdd  = " from $sO2CView join $sArticleTable ";
00064             $sQAdd .= " on $sJoin where $sO2CView.oxcatnid = '$sOxid' ";
00065             $sQAdd .= " and $sArticleTable.oxid is not null $sSubSelect ";
00066         }
00067 
00068         // display variants or not ?
00069         $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )? '' : ' and '.$sArticleTable.'.oxparentid = "" ';
00070 
00071         return $sQAdd;
00072     }
00073 
00080     public function addarticle()
00081     {
00082         $myConfig = $this->getConfig();
00083 
00084         $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00085         $sCategoryID = oxConfig::getParameter( 'synchoxid');
00086         $sShopID     = $myConfig->getShopId();
00087 
00088         // adding
00089         if ( oxConfig::getParameter( 'all' ) ) {
00090             $sArticleTable = getViewName( 'oxarticles' );
00091             $aArticles = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00092         }
00093 
00094         if ( is_array($aArticles)) {
00095 
00096             $oDb = oxDb::getDb();
00097 
00098             $sO2CView = getViewName('oxobject2category');
00099 
00100             $oNew = oxNew( 'oxbase' );
00101             $oNew->init( 'oxobject2category' );
00102             $myUtilsObject = oxUtilsObject::getInstance();
00103             $oActShop = $myConfig->getActiveShop();
00104 
00105             foreach ( $aArticles as $sAdd) {
00106 
00107                 // check, if it's already in, then don't add it again
00108                 $sSelect = "select 1 from $sO2CView as oxobject2category where oxobject2category.oxcatnid='$sCategoryID' and oxobject2category.oxobjectid ='$sAdd'";
00109                 if ( $oDb->getOne( $sSelect ) )
00110                     continue;
00111 
00112                 $oNew->oxobject2category__oxid       = new oxField($oNew->setId( $myUtilsObject->generateUID() ));
00113                 $oNew->oxobject2category__oxobjectid = new oxField($sAdd);
00114                 $oNew->oxobject2category__oxcatnid   = new oxField($sCategoryID);
00115                 $oNew->oxobject2category__oxtime     = new oxField(time());
00116                 $oNew->save();
00117             }
00118 
00119             $this->resetCounter( "catArticle", $sCategoryID );
00120         }
00121     }
00122 
00128     public function removearticle()
00129     {
00130         $aArticles = $this->_getActionIds( 'oxobject2category.oxid' );
00131         $sCategoryID = oxConfig::getParameter( 'oxid');
00132         $sShopID     = $this->getConfig()->getShopId();
00133         $oDb = oxDb::getDb();
00134 
00135         // adding
00136         if ( oxConfig::getParameter( 'all' ) ) {
00137 
00138             $sO2CView = getViewName('oxobject2category');
00139             $sQ = $this->_addFilter( "delete $sO2CView.* ".$this->_getQuery() );
00140             $oDb->Execute( $sQ );
00141 
00142         } elseif ( is_array( $aArticles ) && count( $aArticles ) ) {
00143 
00144             $sQ = 'delete from oxobject2category where oxid in ("' . implode( '", "', $aArticles ) . '")';
00145             $oDb->Execute( $sQ );
00146 
00147         }
00148 
00149         $this->resetCounter( "catArticle", $sCategoryID );
00150     }
00151 
00158     protected function _getQueryCols()
00159     {
00160         $myConfig = $this->getConfig();
00161         $sLangTag = oxLang::getInstance()->getLanguageTag();
00162 
00163         $sQ = '';
00164         $blSep = false;
00165         $aVisiblecols = $this->_getVisibleColNames();
00166         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00167             if ( $blSep )
00168                 $sQ .= ', ';
00169             $sViewTable = getViewName( $aCol[1] );
00170             // multilanguage
00171             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00172             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00173                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00174                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00175             } else {
00176                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00177             }
00178             $blSep = true;
00179         }
00180 
00181         $aIdentCols = $this->_getIdentColNames();
00182         foreach ( $aIdentCols as $iCnt => $aCol ) {
00183             if ( $blSep )
00184                 $sQ .= ', ';
00185 
00186             // multilanguage
00187             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00188             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00189         }
00190 
00191         return " $sQ ";
00192     }
00193 
00194 }

Generated on Wed Apr 22 12:26:29 2009 for OXID eShop CE by  doxygen 1.5.5