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 
00097             $sO2CView = getViewName('oxobject2category');
00098 
00099             $oNew = oxNew( 'oxbase' );
00100             $oNew->init( 'oxobject2category' );
00101 
00102             foreach ( $aArticles as $sAdd) {
00103 
00104                 // check, if it's already in, then don't add it again
00105                 $sSelect = "select 1 from $sO2CView as oxobject2category where oxobject2category.oxcatnid='$sCategoryID' and oxobject2category.oxobjectid ='$sAdd'";
00106                 if ( oxDb::getDb()->getOne( $sSelect ) )
00107                     continue;
00108 
00109                 $oNew->oxobject2category__oxid       = new oxField($oNew->setId( oxUtilsObject::getInstance()->generateUID() ));
00110                 $oNew->oxobject2category__oxobjectid = new oxField($sAdd);
00111                 $oNew->oxobject2category__oxcatnid   = new oxField($sCategoryID);
00112                 $oNew->oxobject2category__oxtime     = new oxField(time());
00113                 $oNew->save();
00114             }
00115         }
00116     }
00117 
00123     public function removearticle()
00124     {
00125         $aArticles = $this->_getActionIds( 'oxobject2category.oxid' );
00126         $sCategoryID = oxConfig::getParameter( 'oxajax_fid');
00127         $sShopID     = $this->getConfig()->getShopId();
00128 
00129         // adding
00130         if ( oxConfig::getParameter( 'all' ) ) {
00131 
00132             $sO2CView = getViewName('oxobject2category');
00133             $sQ = $this->_addFilter( "delete $sO2CView.* ".$this->_getQuery() );
00134             oxDb::getDb()->Execute( $sQ );
00135 
00136         } elseif ( is_array( $aArticles ) && count( $aArticles ) ) {
00137 
00138             $sQ = 'delete from oxobject2category where oxid in ("' . implode( '", "', $aArticles ) . '")';
00139             oxDb::getDb()->Execute( $sQ );
00140 
00141         }
00142     }
00143 
00150     protected function _getQueryCols()
00151     {
00152         $myConfig      = $this->getConfig();
00153         $sQ = '';
00154         $blSep = false;
00155         $aVisiblecols = $this->_getVisibleColNames();
00156         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00157             if ( $blSep )
00158                 $sQ .= ', ';
00159             $sViewTable = getViewName( $aCol[1] );
00160             // multilanguage
00161             $sCol = $aCol[3]?$aCol[0].oxLang::getInstance()->getLanguageTag():$aCol[0];
00162             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00163                 $sVarSelect = "$sViewTable.oxvarselect".oxLang::getInstance()->getLanguageTag();
00164                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00165             } else {
00166                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00167             }
00168             $blSep = true;
00169         }
00170 
00171         $aIdentCols = $this->_getIdentColNames();
00172         foreach ( $aIdentCols as $iCnt => $aCol ) {
00173             if ( $blSep )
00174                 $sQ .= ', ';
00175 
00176             // multilanguage
00177             $sCol = $aCol[3]?$aCol[0].oxLang::getInstance()->getLanguageTag():$aCol[0];
00178             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00179         }
00180 
00181         return " $sQ ";
00182     }
00183 
00184 }

Generated on Thu Dec 4 12:04:55 2008 for OXID eShop CE by  doxygen 1.5.5