selectlist_order_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class selectlist_order_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_aColumns = array('container1' => array(
00015         array('oxtitle', 'oxselectlist', 1, 1, 0),
00016         array('oxsort', 'oxobject2selectlist', 1, 0, 0),
00017         array('oxident', 'oxselectlist', 0, 0, 0),
00018         array('oxvaldesc', 'oxselectlist', 0, 0, 0),
00019         array('oxid', 'oxobject2selectlist', 0, 0, 1)
00020     )
00021     );
00022 
00028     protected function _getQuery()
00029     {
00030         $sSelTable = $this->_getViewName('oxselectlist');
00031         $sArtId = oxRegistry::getConfig()->getRequestParameter('oxid');
00032 
00033         $sQAdd = " from $sSelTable left join oxobject2selectlist on oxobject2selectlist.oxselnid = $sSelTable.oxid " .
00034                  "where oxobjectid = '$sArtId' ";
00035 
00036         return $sQAdd;
00037     }
00038 
00044     protected function _getSorting()
00045     {
00046         return 'order by oxobject2selectlist.oxsort ';
00047     }
00048 
00052     public function setSorting()
00053     {
00054         $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
00055         $sSelect = "select * from oxobject2selectlist where oxobjectid='$sSelId' order by oxsort";
00056 
00057         $oList = oxNew("oxlist");
00058         $oList->init("oxbase", "oxobject2selectlist");
00059         $oList->selectString($sSelect);
00060 
00061         // fixing indexes
00062         $iSelCnt = 0;
00063         $aIdx2Id = array();
00064         foreach ($oList as $sKey => $oSel) {
00065 
00066             if ($oSel->oxobject2selectlist__oxsort->value != $iSelCnt) {
00067                 $oSel->oxobject2selectlist__oxsort->setValue($iSelCnt);
00068 
00069                 // saving new index
00070                 $oSel->save();
00071             }
00072             $aIdx2Id[$iSelCnt] = $sKey;
00073             $iSelCnt++;
00074         }
00075 
00076         //
00077         if (($iKey = array_search(oxRegistry::getConfig()->getRequestParameter('sortoxid'), $aIdx2Id)) !== false) {
00078             $iDir = (oxRegistry::getConfig()->getRequestParameter('direction') == 'up') ? ($iKey - 1) : ($iKey + 1);
00079             if (isset($aIdx2Id[$iDir])) {
00080                 // exchanging indexes
00081                 $oDir1 = $oList->offsetGet($aIdx2Id[$iDir]);
00082                 $oDir2 = $oList->offsetGet($aIdx2Id[$iKey]);
00083 
00084                 $iCopy = $oDir1->oxobject2selectlist__oxsort->value;
00085                 $oDir1->oxobject2selectlist__oxsort->setValue($oDir2->oxobject2selectlist__oxsort->value);
00086                 $oDir2->oxobject2selectlist__oxsort->setValue($iCopy);
00087 
00088                 $oDir1->save();
00089                 $oDir2->save();
00090             }
00091         }
00092 
00093         $sQAdd = $this->_getQuery();
00094 
00095         $sQ = 'select ' . $this->_getQueryCols() . $sQAdd;
00096         $sCountQ = 'select count( * ) ' . $sQAdd;
00097 
00098         $this->_outputResponse($this->_getData($sCountQ, $sQ));
00099     }
00100 }