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 $_blAllowExtColumns = true;
00036 
00042     protected function _getQuery()
00043     {
00044         $myConfig = $this->getConfig();
00045         $oDb = oxDb::getDb();
00046         // looking for table/view
00047         $sArtTable = $this->_getViewName('oxarticles');
00048         $sO2CView  = $this->_getViewName('oxobject2category');
00049 
00050         $sSelId      = oxConfig::getParameter( 'oxid' );
00051         $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00052 
00053         // category selected or not ?
00054         if ( !$sSelId ) {
00055             // dodger performance
00056             $sQAdd  = " from $sArtTable where 1 ";
00057             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection')?'':" and $sArtTable.oxparentid = '' ";
00058         } else {
00059             // selected category ?
00060             if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00061 
00062                 $sQAdd  = " from $sO2CView left join $sArtTable on ";
00063                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid=$sO2CView.oxobjectid or $sArtTable.oxparentid=$sO2CView.oxobjectid) ":" $sArtTable.oxid=$sO2CView.oxobjectid ";
00064                 $sQAdd .= " where $sO2CView.oxcatnid = ".$oDb->quote( $sSelId );
00065             } else {
00066 
00067                 $sQAdd  = " from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00068                 $sQAdd .= " where oxactions2article.oxactionid = ".$oDb->quote( $sSelId )." and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ";
00069             }
00070         }
00071 
00072         if ( $sSynchSelId && $sSynchSelId != $sSelId ) {
00073             $sQAdd .= " and $sArtTable.oxid not in ( select oxactions2article.oxartid from oxactions2article ";
00074             $sQAdd .= " where oxactions2article.oxactionid = ".$oDb->quote( $sSynchSelId )." and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ) ";
00075         }
00076 
00077         return $sQAdd;
00078     }
00079 
00087     protected function _addFilter( $sQ )
00088     {
00089         $sQ = parent::_addFilter( $sQ );
00090 
00091         // display variants or not ?
00092         if ( $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00093             $sQ .= ' group by '.$this->_getViewName( 'oxarticles' ).'.oxid ';
00094 
00095             $oStr = getStr();
00096             if ( $oStr->strpos( $sQ, "select count( * ) " ) === 0 ) {
00097                 $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
00098             }
00099         }
00100         return $sQ;
00101     }
00102 
00108     protected function _getSorting()
00109     {
00110         if ( oxConfig::getParameter( 'oxid' ) && !oxConfig::getParameter( 'synchoxid' ) )
00111             return 'order by oxactions2article.oxsort ';
00112         return parent::_getSorting();
00113     }
00114 
00120     public function removeartfromact()
00121     {
00122         $aChosenArt = $this->_getActionIds( 'oxactions2article.oxid' );
00123         $sOxid = oxConfig::getParameter( 'oxid' );
00124         if ( oxConfig::getParameter( 'all' ) ) {
00125             $sQ = parent::_addFilter( "delete oxactions2article.* ".$this->_getQuery() );
00126             oxDb::getDb()->Execute( $sQ );
00127         } elseif ( is_array( $aChosenArt ) ) {
00128             $sQ = "delete from oxactions2article where oxactions2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00129             oxDb::getDb()->Execute( $sQ );
00130         }
00131     }
00132 
00138     public function addarttoact()
00139     {
00140         $myConfig  = $this->getConfig();
00141         $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00142         $soxId     = oxConfig::getParameter( 'synchoxid' );
00143 
00144         if ( oxConfig::getParameter( 'all' ) ) {
00145             $sArtTable = $this->_getViewName('oxarticles');
00146             $aArticles = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00147         }
00148 
00149         $oDb = oxDb::getDb();
00150         $sArtTable = $this->_getViewName('oxarticles');
00151         $sQ = "select max(oxactions2article.oxsort) from oxactions2article join $sArtTable on $sArtTable.oxid=oxactions2article.oxartid
00152                where oxactions2article.oxactionid = ".$oDb->quote( $soxId )." and oxactions2article.oxshopid = '".$myConfig->getShopId()."'
00153                and $sArtTable.oxid is not null";
00154         $iSort = ( (int) $oDb->getOne( $sQ ) ) + 1;
00155 
00156         if ( $soxId && $soxId != "-1" && is_array( $aArticles ) ) {
00157             $sShopId = $myConfig->getShopId();
00158             foreach ( $aArticles as $sAdd ) {
00159                 $oNewGroup = oxNew( 'oxbase' );
00160                 $oNewGroup->init( 'oxactions2article' );
00161                 $oNewGroup->oxactions2article__oxshopid   = new oxField( $sShopId );
00162                 $oNewGroup->oxactions2article__oxactionid = new oxField( $soxId );
00163                 $oNewGroup->oxactions2article__oxartid = new oxField( $sAdd );
00164                 $oNewGroup->oxactions2article__oxsort  = new oxField( $iSort++ );
00165                 $oNewGroup->save();
00166             }
00167         }
00168     }
00169 
00175     public function setSorting()
00176     {
00177         $myConfig  = $this->getConfig();
00178         $sArtTable = $this->_getViewName('oxarticles');
00179         $sSelId  = oxConfig::getParameter( 'oxid' );
00180         $sSelect  = "select * from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00181         $sSelect .= "where oxactions2article.oxactionid = " . oxDb::getDb()->quote( $sSelId ) . " and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ".$this->_getSorting();
00182 
00183         $oList = oxNew( "oxlist" );
00184         $oList->init( "oxbase", "oxactions2article" );
00185         $oList->selectString( $sSelect );
00186 
00187         // fixing indexes
00188         $iSelCnt = 0;
00189         $aIdx2Id = array();
00190         foreach ( $oList as $sKey => $oSel ) {
00191             if ( $oSel->oxactions2article__oxsort->value != $iSelCnt ) {
00192                 $oSel->oxactions2article__oxsort->setValue($iSelCnt);
00193 
00194                 // saving new index
00195                 $oSel->save();
00196             }
00197             $aIdx2Id[$iSelCnt] = $sKey;
00198             $iSelCnt++;
00199         }
00200 
00201         //
00202         if ( ( $iKey = array_search( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
00203             $iDir = (oxConfig::getParameter( 'direction' ) == 'up')?($iKey-1):($iKey+1);
00204             if ( isset( $aIdx2Id[$iDir] ) ) {
00205 
00206                 // exchanging indexes
00207                 $oDir1 = $oList->offsetGet( $aIdx2Id[$iDir] );
00208                 $oDir2 = $oList->offsetGet( $aIdx2Id[$iKey] );
00209 
00210                 $iCopy = $oDir1->oxactions2article__oxsort->value;
00211                 $oDir1->oxactions2article__oxsort->setValue($oDir2->oxactions2article__oxsort->value);
00212                 $oDir2->oxactions2article__oxsort->setValue($iCopy);
00213 
00214                 $oDir1->save();
00215                 $oDir2->save();
00216             }
00217         }
00218 
00219         $sQAdd = $this->_getQuery();
00220 
00221         $sQ      = 'select ' . $this->_getQueryCols() . $sQAdd;
00222         $sCountQ = 'select count( * ) ' . $sQAdd;
00223 
00224         $this->_outputResponse( $this->_getData( $sCountQ, $sQ ) );
00225     }
00226 }