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