actions_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( 'oxsort',   'oxactions2article', 1, 0, 0 ),
00015                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00016                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00017                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00018                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00019                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00020                                         array( 'oxid',     'oxactions2article', 0, 0, 1 )
00021                                         )
00022                     );
00023 
00024 
00028 class ajaxComponent extends ajaxListComponent
00029 {
00035     protected function _getQuery()
00036     {
00037         $myConfig = $this->getConfig();
00038 
00039         // looking for table/view
00040         $sArtTable = getViewName('oxarticles');
00041         $sO2CView  = getViewName('oxobject2category');
00042 
00043         $sSelId      = oxConfig::getParameter( 'oxid' );
00044         $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00045 
00046         // category selected or not ?
00047         if ( !$sSelId ) {
00048             // dodger performance
00049             $sQAdd  = " from $sArtTable where 1 ";
00050             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection')?'':" and $sArtTable.oxparentid = '' ";
00051         } else {
00052             // selected category ?
00053             if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00054 
00055                 $sQAdd  = " from $sO2CView left join $sArtTable on ";
00056                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid=$sO2CView.oxobjectid or $sArtTable.oxparentid=$sO2CView.oxobjectid) ":" $sArtTable.oxid=$sO2CView.oxobjectid ";
00057                 $sQAdd .= " where $sO2CView.oxcatnid = '$sSelId' ";
00058             } else {
00059 
00060                 $sQAdd  = " from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00061                 $sQAdd .= " where oxactions2article.oxactionid = '$sSelId' and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ";
00062             }
00063         }
00064 
00065         if ( $sSynchSelId && $sSynchSelId != $sSelId ) {
00066             $sQAdd .= " and $sArtTable.oxid not in ( select oxactions2article.oxartid from oxactions2article ";
00067             $sQAdd .= " where oxactions2article.oxactionid = '$sSynchSelId' and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ) ";
00068         }
00069 
00070         return $sQAdd;
00071     }
00072 
00080     protected function _addFilter( $sQ )
00081     {
00082         $sQ = parent::_addFilter( $sQ );
00083 
00084         // display variants or not ?
00085         if ( $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00086             $sQ .= ' group by '.getViewName( 'oxarticles' ).'.oxid ';
00087 
00088             $oStr = getStr();
00089             if ( $oStr->strpos( $sQ, "select count( * ) " ) === 0 ) {
00090                 $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
00091             }
00092         }
00093         return $sQ;
00094     }
00095 
00101     protected function _getSorting()
00102     {
00103         if ( oxConfig::getParameter( 'oxid' ) && !oxConfig::getParameter( 'synchoxid' ) )
00104             return 'order by oxactions2article.oxsort ';
00105         return parent::_getSorting();
00106     }
00107 
00113     public function removeartfromact()
00114     {
00115         $aChosenArt = $this->_getActionIds( 'oxactions2article.oxid' );
00116         $sOxid = oxConfig::getParameter( 'oxid' );
00117         if ( oxConfig::getParameter( 'all' ) ) {
00118             $sQ = parent::_addFilter( "delete oxactions2article.* ".$this->_getQuery() );
00119             oxDb::getDb()->Execute( $sQ );
00120         } elseif ( is_array( $aChosenArt ) ) {
00121             $sQ = "delete from oxactions2article where oxactions2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00122             oxDb::getDb()->Execute( $sQ );
00123         }
00124     }
00125 
00131     public function addarttoact()
00132     {
00133         $myConfig  = $this->getConfig();
00134         $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00135         $soxId     = oxConfig::getParameter( 'synchoxid' );
00136 
00137         if ( oxConfig::getParameter( 'all' ) ) {
00138             $sArtTable = getViewName('oxarticles');
00139             $aArticles = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00140         }
00141 
00142         $sArtTable = getViewName('oxarticles');
00143         $sQ = "select max(oxactions2article.oxsort) from oxactions2article join $sArtTable on $sArtTable.oxid=oxactions2article.oxartid
00144                where oxactions2article.oxactionid = '".$soxId."' and oxactions2article.oxshopid = '".$myConfig->getShopId()."'
00145                and $sArtTable.oxid is not null";
00146         $iSort = ( (int) oxDb::getDb()->getOne( $sQ ) ) + 1;
00147 
00148         if ( $soxId && $soxId != "-1" && is_array( $aArticles ) ) {
00149             $sShopId = $myConfig->getShopId();
00150             foreach ( $aArticles as $sAdd ) {
00151                 $oNewGroup = oxNew( 'oxbase' );
00152                 $oNewGroup->init( 'oxactions2article' );
00153                 $oNewGroup->oxactions2article__oxshopid   = new oxField( $sShopId );
00154                 $oNewGroup->oxactions2article__oxactionid = new oxField( $soxId );
00155                 $oNewGroup->oxactions2article__oxartid = new oxField( $sAdd );
00156                 $oNewGroup->oxactions2article__oxsort  = new oxField( $iSort++ );
00157                 $oNewGroup->save();
00158             }
00159         }
00160     }
00161 
00167     public function setSorting()
00168     {
00169         $myConfig  = $this->getConfig();
00170         $sArtTable = getViewName('oxarticles');
00171         $sSelId  = oxConfig::getParameter( 'oxid' );
00172         $sSelect  = "select * from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00173         $sSelect .= "where oxactions2article.oxactionid = " . oxDb::getDb()->quote( $sSelId ) . " and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ".$this->_getSorting();
00174 
00175         $oList = oxNew( "oxlist" );
00176         $oList->init( "oxbase", "oxactions2article" );
00177         $oList->selectString( $sSelect );
00178 
00179         // fixing indexes
00180         $iSelCnt = 0;
00181         $aIdx2Id = array();
00182         foreach ( $oList as $sKey => $oSel ) {
00183             if ( $oSel->oxactions2article__oxsort->value != $iSelCnt ) {
00184                 $oSel->oxactions2article__oxsort->setValue($iSelCnt);
00185 
00186                 // saving new index
00187                 $oSel->save();
00188             }
00189             $aIdx2Id[$iSelCnt] = $sKey;
00190             $iSelCnt++;
00191         }
00192 
00193         //
00194         if ( ( $iKey = array_search( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
00195             $iDir = (oxConfig::getParameter( 'direction' ) == 'up')?($iKey-1):($iKey+1);
00196             if ( isset( $aIdx2Id[$iDir] ) ) {
00197 
00198                 // exchanging indexes
00199                 $oDir1 = $oList->offsetGet( $aIdx2Id[$iDir] );
00200                 $oDir2 = $oList->offsetGet( $aIdx2Id[$iKey] );
00201 
00202                 $iCopy = $oDir1->oxactions2article__oxsort->value;
00203                 $oDir1->oxactions2article__oxsort->setValue($oDir2->oxactions2article__oxsort->value);
00204                 $oDir2->oxactions2article__oxsort->setValue($iCopy);
00205 
00206                 $oDir1->save();
00207                 $oDir2->save();
00208             }
00209         }
00210 
00211         $sQAdd = $this->_getQuery();
00212 
00213         $sQ      = 'select ' . $this->_getQueryCols() . $sQAdd;
00214         $sCountQ = 'select count( * ) ' . $sQAdd;
00215 
00216         $this->_outputResponse( $this->_getData( $sCountQ, $sQ ) );
00217     }
00218 
00225     protected function _getQueryCols()
00226     {
00227         $myConfig = $this->getConfig();
00228         $sLangTag = oxLang::getInstance()->getLanguageTag();
00229 
00230         $sQ = '';
00231         $blSep = false;
00232         $aVisiblecols = $this->_getVisibleColNames();
00233         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00234             if ( $blSep )
00235                 $sQ .= ', ';
00236             $sViewTable = getViewName( $aCol[1] );
00237             // multilanguage
00238             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00239             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00240                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00241                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00242             } else {
00243                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00244             }
00245             $blSep = true;
00246         }
00247 
00248         $aIdentCols = $this->_getIdentColNames();
00249         foreach ( $aIdentCols as $iCnt => $aCol ) {
00250             if ( $blSep )
00251                 $sQ .= ', ';
00252 
00253             // multilanguage
00254             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00255             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00256         }
00257 
00258         return " $sQ ";
00259     }
00260 
00261 }