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             foreach ( $aArticles as $sAdd ) {
00125                 $oNewGroup = oxNew( 'oxbase' );
00126                 $oNewGroup->init( 'oxactions2article' );
00127                 $oNewGroup->oxactions2article__oxshopid   = new oxField( $myConfig->getShopId() );
00128                 $oNewGroup->oxactions2article__oxactionid = new oxField( $soxId );
00129                 $oNewGroup->oxactions2article__oxartid = new oxField( $sAdd );
00130                 $oNewGroup->oxactions2article__oxsort  = new oxField( $iSort++ );
00131                 $oNewGroup->save();
00132             }
00133         }
00134     }
00135 
00141     public function setSorting()
00142     {
00143         $myConfig = oxConfig::getInstance();
00144         $sArtTable = getViewName('oxarticles');
00145         $sSelId  = oxConfig::getParameter( 'oxid' );
00146         $sSelect  = "select * from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00147         $sSelect .= "where oxactions2article.oxactionid = '$sSelId' and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ".$this->_getSorting();
00148 
00149         $oList = oxNew( "oxlist" );
00150         $oList->init( "oxbase", "oxactions2article" );
00151         $oList->selectString( $sSelect );
00152 
00153         // fixing indexes
00154         $iSelCnt = 0;
00155         $aIdx2Id = array();
00156         foreach ( $oList as $sKey => $oSel ) {
00157             if ( $oSel->oxactions2article__oxsort->value != $iSelCnt ) {
00158                 $oSel->oxactions2article__oxsort->setValue($iSelCnt);
00159 
00160                 // saving new index
00161                 $oSel->save();
00162             }
00163             $aIdx2Id[$iSelCnt] = $sKey;
00164             $iSelCnt++;
00165         }
00166 
00167         //
00168         if ( ( $iKey = array_search( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
00169             $iDir = (oxConfig::getParameter( 'direction' ) == 'up')?($iKey-1):($iKey+1);
00170             if ( isset( $aIdx2Id[$iDir] ) ) {
00171 
00172                 // exchanging indexes
00173                 $oDir1 = $oList->offsetGet( $aIdx2Id[$iDir] );
00174                 $oDir2 = $oList->offsetGet( $aIdx2Id[$iKey] );
00175 
00176                 $iCopy = $oDir1->oxactions2article__oxsort->value;
00177                 $oDir1->oxactions2article__oxsort->setValue($oDir2->oxactions2article__oxsort->value);
00178                 $oDir2->oxactions2article__oxsort->setValue($iCopy);
00179 
00180                 $oDir1->save();
00181                 $oDir2->save();
00182             }
00183         }
00184 
00185         $sQAdd = $this->_getQuery();
00186 
00187         $sQ      = 'select ' . $this->_getQueryCols() . $sQAdd;
00188         $sCountQ = 'select count( * ) ' . $sQAdd;
00189 
00190         $this->_outputResponse( $this->_getData( $sCountQ, $sQ ) );
00191     }
00192 
00199     protected function _getQueryCols()
00200     {
00201         $myConfig      = $this->getConfig();
00202         $sQ = '';
00203         $blSep = false;
00204         $aVisiblecols = $this->_getVisibleColNames();
00205         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00206             if ( $blSep )
00207                 $sQ .= ', ';
00208             $sViewTable = getViewName( $aCol[1] );
00209             // multilanguage
00210             $sCol = $aCol[3]?$aCol[0].oxLang::getInstance()->getLanguageTag():$aCol[0];
00211             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00212                 $sVarSelect = "$sViewTable.oxvarselect".oxLang::getInstance()->getLanguageTag();
00213                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00214             } else {
00215                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00216             }
00217             $blSep = true;
00218         }
00219 
00220         $aIdentCols = $this->_getIdentColNames();
00221         foreach ( $aIdentCols as $iCnt => $aCol ) {
00222             if ( $blSep )
00223                 $sQ .= ', ';
00224 
00225             // multilanguage
00226             $sCol = $aCol[3]?$aCol[0].oxLang::getInstance()->getLanguageTag():$aCol[0];
00227             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00228         }
00229 
00230         return " $sQ ";
00231     }
00232 
00233 }

Generated on Thu Dec 4 12:04:55 2008 for OXID eShop CE by  doxygen 1.5.5