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

Generated on Mon Oct 26 20:07:16 2009 for OXID eShop CE by  doxygen 1.5.5