actions_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class actions_main_ajax extends ajaxListComponent
00007 {
00013     protected $_blAllowExtColumns = true;
00014 
00020     protected $_aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00021                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00022                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00023                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00024                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00025                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00026                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00027                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00028                                         ),
00029                                 'container2' => array(
00030                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00031                                         array( 'oxsort',   'oxactions2article', 1, 0, 0 ),
00032                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00033                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00034                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00035                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00036                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00037                                         array( 'oxid',     'oxactions2article', 0, 0, 1 )
00038                                         )
00039                                 );
00040 
00046     protected function _getQuery()
00047     {
00048         $myConfig = $this->getConfig();
00049         $oDb = oxDb::getDb();
00050         // looking for table/view
00051         $sArtTable = $this->_getViewName('oxarticles');
00052         $sO2CView  = $this->_getViewName('oxobject2category');
00053 
00054         $sSelId      = oxConfig::getParameter( 'oxid' );
00055         $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00056 
00057         // category selected or not ?
00058         if ( !$sSelId ) {
00059             // dodger performance
00060             $sQAdd  = " from $sArtTable where 1 ";
00061             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection')?'':" and $sArtTable.oxparentid = '' ";
00062         } else {
00063             // selected category ?
00064             if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00065 
00066                 $sQAdd  = " from $sO2CView left join $sArtTable on ";
00067                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid=$sO2CView.oxobjectid or $sArtTable.oxparentid=$sO2CView.oxobjectid) ":" $sArtTable.oxid=$sO2CView.oxobjectid ";
00068                 $sQAdd .= " where $sO2CView.oxcatnid = ".$oDb->quote( $sSelId );
00069             } else {
00070 
00071                 $sQAdd  = " from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00072                 $sQAdd .= " where oxactions2article.oxactionid = ".$oDb->quote( $sSelId )." and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ";
00073             }
00074         }
00075 
00076         if ( $sSynchSelId && $sSynchSelId != $sSelId ) {
00077             $sQAdd .= " and $sArtTable.oxid not in ( select oxactions2article.oxartid from oxactions2article ";
00078             $sQAdd .= " where oxactions2article.oxactionid = ".$oDb->quote( $sSynchSelId )." and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ) ";
00079         }
00080 
00081         return $sQAdd;
00082     }
00083 
00091     protected function _addFilter( $sQ )
00092     {
00093         $sQ = parent::_addFilter( $sQ );
00094 
00095         // display variants or not ?
00096         if ( $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00097             $sQ .= ' group by '.$this->_getViewName( 'oxarticles' ).'.oxid ';
00098 
00099             $oStr = getStr();
00100             if ( $oStr->strpos( $sQ, "select count( * ) " ) === 0 ) {
00101                 $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
00102             }
00103         }//echo $sQ;
00104         return $sQ;
00105     }
00106 
00112     protected function _getSorting()
00113     {
00114         if ( oxConfig::getParameter( 'oxid' ) && !oxConfig::getParameter( 'synchoxid' ) )
00115             return 'order by oxactions2article.oxsort ';
00116         return parent::_getSorting();
00117     }
00118 
00124     public function removeArtFromAct()
00125     {
00126         $aChosenArt = $this->_getActionIds( 'oxactions2article.oxid' );
00127         $sOxid = oxConfig::getParameter( 'oxid' );
00128         if ( oxConfig::getParameter( 'all' ) ) {
00129             $sQ = parent::_addFilter( "delete oxactions2article.* ".$this->_getQuery() );
00130             oxDb::getDb()->Execute( $sQ );
00131         } elseif ( is_array( $aChosenArt ) ) {
00132             $sQ = "delete from oxactions2article where oxactions2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00133             oxDb::getDb()->Execute( $sQ );
00134         }
00135     }
00136 
00142     public function addArtToAct()
00143     {
00144         $myConfig  = $this->getConfig();
00145         $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00146         $soxId     = oxConfig::getParameter( 'synchoxid' );
00147 
00148         if ( oxConfig::getParameter( 'all' ) ) {
00149             $sArtTable = $this->_getViewName('oxarticles');
00150             $aArticles = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00151         }
00152 
00153         $oDb = oxDb::getDb();
00154         $sArtTable = $this->_getViewName('oxarticles');
00155         $sQ = "select max(oxactions2article.oxsort) from oxactions2article join $sArtTable on $sArtTable.oxid=oxactions2article.oxartid
00156                where oxactions2article.oxactionid = ".$oDb->quote( $soxId )." and oxactions2article.oxshopid = '".$myConfig->getShopId()."'
00157                and $sArtTable.oxid is not null";
00158         $iSort = ( (int) $oDb->getOne( $sQ, false, false ) ) + 1;
00159 
00160         if ( $soxId && $soxId != "-1" && is_array( $aArticles ) ) {
00161             $sShopId = $myConfig->getShopId();
00162             foreach ( $aArticles as $sAdd ) {
00163                 $oNewGroup = oxNew( 'oxbase' );
00164                 $oNewGroup->init( 'oxactions2article' );
00165                 $oNewGroup->oxactions2article__oxshopid   = new oxField( $sShopId );
00166                 $oNewGroup->oxactions2article__oxactionid = new oxField( $soxId );
00167                 $oNewGroup->oxactions2article__oxartid = new oxField( $sAdd );
00168                 $oNewGroup->oxactions2article__oxsort  = new oxField( $iSort++ );
00169                 $oNewGroup->save();
00170             }
00171         }
00172     }
00173 
00179     public function setSorting()
00180     {
00181         $myConfig  = $this->getConfig();
00182         $sArtTable = $this->_getViewName('oxarticles');
00183         $sSelId  = oxConfig::getParameter( 'oxid' );
00184         $sSelect  = "select * from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00185         $sSelect .= "where oxactions2article.oxactionid = " . oxDb::getDb()->quote( $sSelId ) . " and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ".$this->_getSorting();
00186 
00187         $oList = oxNew( "oxlist" );
00188         $oList->init( "oxbase", "oxactions2article" );
00189         $oList->selectString( $sSelect );
00190 
00191         // fixing indexes
00192         $iSelCnt = 0;
00193         $aIdx2Id = array();
00194         foreach ( $oList as $sKey => $oSel ) {
00195             if ( $oSel->oxactions2article__oxsort->value != $iSelCnt ) {
00196                 $oSel->oxactions2article__oxsort->setValue($iSelCnt);
00197 
00198                 // saving new index
00199                 $oSel->save();
00200             }
00201             $aIdx2Id[$iSelCnt] = $sKey;
00202             $iSelCnt++;
00203         }
00204 
00205         //
00206         if ( ( $iKey = array_search( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
00207             $iDir = (oxConfig::getParameter( 'direction' ) == 'up')?($iKey-1):($iKey+1);
00208             if ( isset( $aIdx2Id[$iDir] ) ) {
00209 
00210                 // exchanging indexes
00211                 $oDir1 = $oList->offsetGet( $aIdx2Id[$iDir] );
00212                 $oDir2 = $oList->offsetGet( $aIdx2Id[$iKey] );
00213 
00214                 $iCopy = $oDir1->oxactions2article__oxsort->value;
00215                 $oDir1->oxactions2article__oxsort->setValue($oDir2->oxactions2article__oxsort->value);
00216                 $oDir2->oxactions2article__oxsort->setValue($iCopy);
00217 
00218                 $oDir1->save();
00219                 $oDir2->save();
00220             }
00221         }
00222 
00223         $sQAdd = $this->_getQuery();
00224 
00225         $sQ      = 'select ' . $this->_getQueryCols() . $sQAdd;
00226         $sCountQ = 'select count( * ) ' . $sQAdd;
00227 
00228         $this->_outputResponse( $this->_getData( $sCountQ, $sQ ) );
00229 
00230     }
00231 }