OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
selectlist_order_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  protected $_aColumns = array( 'container1' => array(
14  array( 'oxtitle', 'oxselectlist', 1, 1, 0 ),
15  array( 'oxsort', 'oxobject2selectlist', 1, 0, 0 ),
16  array( 'oxident', 'oxselectlist', 0, 0, 0 ),
17  array( 'oxvaldesc', 'oxselectlist', 0, 0, 0 ),
18  array( 'oxid', 'oxobject2selectlist', 0, 0, 1 )
19  )
20  );
21 
27  protected function _getQuery()
28  {
29  $sSelTable = $this->_getViewName('oxselectlist');
30  $sArtId = oxConfig::getParameter( 'oxid' );
31 
32  $sQAdd = " from $sSelTable left join oxobject2selectlist on oxobject2selectlist.oxselnid = $sSelTable.oxid where oxobjectid = '$sArtId' ";
33 
34  return $sQAdd;
35  }
36 
42  protected function _getSorting()
43  {
44  return 'order by oxobject2selectlist.oxsort ';
45  }
46 
52  public function setSorting()
53  {
54  $sSelId = oxConfig::getParameter( 'oxid' );
55  $sSelect = "select * from oxobject2selectlist where oxobjectid='$sSelId' order by oxsort";
56 
57  $oList = oxNew( "oxlist" );
58  $oList->init( "oxbase", "oxobject2selectlist" );
59  $oList->selectString( $sSelect );
60 
61  // fixing indexes
62  $iSelCnt = 0;
63  $aIdx2Id = array();
64  foreach ( $oList as $sKey => $oSel ) {
65 
66  if ( $oSel->oxobject2selectlist__oxsort->value != $iSelCnt ) {
67  $oSel->oxobject2selectlist__oxsort->setValue($iSelCnt);
68 
69  // saving new index
70  $oSel->save();
71  }
72  $aIdx2Id[$iSelCnt] = $sKey;
73  $iSelCnt++;
74  }
75 
76  //
77  if ( ( $iKey = array_search( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
78  $iDir = (oxConfig::getParameter( 'direction' ) == 'up')?($iKey-1):($iKey+1);
79  if ( isset( $aIdx2Id[$iDir] ) ) {
80  // exchanging indexes
81  $oDir1 = $oList->offsetGet( $aIdx2Id[$iDir] );
82  $oDir2 = $oList->offsetGet( $aIdx2Id[$iKey] );
83 
84  $iCopy = $oDir1->oxobject2selectlist__oxsort->value;
85  $oDir1->oxobject2selectlist__oxsort->setValue($oDir2->oxobject2selectlist__oxsort->value);
86  $oDir2->oxobject2selectlist__oxsort->setValue($iCopy);
87 
88  $oDir1->save();
89  $oDir2->save();
90  }
91  }
92 
93  $sQAdd = $this->_getQuery();
94 
95  $sQ = 'select ' . $this->_getQueryCols() . $sQAdd;
96  $sCountQ = 'select count( * ) ' . $sQAdd;
97 
98  $this->_outputResponse( $this->_getData( $sCountQ, $sQ ) );
99  }
100 }