selectlist_order.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(
00004                                         array( 'oxtitle',   'oxselectlist', 1, 1, 0 ),
00005                                         array( 'oxsort',    'oxobject2selectlist', 1, 0, 0 ),
00006                                         array( 'oxident',   'oxselectlist', 0, 0, 0 ),
00007                                         array( 'oxvaldesc', 'oxselectlist', 0, 0, 0 ),
00008                                         array( 'oxid',      'oxobject2selectlist', 0, 0, 1 )
00009                                         )
00010                                     );
00014 class ajaxComponent extends ajaxListComponent
00015 {
00021     protected function _getQuery()
00022     {
00023         $sSelTable = getViewName('oxselectlist');
00024         $sArtId    = oxConfig::getParameter( 'oxid' );
00025 
00026         $sQAdd = " from $sSelTable left join oxobject2selectlist on oxobject2selectlist.oxselnid = $sSelTable.oxid where oxobjectid = '$sArtId' ";
00027 
00028         return $sQAdd;
00029     }
00030 
00036     protected function _getSorting()
00037     {
00038         return 'order by oxobject2selectlist.oxsort ';
00039     }
00040 
00046     public function setSorting()
00047     {
00048         $sSelId  = oxConfig::getParameter( 'oxid' );
00049         $sSelect = "select * from oxobject2selectlist where oxobjectid='$sSelId' order by oxsort";
00050 
00051         $oList = oxNew( "oxlist" );
00052         $oList->init( "oxbase", "oxobject2selectlist" );
00053         $oList->selectString( $sSelect );
00054 
00055         // fixing indexes
00056         $iSelCnt = 0;
00057         $aIdx2Id = array();
00058         foreach ( $oList as $sKey => $oSel ) {
00059 
00060             if ( $oSel->oxobject2selectlist__oxsort->value != $iSelCnt ) {
00061                 $oSel->oxobject2selectlist__oxsort->setValue($iSelCnt);
00062 
00063                 // saving new index
00064                 $oSel->save();
00065             }
00066             $aIdx2Id[$iSelCnt] = $sKey;
00067             $iSelCnt++;
00068         }
00069 
00070         //
00071         if ( ( $iKey = array_search( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
00072             $iDir = (oxConfig::getParameter( 'direction' ) == 'up')?($iKey-1):($iKey+1);
00073             if ( isset( $aIdx2Id[$iDir] ) ) {
00074                 // exchanging indexes
00075                 $oDir1 = $oList->offsetGet( $aIdx2Id[$iDir] );
00076                 $oDir2 = $oList->offsetGet( $aIdx2Id[$iKey] );
00077 
00078                 $iCopy = $oDir1->oxobject2selectlist__oxsort->value;
00079                 $oDir1->oxobject2selectlist__oxsort->setValue($oDir2->oxobject2selectlist__oxsort->value);
00080                 $oDir2->oxobject2selectlist__oxsort->setValue($iCopy);
00081 
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 }