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( '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',     'oxarticles', 0, 0, 1 )
00020                                         )
00021                     );
00022 
00023 
00027 class ajaxComponent extends ajaxListComponent
00028 {
00034     protected function _getQuery()
00035     {
00036         $myConfig = $this->getConfig();
00037 
00038         $sArticleTable = getViewName('oxarticles');
00039         $sO2CView      = getViewName('oxobject2category');
00040 
00041         $sOxid      = oxConfig::getParameter( 'oxid' );
00042         $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00043         $oDb        = oxDb::getDb();
00044 
00045         $sShopID    = $myConfig->getShopId();
00046 
00047         // category selected or not ?
00048         if ( !$sOxid && $sSynchOxid ) {
00049 
00050             // dodger performance
00051             $sQAdd  = ' from '.$sArticleTable.' where 1 ';
00052         } else {
00053 
00054             // copied from oxadminview (not sure if this works)
00055             $sJoin = " {$sArticleTable}.oxid={$sO2CView}.oxobjectid ";
00056 
00057             $sSubSelect = '';
00058             if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
00059 
00060                 $sSubSelect  = ' and '.$sArticleTable.'.oxid not in ( ';
00061                 $sSubSelect .= "select $sArticleTable.oxid from $sO2CView left join $sArticleTable ";
00062                 $sSubSelect .= "on $sJoin where $sO2CView.oxcatnid =  " . $oDb->quote( $sSynchOxid ) . " ";
00063                 $sSubSelect .= 'and '.$sArticleTable.'.oxid is not null ) ';
00064             }
00065 
00066             $sQAdd  = " from $sO2CView join $sArticleTable ";
00067             $sQAdd .= " on $sJoin where $sO2CView.oxcatnid = '" . $sOxid . "' ";
00068             $sQAdd .= " and $sArticleTable.oxid is not null $sSubSelect ";
00069         }
00070 
00071         return $sQAdd;
00072     }
00073 
00081     protected function _addFilter( $sQ )
00082     {
00083         $sArtTable = getViewName('oxarticles');
00084         $sQ = parent::_addFilter( $sQ );
00085 
00086         // display variants or not ?
00087         if ( !$this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00088             $sQ .=  " and {$sArtTable}.oxparentid = '' ";
00089         }
00090 
00091         return $sQ;
00092     }
00093 
00100     public function addarticle()
00101     {
00102         $myConfig = $this->getConfig();
00103 
00104         $aArticles  = $this->_getActionIds( 'oxarticles.oxid' );
00105         $sCategoryID = oxConfig::getParameter( 'synchoxid');
00106         $sShopID     = $myConfig->getShopId();
00107         $oDb         = oxDb::getDb();
00108         $sArticleTable = getViewName( 'oxarticles' );
00109 
00110         // adding
00111         if ( oxConfig::getParameter( 'all' ) ) {
00112             $aArticles = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00113         }
00114 
00115         if ( is_array($aArticles)) {
00116 
00117 
00118             $sO2CView = getViewName('oxobject2category');
00119 
00120             $oNew = oxNew( 'oxbase' );
00121             $oNew->init( 'oxobject2category' );
00122             $myUtilsObject = oxUtilsObject::getInstance();
00123             $oActShop = $myConfig->getActiveShop();
00124 
00125             foreach ( $aArticles as $sAdd) {
00126 
00127                 // check, if it's already in, then don't add it again
00128                 $sSelect = "select 1 from $sO2CView as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sCategoryID ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $sAdd ) . "";
00129                 if ( $oDb->getOne( $sSelect ) )
00130                     continue;
00131 
00132                 $oNew->oxobject2category__oxid       = new oxField($oNew->setId( $myUtilsObject->generateUID() ));
00133                 $oNew->oxobject2category__oxobjectid = new oxField($sAdd);
00134                 $oNew->oxobject2category__oxcatnid   = new oxField($sCategoryID);
00135                 $oNew->oxobject2category__oxtime     = new oxField(time());
00136                 $oNew->save();
00137             }
00138 
00139             $this->resetArtSeoUrl( $aArticles );
00140             $this->resetCounter( "catArticle", $sCategoryID );
00141         }
00142     }
00143 
00149     public function removearticle()
00150     {
00151         $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00152         $sCategoryID = oxConfig::getParameter( 'oxid');
00153         $sShopID     = $this->getConfig()->getShopId();
00154         $oDb = oxDb::getDb();
00155 
00156         // adding
00157         if ( oxConfig::getParameter( 'all' ) ) {
00158 
00159             $sO2CView = getViewName('oxobject2category');
00160             $sQ = $this->_addFilter( "delete $sO2CView.* ".$this->_getQuery() );
00161             $oDb->Execute( $sQ );
00162 
00163         } elseif ( is_array( $aArticles ) && count( $aArticles ) ) {
00164             if ( !$this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00165                 $sQ = "delete from oxobject2category where oxcatnid=".$oDb->quote( $sCategoryID )." and oxobjectid in ( select oxid from oxarticles where oxparentid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) ) . ") )";
00166                 $oDb->execute( $sQ );
00167             }
00168             $sQ = "delete from oxobject2category where oxcatnid=".$oDb->quote( $sCategoryID )." and oxobjectid in ( " . implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) ) . ")";
00169             $oDb->execute( $sQ );
00170 
00171         }
00172 
00173         $this->resetArtSeoUrl( $sAdd );
00174         $this->resetCounter( "catArticle", $sCategoryID );
00175     }
00176 
00183     protected function _getQueryCols()
00184     {
00185         $myConfig = $this->getConfig();
00186         $sLangTag = oxLang::getInstance()->getLanguageTag();
00187 
00188         $sQ = '';
00189         $blSep = false;
00190         $aVisiblecols = $this->_getVisibleColNames();
00191         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00192             if ( $blSep )
00193                 $sQ .= ', ';
00194             $sViewTable = getViewName( $aCol[1] );
00195             // multilanguage
00196             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00197             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00198                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00199                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00200             } else {
00201                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00202             }
00203             $blSep = true;
00204         }
00205 
00206         $aIdentCols = $this->_getIdentColNames();
00207         foreach ( $aIdentCols as $iCnt => $aCol ) {
00208             if ( $blSep )
00209                 $sQ .= ', ';
00210 
00211             // multilanguage
00212             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00213             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00214         }
00215 
00216         return " $sQ ";
00217     }
00218 
00219 }