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         $sArtTable = getViewName('oxarticles');
00083         $sQ = parent::_addFilter( $sQ );
00084 
00085         // display variants or not ?
00086         $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00087         return $sQ;
00088     }
00089 
00095     protected function _getSorting()
00096     {
00097         if ( oxConfig::getParameter( 'oxid' ) && !oxConfig::getParameter( 'synchoxid' ) )
00098             return 'order by oxactions2article.oxsort ';
00099         return parent::_getSorting();
00100     }
00101 
00107     public function removeartfromact()
00108     {
00109         $aChosenArt = $this->_getActionIds( 'oxactions2article.oxid' );
00110         $sOxid = oxConfig::getParameter( 'oxid' );
00111         if ( oxConfig::getParameter( 'all' ) ) {
00112             $sQ = $this->_addFilter( "delete oxactions2article.* ".$this->_getQuery() );
00113             oxDb::getDb()->Execute( $sQ );
00114         } elseif ( is_array( $aChosenArt ) ) {
00115             $sQ = "delete from oxactions2article where oxactions2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00116             oxDb::getDb()->Execute( $sQ );
00117         }
00118     }
00119 
00125     public function addarttoact()
00126     {
00127         $myConfig  = $this->getConfig();
00128         $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00129         $soxId     = oxConfig::getParameter( 'synchoxid' );
00130 
00131         if ( oxConfig::getParameter( 'all' ) ) {
00132             $sArtTable = getViewName('oxarticles');
00133             $aArticles = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00134         }
00135 
00136         $sArtTable = getViewName('oxarticles');
00137         $sQ = "select max(oxactions2article.oxsort) from oxactions2article join $sArtTable on $sArtTable.oxid=oxactions2article.oxartid
00138                where oxactions2article.oxactionid = '".$soxId."' and oxactions2article.oxshopid = '".$myConfig->getShopId()."'
00139                and $sArtTable.oxid is not null";
00140         $iSort = ( (int) oxDb::getDb()->getOne( $sQ ) ) + 1;
00141 
00142         if ( $soxId && $soxId != "-1" && is_array( $aArticles ) ) {
00143             $sShopId = $myConfig->getShopId();
00144             foreach ( $aArticles as $sAdd ) {
00145                 $oNewGroup = oxNew( 'oxbase' );
00146                 $oNewGroup->init( 'oxactions2article' );
00147                 $oNewGroup->oxactions2article__oxshopid   = new oxField( $sShopId );
00148                 $oNewGroup->oxactions2article__oxactionid = new oxField( $soxId );
00149                 $oNewGroup->oxactions2article__oxartid = new oxField( $sAdd );
00150                 $oNewGroup->oxactions2article__oxsort  = new oxField( $iSort++ );
00151                 $oNewGroup->save();
00152             }
00153         }
00154     }
00155 
00161     public function setSorting()
00162     {
00163         $myConfig  = $this->getConfig();
00164         $sArtTable = getViewName('oxarticles');
00165         $sSelId  = oxConfig::getParameter( 'oxid' );
00166         $sSelect  = "select * from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00167         $sSelect .= "where oxactions2article.oxactionid = " . oxDb::getDb()->quote( $sSelId ) . " and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ".$this->_getSorting();
00168 
00169         $oList = oxNew( "oxlist" );
00170         $oList->init( "oxbase", "oxactions2article" );
00171         $oList->selectString( $sSelect );
00172 
00173         // fixing indexes
00174         $iSelCnt = 0;
00175         $aIdx2Id = array();
00176         foreach ( $oList as $sKey => $oSel ) {
00177             if ( $oSel->oxactions2article__oxsort->value != $iSelCnt ) {
00178                 $oSel->oxactions2article__oxsort->setValue($iSelCnt);
00179 
00180                 // saving new index
00181                 $oSel->save();
00182             }
00183             $aIdx2Id[$iSelCnt] = $sKey;
00184             $iSelCnt++;
00185         }
00186 
00187         //
00188         if ( ( $iKey = array_search( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
00189             $iDir = (oxConfig::getParameter( 'direction' ) == 'up')?($iKey-1):($iKey+1);
00190             if ( isset( $aIdx2Id[$iDir] ) ) {
00191 
00192                 // exchanging indexes
00193                 $oDir1 = $oList->offsetGet( $aIdx2Id[$iDir] );
00194                 $oDir2 = $oList->offsetGet( $aIdx2Id[$iKey] );
00195 
00196                 $iCopy = $oDir1->oxactions2article__oxsort->value;
00197                 $oDir1->oxactions2article__oxsort->setValue($oDir2->oxactions2article__oxsort->value);
00198                 $oDir2->oxactions2article__oxsort->setValue($iCopy);
00199 
00200                 $oDir1->save();
00201                 $oDir2->save();
00202             }
00203         }
00204 
00205         $sQAdd = $this->_getQuery();
00206 
00207         $sQ      = 'select ' . $this->_getQueryCols() . $sQAdd;
00208         $sCountQ = 'select count( * ) ' . $sQAdd;
00209 
00210         $this->_outputResponse( $this->_getData( $sCountQ, $sQ ) );
00211     }
00212 
00219     protected function _getQueryCols()
00220     {
00221         $myConfig = $this->getConfig();
00222         $sLangTag = oxLang::getInstance()->getLanguageTag();
00223 
00224         $sQ = '';
00225         $blSep = false;
00226         $aVisiblecols = $this->_getVisibleColNames();
00227         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00228             if ( $blSep )
00229                 $sQ .= ', ';
00230             $sViewTable = getViewName( $aCol[1] );
00231             // multilanguage
00232             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00233             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00234                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00235                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00236             } else {
00237                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00238             }
00239             $blSep = true;
00240         }
00241 
00242         $aIdentCols = $this->_getIdentColNames();
00243         foreach ( $aIdentCols as $iCnt => $aCol ) {
00244             if ( $blSep )
00245                 $sQ .= ', ';
00246 
00247             // multilanguage
00248             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00249             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00250         }
00251 
00252         return " $sQ ";
00253     }
00254 
00255 }