OXID eShop CE  4.9.8
 All Classes Files Functions Variables Pages
attribute_order_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_aColumns = array('container1' => array(
15  array('oxtitle', 'oxattribute', 1, 1, 0),
16  array('oxsort', 'oxcategory2attribute', 1, 0, 0),
17  array('oxid', 'oxcategory2attribute', 0, 0, 1)
18  )
19  );
20 
26  protected function _getQuery()
27  {
28  $sSelTable = $this->_getViewName('oxattribute');
29  $sArtId = oxRegistry::getConfig()->getRequestParameter('oxid');
30 
31  $sQAdd = " from $sSelTable left join oxcategory2attribute on oxcategory2attribute.oxattrid = $sSelTable.oxid " .
32  "where oxobjectid = " . oxDb::getDb()->quote($sArtId) . " ";
33 
34  return $sQAdd;
35  }
36 
42  protected function _getSorting()
43  {
44  return 'order by oxcategory2attribute.oxsort ';
45  }
46 
50  public function setSorting()
51  {
52  $sSelId = oxRegistry::getConfig()->getRequestParameter('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(oxRegistry::getConfig()->getRequestParameter('sortoxid'), $aIdx2Id)) !== false) {
73  $iDir = (oxRegistry::getConfig()->getRequestParameter('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 }