attribute_order_ajax.php

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