category_order_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class category_order_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00014                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00015                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00016                                         array( 'oxpos',    'oxobject2category', 1, 0, 0 ),
00017                                         array( 'oxean',    'oxarticles', 0, 0, 0 ),
00018                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00019                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00020                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00021                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00022                                         ),
00023                                 'container2' => array(
00024                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00025                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00026                                         array( 'oxean',    'oxarticles', 0, 0, 0 ),
00027                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00028                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00029                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00030                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00031                                         )
00032                                 );
00033 
00039     protected function _getQuery()
00040     {
00041         // looking for table/view
00042         $sArtTable = $this->_getViewName( 'oxarticles' );
00043         $sO2CView  = $this->_getViewName( 'oxobject2category' );
00044         $oDb = oxDb::getDb();
00045 
00046         // category selected or not ?
00047         if ( $sSynchOxid  = oxConfig::getParameter( 'synchoxid' ) ) {
00048             $sQAdd  = " from $sArtTable left join $sO2CView on $sArtTable.oxid=$sO2CView.oxobjectid where $sO2CView.oxcatnid = ".$oDb->quote( $sSynchOxid );
00049             if ( $aSkipArt = oxSession::getVar( 'neworder_sess' ) ) {
00050                 $sQAdd .= " and $sArtTable.oxid not in ( ".implode( ", ", oxDb::getInstance()->quoteArray( $aSkipArt ) )." ) ";
00051             }
00052         } else {
00053             // which fields to load ?
00054             $sQAdd  = " from $sArtTable where ";
00055             if ( $aSkipArt = oxSession::getVar( 'neworder_sess') ) {
00056                 $sQAdd .= " $sArtTable.oxid in ( ".implode( ", ", oxDb::getInstance()->quoteArray( $aSkipArt ) )." ) ";
00057             } else {
00058                 $sQAdd .= " 1 = 0 ";
00059             }
00060         }
00061 
00062         return $sQAdd;
00063     }
00064 
00070     protected function _getSorting()
00071     {
00072         $sOrder = '';
00073         if ( oxConfig::getParameter( 'synchoxid' ) ) {
00074             $sOrder = parent::_getSorting();
00075         } elseif ( ( $aSkipArt = oxSession::getVar( 'neworder_sess' ) ) ) {
00076             $sOrderBy  = '';
00077             $sArtTable = $this->_getViewName( 'oxarticles' );
00078             $sSep = '';
00079             foreach ( $aSkipArt as $sId ) {
00080                 $sOrderBy = " $sArtTable.oxid=" . oxDb::getDb()->quote( $sId ) . " ".$sSep.$sOrderBy;
00081                 $sSep = ", ";
00082             }
00083             $sOrder = "order by ".$sOrderBy;
00084         }
00085 
00086         return $sOrder;
00087     }
00088 
00094     public function removeCatOrderArticle()
00095     {
00096         $aRemoveArt = $this->_getActionIds( 'oxarticles.oxid' );
00097         $soxId      = oxConfig::getParameter( 'oxid' );
00098         $aSkipArt   = oxSession::getVar( 'neworder_sess' );
00099 
00100         if ( is_array( $aRemoveArt ) && is_array( $aSkipArt  ) ) {
00101             foreach ( $aRemoveArt as $sRem ) {
00102                 if ( ( $iKey = array_search( $sRem, $aSkipArt ) ) !== false ) {
00103                     unset( $aSkipArt[$iKey] );
00104                 }
00105             }
00106             oxSession::setVar( 'neworder_sess', $aSkipArt );
00107 
00108             $sArticleTable = $this->_getViewName('oxarticles');
00109             $sO2CView      = $this->_getViewName('oxobject2category');
00110 
00111             // checking if all articles were moved from one
00112             $sSelect  = "select 1 from $sArticleTable left join $sO2CView on $sArticleTable.oxid=$sO2CView.oxobjectid ";
00113             $sSelect .= "where $sO2CView.oxcatnid = '$soxId' and $sArticleTable.oxparentid = '' and $sArticleTable.oxid ";
00114             $sSelect .= "not in ( ".implode( ", ", oxDb::getInstance()->quoteArray( $aSkipArt ) )." ) ";
00115 
00116             // simply echoing "1" if some items found, and 0 if nothing was found
00117             echo (int) oxDb::getDb()->getOne( $sSelect, false, false );
00118         }
00119     }
00120 
00126     public function addCatOrderArticle()
00127     {
00128         $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00129         $soxId       = oxConfig::getParameter( 'synchoxid' );
00130 
00131         $aOrdArt = oxSession::getVar( 'neworder_sess' );
00132         if ( !is_array( $aOrdArt ) )
00133             $aOrdArt = array();
00134 
00135         $blEnable    = false;
00136 
00137         if ( is_array( $aAddArticle ) ) {
00138             // storing newly ordered article seq.
00139             foreach ($aAddArticle as $sAdd) {
00140                 if ( array_search( $sAdd, $aOrdArt ) === false )
00141                     $aOrdArt[] = $sAdd;
00142             }
00143             oxSession::setVar( 'neworder_sess', $aOrdArt );
00144 
00145             $sArticleTable = $this->_getViewName('oxarticles');
00146             $sO2CView      = $this->_getViewName('oxobject2category');
00147 
00148             // checking if all articles were moved from one
00149             $sSelect  = "select 1 from $sArticleTable left join $sO2CView on $sArticleTable.oxid=$sO2CView.oxobjectid ";
00150             $sSelect .= "where $sO2CView.oxcatnid = '$soxId' and $sArticleTable.oxparentid = '' and $sArticleTable.oxid ";
00151             $sSelect .= "not in ( ".implode( ", ", oxDb::getInstance()->quoteArray( $aOrdArt ) )." ) ";
00152 
00153             // simply echoing "1" if some items found, and 0 if nothing was found
00154             echo (int) oxDb::getDb()->getOne( $sSelect, false, false );
00155         }
00156     }
00157 
00163     public function saveNewOrder()
00164     {
00165         $oCategory = oxNew( "oxcategory" );
00166         $sId = oxConfig::getParameter( "oxid" );
00167         if ( $oCategory->load( $sId ) ) {
00168 
00169 
00170             $aNewOrder = oxSession::getVar( "neworder_sess" );
00171             if ( is_array( $aNewOrder ) && count( $aNewOrder ) ) {
00172                 $sO2CView = $this->_getViewName('oxobject2category');
00173                 $sSelect =  "select * from $sO2CView where $sO2CView.oxcatnid='".$oCategory->getId()."' and $sO2CView.oxobjectid in (".implode( ", ", oxDb::getInstance()->quoteArray( $aNewOrder ) )." )";
00174                 $oList = oxNew( "oxlist" );
00175                 $oList->init( "oxbase", "oxobject2category" );
00176                 $oList->selectString( $sSelect );
00177 
00178                 // setting new position
00179                 foreach ( $oList as $oObj ) {
00180                     if ( ( $iNewPos = array_search( $oObj->oxobject2category__oxobjectid->value, $aNewOrder ) ) !== false ) {
00181                         $oObj->oxobject2category__oxpos->setValue($iNewPos);
00182                         $oObj->save();
00183                     }
00184                 }
00185 
00186                 oxSession::setVar( 'neworder_sess', null );
00187             }
00188 
00189 
00190         }
00191     }
00192 
00198     public function remNewOrder()
00199     {
00200         $oCategory = oxNew( "oxcategory" );
00201         $sId = oxConfig::getParameter( "oxid" );
00202         if ( $oCategory->load( $sId ) ) {
00203 
00204 
00205             $oDb = oxDb::getDb();
00206             $sSelect = "update oxobject2category set oxpos = '0' where oxobject2category.oxcatnid=" . $oDb->quote( $oCategory->getId() );
00207             $oDb->execute( $sSelect );
00208 
00209             oxSession::setVar( 'neworder_sess', null );
00210 
00211         }
00212     }
00213 }