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

Generated on Wed May 13 13:25:50 2009 for OXID eShop CE by  doxygen 1.5.5