actions_order_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class actions_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 = " . oxDb::getDb()->quote($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         $sQuotedSelectionId = oxDb::getDb()->quote($sSelId);
00056         $sSelect = "select * from oxobject2selectlist where oxobjectid= {$sQuotedSelectionId} order by oxsort";
00057 
00058         $oList = oxNew("oxlist");
00059         $oList->init("oxbase", "oxobject2selectlist");
00060         $oList->selectString($sSelect);
00061 
00062         // fixing indexes
00063         $iSelCnt = 0;
00064         $aIdx2Id = array();
00065         foreach ($oList as $sKey => $oSel) {
00066 
00067             if ($oSel->oxobject2selectlist__oxsort->value != $iSelCnt) {
00068                 $oSel->oxobject2selectlist__oxsort->setValue($iSelCnt);
00069 
00070                 // saving new index
00071                 $oSel->save();
00072             }
00073             $aIdx2Id[$iSelCnt] = $sKey;
00074             $iSelCnt++;
00075         }
00076 
00077         //
00078         if (($iKey = array_search(oxRegistry::getConfig()->getRequestParameter('sortoxid'), $aIdx2Id)) !== false) {
00079             $iDir = (oxRegistry::getConfig()->getRequestParameter('direction') == 'up') ? ($iKey - 1) : ($iKey + 1);
00080             if (isset($aIdx2Id[$iDir])) {
00081                 // exchanging indexes
00082                 $oDir1 = $oList->offsetGet($aIdx2Id[$iDir]);
00083                 $oDir2 = $oList->offsetGet($aIdx2Id[$iKey]);
00084 
00085                 $iCopy = $oDir1->oxobject2selectlist__oxsort->value;
00086                 $oDir1->oxobject2selectlist__oxsort->setValue($oDir2->oxobject2selectlist__oxsort->value);
00087                 $oDir2->oxobject2selectlist__oxsort->setValue($iCopy);
00088 
00089                 $oDir1->save();
00090                 $oDir2->save();
00091             }
00092         }
00093 
00094         $sQAdd = $this->_getQuery();
00095 
00096         $sQ = 'select ' . $this->_getQueryCols() . $sQAdd;
00097         $sCountQ = 'select count( * ) ' . $sQAdd;
00098 
00099         $this->_outputResponse($this->_getData($sCountQ, $sQ));
00100 
00101     }
00102 }