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

Generated on Tue Sep 29 16:45:12 2009 for OXID eShop CE by  doxygen 1.5.5