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