OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
actions_main_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  protected $_blAllowExtColumns = true;
14 
20  protected $_aColumns = array( 'container1' => array( // field , table, visible, multilanguage, ident
21  array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
22  array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
23  array( 'oxean', 'oxarticles', 1, 0, 0 ),
24  array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
25  array( 'oxprice', 'oxarticles', 0, 0, 0 ),
26  array( 'oxstock', 'oxarticles', 0, 0, 0 ),
27  array( 'oxid', 'oxarticles', 0, 0, 1 )
28  ),
29  'container2' => array(
30  array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
31  array( 'oxsort', 'oxactions2article', 1, 0, 0 ),
32  array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
33  array( 'oxean', 'oxarticles', 1, 0, 0 ),
34  array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
35  array( 'oxprice', 'oxarticles', 0, 0, 0 ),
36  array( 'oxstock', 'oxarticles', 0, 0, 0 ),
37  array( 'oxid', 'oxactions2article', 0, 0, 1 )
38  )
39  );
40 
46  protected function _getQuery()
47  {
48  $myConfig = $this->getConfig();
49  $oDb = oxDb::getDb();
50  // looking for table/view
51  $sArtTable = $this->_getViewName('oxarticles');
52  $sO2CView = $this->_getViewName('oxobject2category');
53 
54  $sSelId = oxConfig::getParameter( 'oxid' );
55  $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
56 
57  // category selected or not ?
58  if ( !$sSelId ) {
59  // dodger performance
60  $sQAdd = " from $sArtTable where 1 ";
61  $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection')?'':" and $sArtTable.oxparentid = '' ";
62  } else {
63  // selected category ?
64  if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
65 
66  $sQAdd = " from $sO2CView left join $sArtTable on ";
67  $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid=$sO2CView.oxobjectid or $sArtTable.oxparentid=$sO2CView.oxobjectid) ":" $sArtTable.oxid=$sO2CView.oxobjectid ";
68  $sQAdd .= " where $sO2CView.oxcatnid = ".$oDb->quote( $sSelId );
69  } else {
70 
71  $sQAdd = " from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
72  $sQAdd .= " where oxactions2article.oxactionid = ".$oDb->quote( $sSelId )." and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ";
73  }
74  }
75 
76  if ( $sSynchSelId && $sSynchSelId != $sSelId ) {
77  $sQAdd .= " and $sArtTable.oxid not in ( select oxactions2article.oxartid from oxactions2article ";
78  $sQAdd .= " where oxactions2article.oxactionid = ".$oDb->quote( $sSynchSelId )." and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ) ";
79  }
80 
81  return $sQAdd;
82  }
83 
91  protected function _addFilter( $sQ )
92  {
93  $sQ = parent::_addFilter( $sQ );
94 
95  // display variants or not ?
96  if ( $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
97  $sQ .= ' group by '.$this->_getViewName( 'oxarticles' ).'.oxid ';
98 
99  $oStr = getStr();
100  if ( $oStr->strpos( $sQ, "select count( * ) " ) === 0 ) {
101  $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
102  }
103  }//echo $sQ;
104  return $sQ;
105  }
106 
112  protected function _getSorting()
113  {
114  if ( oxConfig::getParameter( 'oxid' ) && !oxConfig::getParameter( 'synchoxid' ) )
115  return 'order by oxactions2article.oxsort ';
116  return parent::_getSorting();
117  }
118 
124  public function removeArtFromAct()
125  {
126  $aChosenArt = $this->_getActionIds( 'oxactions2article.oxid' );
127  $sOxid = oxConfig::getParameter( 'oxid' );
128  if ( oxConfig::getParameter( 'all' ) ) {
129  $sQ = parent::_addFilter( "delete oxactions2article.* ".$this->_getQuery() );
130  oxDb::getDb()->Execute( $sQ );
131  } elseif ( is_array( $aChosenArt ) ) {
132  $sQ = "delete from oxactions2article where oxactions2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
133  oxDb::getDb()->Execute( $sQ );
134  }
135  }
136 
142  public function addArtToAct()
143  {
144  $myConfig = $this->getConfig();
145  $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
146  $soxId = oxConfig::getParameter( 'synchoxid' );
147 
148  if ( oxConfig::getParameter( 'all' ) ) {
149  $sArtTable = $this->_getViewName('oxarticles');
150  $aArticles = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
151  }
152 
153  $oDb = oxDb::getDb();
154  $sArtTable = $this->_getViewName('oxarticles');
155  $sQ = "select max(oxactions2article.oxsort) from oxactions2article join $sArtTable on $sArtTable.oxid=oxactions2article.oxartid
156  where oxactions2article.oxactionid = ".$oDb->quote( $soxId )." and oxactions2article.oxshopid = '".$myConfig->getShopId()."'
157  and $sArtTable.oxid is not null";
158  $iSort = ( (int) $oDb->getOne( $sQ, false, false ) ) + 1;
159 
160  if ( $soxId && $soxId != "-1" && is_array( $aArticles ) ) {
161  $sShopId = $myConfig->getShopId();
162  foreach ( $aArticles as $sAdd ) {
163  $oNewGroup = oxNew( 'oxbase' );
164  $oNewGroup->init( 'oxactions2article' );
165  $oNewGroup->oxactions2article__oxshopid = new oxField( $sShopId );
166  $oNewGroup->oxactions2article__oxactionid = new oxField( $soxId );
167  $oNewGroup->oxactions2article__oxartid = new oxField( $sAdd );
168  $oNewGroup->oxactions2article__oxsort = new oxField( $iSort++ );
169  $oNewGroup->save();
170  }
171  }
172  }
173 
179  public function setSorting()
180  {
181  $myConfig = $this->getConfig();
182  $sArtTable = $this->_getViewName('oxarticles');
183  $sSelId = oxConfig::getParameter( 'oxid' );
184  $sSelect = "select * from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
185  $sSelect .= "where oxactions2article.oxactionid = " . oxDb::getDb()->quote( $sSelId ) . " and oxactions2article.oxshopid = '".$myConfig->getShopID()."' ".$this->_getSorting();
186 
187  $oList = oxNew( "oxlist" );
188  $oList->init( "oxbase", "oxactions2article" );
189  $oList->selectString( $sSelect );
190 
191  // fixing indexes
192  $iSelCnt = 0;
193  $aIdx2Id = array();
194  foreach ( $oList as $sKey => $oSel ) {
195  if ( $oSel->oxactions2article__oxsort->value != $iSelCnt ) {
196  $oSel->oxactions2article__oxsort->setValue($iSelCnt);
197 
198  // saving new index
199  $oSel->save();
200  }
201  $aIdx2Id[$iSelCnt] = $sKey;
202  $iSelCnt++;
203  }
204 
205  //
206  if ( ( $iKey = array_search( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
207  $iDir = (oxConfig::getParameter( 'direction' ) == 'up')?($iKey-1):($iKey+1);
208  if ( isset( $aIdx2Id[$iDir] ) ) {
209 
210  // exchanging indexes
211  $oDir1 = $oList->offsetGet( $aIdx2Id[$iDir] );
212  $oDir2 = $oList->offsetGet( $aIdx2Id[$iKey] );
213 
214  $iCopy = $oDir1->oxactions2article__oxsort->value;
215  $oDir1->oxactions2article__oxsort->setValue($oDir2->oxactions2article__oxsort->value);
216  $oDir2->oxactions2article__oxsort->setValue($iCopy);
217 
218  $oDir1->save();
219  $oDir2->save();
220  }
221  }
222 
223  $sQAdd = $this->_getQuery();
224 
225  $sQ = 'select ' . $this->_getQueryCols() . $sQAdd;
226  $sCountQ = 'select count( * ) ' . $sQAdd;
227 
228  $this->_outputResponse( $this->_getData( $sCountQ, $sQ ) );
229 
230  }
231 }