attribute_order_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class attribute_order_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(
00014                                         array( 'oxtitle', 'oxattribute', 1, 1, 0 ),
00015                                         array( 'oxsort',  'oxcategory2attribute', 1, 0, 0 ),
00016                                         array( 'oxid',    'oxcategory2attribute', 0, 0, 1 )
00017                                         )
00018                                     );
00019 
00025     protected function _getQuery()
00026     {
00027         $sSelTable = $this->_getViewName('oxattribute');
00028         $sArtId    = oxConfig::getParameter( 'oxid' );
00029 
00030         $sQAdd = " from $sSelTable left join oxcategory2attribute on oxcategory2attribute.oxattrid = $sSelTable.oxid where oxobjectid = " . oxDb::getDb()->quote( $sArtId ) . " ";
00031 
00032         return $sQAdd;
00033     }
00034 
00040     protected function _getSorting()
00041     {
00042         return 'order by oxcategory2attribute.oxsort ';
00043     }
00044 
00050     public function setSorting()
00051     {
00052         $sSelId  = oxConfig::getParameter( '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( oxConfig::getParameter( 'sortoxid' ), $aIdx2Id ) ) !== false ) {
00073             $iDir = (oxConfig::getParameter( '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 }