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 
00076     protected function _getSorting()
00077     {
00078         if ( oxConfig::getParameter( 'oxid' ) && !oxConfig::getParameter( 'synchoxid' ) )
00079             return 'order by oxactions2article.oxsort ';
00080         return parent::_getSorting();
00081     }
00082 
00088     public function removeartfromact()
00089     {
00090         $aChosenArt = $this->_getActionIds( 'oxactions2article.oxid' );
00091         $sOxid = oxConfig::getParameter( 'oxid' );
00092         if ( oxConfig::getParameter( 'all' ) ) {
00093             $sQ = $this->_addFilter( "delete oxactions2article.* ".$this->_getQuery() );
00094             oxDb::getDb()->Execute( $sQ );
00095         } elseif ( is_array( $aChosenArt ) ) {
00096             $sQ = "delete from oxactions2article where oxactions2article.oxid in ('" . implode( "', '", $aChosenArt ) . "') ";
00097             oxDb::getDb()->Execute( $sQ );
00098         }
00099     }
00100 
00106     public function addarttoact()
00107     {
00108         $myConfig  = $this->getConfig();
00109         $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00110         $soxId     = oxConfig::getParameter( 'synchoxid' );
00111 
00112         if ( oxConfig::getParameter( 'all' ) ) {
00113             $sArtTable = getViewName('oxarticles');
00114             $aArticles = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00115         }
00116 
00117         $sArtTable = getViewName('oxarticles');
00118         $sQ = "select max(oxactions2article.oxsort) from oxactions2article join $sArtTable on $sArtTable.oxid=oxactions2article.oxartid
00119                where oxactions2article.oxactionid = '".$soxId."' and oxactions2article.oxshopid = '".$myConfig->getShopId()."'
00120                and $sArtTable.oxid is not null";
00121         $iSort = ( (int) oxDb::getDb()->getOne( $sQ ) ) + 1;
00122 
00123         if ( $soxId && $soxId != "-1" && is_array( $aArticles ) ) {
00124             $sShopId = $myConfig->getShopId();
00125             foreach ( $aArticles as $sAdd ) {
00126                 $oNewGroup = oxNew( 'oxbase' );
00127                 $oNewGroup->init( 'oxactions2article' );
00128                 $oNewGroup->oxactions2article__oxshopid   = new oxField( $sShopId );
00129                 $oNewGroup->oxactions2article__oxactionid = new oxField( $soxId );
00130                 $oNewGroup->oxactions2article__oxartid = new oxField( $sAdd );
00131                 $oNewGroup->oxactions2article__oxsort  = new oxField( $iSort++ );
00132                 $oNewGroup->save();
00133             }
00134         }
00135     }
00136 
00142     public function setSorting()
00143     {
00144         $myConfig  = $this->getConfig();
00145         $sArtTable = getViewName('oxarticles');
00146         $sSelId  = oxConfig::getParameter( 'oxid' );
00147         $sSelect  = "select * from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00148         $sSelect .= "where oxactions2article.oxactionid = '$sSelId' and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ".$this->_getSorting();
00149 
00150         $oList = oxNew( "oxlist" );
00151         $oList->init( "oxbase", "oxactions2article" );
00152         $oList->selectString( $sSelect );
00153 
00154         // fixing indexes
00155         $iSelCnt = 0;
00156         $aIdx2Id = array();
00157         foreach ( $oList as $sKey => $oSel ) {
00158             if ( $oSel->oxactions2article__oxsort->value != $iSelCnt ) {
00159                 $oSel->oxactions2article__oxsort->setValue($iSelCnt);
00160 
00161                 // saving new index
00162                 $oSel->save();
00163             }
00164             $aIdx2Id[$iSelCnt] = $sKey;
00165             $iSelCnt++;
00166         }
00167 
00168         //
00169         if ( ( $iKey = array_search( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
00170             $iDir = (oxConfig::getParameter( 'direction' ) == 'up')?($iKey-1):($iKey+1);
00171             if ( isset( $aIdx2Id[$iDir] ) ) {
00172 
00173                 // exchanging indexes
00174                 $oDir1 = $oList->offsetGet( $aIdx2Id[$iDir] );
00175                 $oDir2 = $oList->offsetGet( $aIdx2Id[$iKey] );
00176 
00177                 $iCopy = $oDir1->oxactions2article__oxsort->value;
00178                 $oDir1->oxactions2article__oxsort->setValue($oDir2->oxactions2article__oxsort->value);
00179                 $oDir2->oxactions2article__oxsort->setValue($iCopy);
00180 
00181                 $oDir1->save();
00182                 $oDir2->save();
00183             }
00184         }
00185 
00186         $sQAdd = $this->_getQuery();
00187 
00188         $sQ      = 'select ' . $this->_getQueryCols() . $sQAdd;
00189         $sCountQ = 'select count( * ) ' . $sQAdd;
00190 
00191         $this->_outputResponse( $this->_getData( $sCountQ, $sQ ) );
00192     }
00193 
00200     protected function _getQueryCols()
00201     {
00202         $myConfig = $this->getConfig();
00203         $sLangTag = oxLang::getInstance()->getLanguageTag();
00204 
00205         $sQ = '';
00206         $blSep = false;
00207         $aVisiblecols = $this->_getVisibleColNames();
00208         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00209             if ( $blSep )
00210                 $sQ .= ', ';
00211             $sViewTable = getViewName( $aCol[1] );
00212             // multilanguage
00213             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00214             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00215                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00216                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00217             } else {
00218                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00219             }
00220             $blSep = true;
00221         }
00222 
00223         $aIdentCols = $this->_getIdentColNames();
00224         foreach ( $aIdentCols as $iCnt => $aCol ) {
00225             if ( $blSep )
00226                 $sQ .= ', ';
00227 
00228             // multilanguage
00229             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00230             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00231         }
00232 
00233         return " $sQ ";
00234     }
00235 
00236 }

Generated on Wed Apr 22 12:26:29 2009 for OXID eShop CE by  doxygen 1.5.5