attribute_order.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(
00004                                         array( 'oxtitle', 'oxattribute', 1, 1, 0 ),
00005                                         array( 'oxsort',  'oxcategory2attribute', 1, 0, 0 ),
00006                                         array( 'oxid',    'oxcategory2attribute', 0, 0, 1 )
00007                                         )
00008                                     );
00012 class ajaxComponent extends ajaxListComponent
00013 {
00019     protected function _getQuery()
00020     {
00021         $sSelTable = getViewName('oxattribute');
00022         $sArtId    = oxConfig::getParameter( 'oxid' );
00023 
00024         $sQAdd = " from $sSelTable left join oxcategory2attribute on oxcategory2attribute.oxattrid = $sSelTable.oxid where oxobjectid = '$sArtId' ";
00025 
00026         return $sQAdd;
00027     }
00028 
00034     protected function _getSorting()
00035     {
00036         return 'order by oxcategory2attribute.oxsort ';
00037     }
00038 
00044     public function setSorting()
00045     {
00046         $sSelId  = oxConfig::getParameter( 'oxid' );
00047         $sSelect = "select * from oxcategory2attribute where oxobjectid='$sSelId' order by oxsort";
00048 
00049         $oList = oxNew( "oxlist" );
00050         $oList->init( "oxbase", "oxcategory2attribute" );
00051         $oList->selectString( $sSelect );
00052 
00053         // fixing indexes
00054         $iSelCnt = 0;
00055         $aIdx2Id = array();
00056         foreach ( $oList as $sKey => $oSel ) {
00057 
00058             if ( $oSel->oxcategory2attribute__oxsort->value != $iSelCnt ) {
00059                 $oSel->oxcategory2attribute__oxsort->setValue($iSelCnt);
00060 
00061                 // saving new index
00062                 $oSel->save();
00063             }
00064             $aIdx2Id[$iSelCnt] = $sKey;
00065             $iSelCnt++;
00066         }
00067 
00068         //
00069         if ( ( $iKey = array_search( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
00070             $iDir = (oxConfig::getParameter( 'direction' ) == 'up')?($iKey-1):($iKey+1);
00071             if ( isset( $aIdx2Id[$iDir] ) ) {
00072                 // exchanging indexes
00073                 $oDir1 = $oList->offsetGet( $aIdx2Id[$iDir] );
00074                 $oDir2 = $oList->offsetGet( $aIdx2Id[$iKey] );
00075 
00076                 $iCopy = $oDir1->oxcategory2attribute__oxsort->value;
00077                 $oDir1->oxcategory2attribute__oxsort->setValue($oDir2->oxcategory2attribute__oxsort->value);
00078                 $oDir2->oxcategory2attribute__oxsort->setValue($iCopy);
00079 
00080                 $oDir1->save();
00081                 $oDir2->save();
00082             }
00083         }
00084 
00085         $sQAdd = $this->_getQuery();
00086 
00087         $sQ      = 'select ' . $this->_getQueryCols() . $sQAdd;
00088         $sCountQ = 'select count( * ) ' . $sQAdd;
00089 
00090         $this->_outputResponse( $this->_getData( $sCountQ, $sQ ) );
00091     }
00092 }

Generated on Wed Apr 22 12:26:29 2009 for OXID eShop CE by  doxygen 1.5.5