category_order.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00004                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00005                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00006                                         array( 'oxpos',    'oxobject2category', 1, 0, 0 ),
00007                                         array( 'oxean',    'oxarticles', 0, 0, 0 ),
00008                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00009                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00010                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00011                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00012                                         ),
00013                      'container2' => array(
00014                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00015                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00016                                         array( 'oxean',    'oxarticles', 0, 0, 0 ),
00017                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00018                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00019                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00020                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00021                                         )
00022                     );
00023 
00027 class ajaxComponent extends ajaxListComponent
00028 {
00034     protected function _getQuery()
00035     {
00036         // looking for table/view
00037         $sArtTable = $this->_getViewName( 'oxarticles' );
00038         $sO2CView  = $this->_getViewName( 'oxobject2category' );
00039         $oDb = oxDb::getDb();
00040 
00041         // category selected or not ?
00042         if ( $sSynchOxid  = oxConfig::getParameter( 'synchoxid' ) ) {
00043             $sQAdd  = " from $sArtTable left join $sO2CView on $sArtTable.oxid=$sO2CView.oxobjectid where $sO2CView.oxcatnid = ".$oDb->quote( $sSynchOxid );
00044             if ( $aSkipArt = oxSession::getVar( 'neworder_sess' ) ) {
00045                 $sQAdd .= " and $sArtTable.oxid not in ( ".implode( ", ", oxDb::getInstance()->quoteArray( $aSkipArt ) )." ) ";
00046             }
00047         } else {
00048             // which fields to load ?
00049             $sQAdd  = " from $sArtTable where ";
00050             if ( $aSkipArt = oxSession::getVar( 'neworder_sess') ) {
00051                 $sQAdd .= " $sArtTable.oxid in ( ".implode( ", ", oxDb::getInstance()->quoteArray( $aSkipArt ) )." ) ";
00052             } else {
00053                 $sQAdd .= " 1 = 0 ";
00054             }
00055         }
00056 
00057         return $sQAdd;
00058     }
00059 
00065     protected function _getSorting()
00066     {
00067         $sOrder = '';
00068         if ( oxConfig::getParameter( 'synchoxid' ) ) {
00069             $sOrder = parent::_getSorting();
00070         } elseif ( ( $aSkipArt = oxSession::getVar( 'neworder_sess' ) ) ) {
00071             $sOrderBy  = '';
00072             $sArtTable = $this->_getViewName( 'oxarticles' );
00073             $sSep = '';
00074             foreach ( $aSkipArt as $sId ) {
00075                 $sOrderBy = " $sArtTable.oxid=" . oxDb::getDb()->quote( $sId ) . " ".$sSep.$sOrderBy;
00076                 $sSep = ", ";
00077             }
00078             $sOrder = "order by ".$sOrderBy;
00079         }
00080 
00081         return $sOrder;
00082     }
00083 
00089     public function removecatorderarticle()
00090     {
00091         $aRemoveArt = $this->_getActionIds( 'oxarticles.oxid' );
00092         $soxId      = oxConfig::getParameter( 'oxid' );
00093         $aSkipArt   = oxSession::getVar( 'neworder_sess' );
00094 
00095         if ( is_array( $aRemoveArt ) && is_array( $aSkipArt  ) ) {
00096             foreach ( $aRemoveArt as $sRem ) {
00097                 if ( ( $iKey = array_search( $sRem, $aSkipArt ) ) !== false ) {
00098                     unset( $aSkipArt[$iKey] );
00099                 }
00100             }
00101             oxSession::setVar( 'neworder_sess', $aSkipArt );
00102 
00103             $sArticleTable = $this->_getViewName('oxarticles');
00104             $sO2CView      = $this->_getViewName('oxobject2category');
00105 
00106             // checking if all articles were moved from one
00107             $sSelect  = "select 1 from $sArticleTable left join $sO2CView on $sArticleTable.oxid=$sO2CView.oxobjectid ";
00108             $sSelect .= "where $sO2CView.oxcatnid = '$soxId' and $sArticleTable.oxparentid = '' and $sArticleTable.oxid ";
00109             $sSelect .= "not in ( ".implode( ", ", oxDb::getInstance()->quoteArray( $aSkipArt ) )." ) ";
00110 
00111             // simply echoing "1" if some items found, and 0 if nothing was found
00112             echo (int) oxDb::getDb()->getOne( $sSelect );
00113         }
00114     }
00115 
00121     public function addcatorderarticle()
00122     {
00123         $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00124         $soxId       = oxConfig::getParameter( 'synchoxid' );
00125 
00126         $aOrdArt = oxSession::getVar( 'neworder_sess' );
00127         if ( !is_array( $aOrdArt ) )
00128             $aOrdArt = array();
00129 
00130         $blEnable    = false;
00131 
00132         if ( is_array( $aAddArticle ) ) {
00133             // storing newly ordered article seq.
00134             foreach ($aAddArticle as $sAdd) {
00135                 if ( array_search( $sAdd, $aOrdArt ) === false )
00136                     $aOrdArt[] = $sAdd;
00137             }
00138             oxSession::setVar( 'neworder_sess', $aOrdArt );
00139 
00140             $sArticleTable = $this->_getViewName('oxarticles');
00141             $sO2CView      = $this->_getViewName('oxobject2category');
00142 
00143             // checking if all articles were moved from one
00144             $sSelect  = "select 1 from $sArticleTable left join $sO2CView on $sArticleTable.oxid=$sO2CView.oxobjectid ";
00145             $sSelect .= "where $sO2CView.oxcatnid = '$soxId' and $sArticleTable.oxparentid = '' and $sArticleTable.oxid ";
00146             $sSelect .= "not in ( ".implode( ", ", oxDb::getInstance()->quoteArray( $aOrdArt ) )." ) ";
00147 
00148             // simply echoing "1" if some items found, and 0 if nothing was found
00149             echo (int) oxDb::getDb()->getOne( $sSelect );
00150         }
00151     }
00152 
00158     public function saveneworder()
00159     {
00160         $oCategory = oxNew( "oxcategory" );
00161         if ( $oCategory->load( oxConfig::getParameter( "oxid" ) ) ) {
00162 
00163 
00164             $aNewOrder = oxSession::getVar( "neworder_sess" );
00165             if ( is_array( $aNewOrder ) && count( $aNewOrder ) ) {
00166                 $sO2CView = $this->_getViewName('oxobject2category');
00167                 $sSelect =  "select * from $sO2CView where $sO2CView.oxcatnid='".$oCategory->getId()."' and $sO2CView.oxobjectid in (".implode( ", ", oxDb::getInstance()->quoteArray( $aNewOrder ) )." )";
00168                 $oList = oxNew( "oxlist" );
00169                 $oList->init( "oxbase", "oxobject2category" );
00170                 $oList->selectString( $sSelect );
00171 
00172                 // setting new position
00173                 foreach ( $oList as $oObj ) {
00174                     if ( ( $iNewPos = array_search( $oObj->oxobject2category__oxobjectid->value, $aNewOrder ) ) !== false ) {
00175                         $oObj->oxobject2category__oxpos->setValue($iNewPos);
00176                         $oObj->save();
00177                     }
00178                 }
00179 
00180                 oxSession::setVar( 'neworder_sess', null );
00181             }
00182         }
00183     }
00184 
00190     public function remneworder()
00191     {
00192         $oCategory = oxNew( "oxcategory" );
00193         if ( $oCategory->load( oxConfig::getParameter( "oxid" ) ) ) {
00194 
00195 
00196             $oDb = oxDb::getDb();
00197             $sSelect = "update oxobject2category set oxpos = '0' where oxobject2category.oxcatnid=" . $oDb->quote( $oCategory->getId() );
00198             $oDb->execute( $sSelect );
00199 
00200             oxSession::setVar( 'neworder_sess', null );
00201         }
00202     }
00203 }