00001 <?php
00002
00003 $aColumns = array( 'container1' => array(
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
00046
00047 $sArtTable = $this->_getViewName('oxarticles');
00048 $sO2CView = $this->_getViewName('oxobject2category');
00049
00050 $sSelId = oxConfig::getParameter( 'oxid' );
00051 $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00052
00053
00054 if ( !$sSelId ) {
00055
00056 $sQAdd = " from $sArtTable where 1 ";
00057 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection')?'':" and $sArtTable.oxparentid = '' ";
00058 } else {
00059
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 = '$sSelId' ";
00065 } else {
00066
00067 $sQAdd = " from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00068 $sQAdd .= " where oxactions2article.oxactionid = '$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 = '$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
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 $sArtTable = $this->_getViewName('oxarticles');
00150 $sQ = "select max(oxactions2article.oxsort) from oxactions2article join $sArtTable on $sArtTable.oxid=oxactions2article.oxartid
00151 where oxactions2article.oxactionid = '".$soxId."' and oxactions2article.oxshopid = '".$myConfig->getShopId()."'
00152 and $sArtTable.oxid is not null";
00153 $iSort = ( (int) oxDb::getDb()->getOne( $sQ ) ) + 1;
00154
00155 if ( $soxId && $soxId != "-1" && is_array( $aArticles ) ) {
00156 $sShopId = $myConfig->getShopId();
00157 foreach ( $aArticles as $sAdd ) {
00158 $oNewGroup = oxNew( 'oxbase' );
00159 $oNewGroup->init( 'oxactions2article' );
00160 $oNewGroup->oxactions2article__oxshopid = new oxField( $sShopId );
00161 $oNewGroup->oxactions2article__oxactionid = new oxField( $soxId );
00162 $oNewGroup->oxactions2article__oxartid = new oxField( $sAdd );
00163 $oNewGroup->oxactions2article__oxsort = new oxField( $iSort++ );
00164 $oNewGroup->save();
00165 }
00166 }
00167 }
00168
00174 public function setSorting()
00175 {
00176 $myConfig = $this->getConfig();
00177 $sArtTable = $this->_getViewName('oxarticles');
00178 $sSelId = oxConfig::getParameter( 'oxid' );
00179 $sSelect = "select * from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00180 $sSelect .= "where oxactions2article.oxactionid = " . oxDb::getDb()->quote( $sSelId ) . " and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ".$this->_getSorting();
00181
00182 $oList = oxNew( "oxlist" );
00183 $oList->init( "oxbase", "oxactions2article" );
00184 $oList->selectString( $sSelect );
00185
00186
00187 $iSelCnt = 0;
00188 $aIdx2Id = array();
00189 foreach ( $oList as $sKey => $oSel ) {
00190 if ( $oSel->oxactions2article__oxsort->value != $iSelCnt ) {
00191 $oSel->oxactions2article__oxsort->setValue($iSelCnt);
00192
00193
00194 $oSel->save();
00195 }
00196 $aIdx2Id[$iSelCnt] = $sKey;
00197 $iSelCnt++;
00198 }
00199
00200
00201 if ( ( $iKey = array_search( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
00202 $iDir = (oxConfig::getParameter( 'direction' ) == 'up')?($iKey-1):($iKey+1);
00203 if ( isset( $aIdx2Id[$iDir] ) ) {
00204
00205
00206 $oDir1 = $oList->offsetGet( $aIdx2Id[$iDir] );
00207 $oDir2 = $oList->offsetGet( $aIdx2Id[$iKey] );
00208
00209 $iCopy = $oDir1->oxactions2article__oxsort->value;
00210 $oDir1->oxactions2article__oxsort->setValue($oDir2->oxactions2article__oxsort->value);
00211 $oDir2->oxactions2article__oxsort->setValue($iCopy);
00212
00213 $oDir1->save();
00214 $oDir2->save();
00215 }
00216 }
00217
00218 $sQAdd = $this->_getQuery();
00219
00220 $sQ = 'select ' . $this->_getQueryCols() . $sQAdd;
00221 $sCountQ = 'select count( * ) ' . $sQAdd;
00222
00223 $this->_outputResponse( $this->_getData( $sCountQ, $sQ ) );
00224 }
00225 }