00001 <?php
00002
00006 class category_order_ajax extends ajaxListComponent
00007 {
00013 protected $_aColumns = array( 'container1' => array(
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
00042 $sArtTable = $this->_getViewName( 'oxarticles' );
00043 $sO2CView = $this->_getViewName( 'oxobject2category' );
00044 $oDb = oxDb::getDb();
00045
00046
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
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
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
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
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
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
00154 echo (int) oxDb::getDb()->getOne( $sSelect, false, false );
00155 }
00156 }
00157
00163 public function saveNewOrder()
00164 {
00165 $oCategory = oxNew( "oxcategory" );
00166 if ( $oCategory->load( oxConfig::getParameter( "oxid" ) ) ) {
00167
00168
00169 $aNewOrder = oxSession::getVar( "neworder_sess" );
00170 if ( is_array( $aNewOrder ) && count( $aNewOrder ) ) {
00171 $sO2CView = $this->_getViewName('oxobject2category');
00172 $sSelect = "select * from $sO2CView where $sO2CView.oxcatnid='".$oCategory->getId()."' and $sO2CView.oxobjectid in (".implode( ", ", oxDb::getInstance()->quoteArray( $aNewOrder ) )." )";
00173 $oList = oxNew( "oxlist" );
00174 $oList->init( "oxbase", "oxobject2category" );
00175 $oList->selectString( $sSelect );
00176
00177
00178 foreach ( $oList as $oObj ) {
00179 if ( ( $iNewPos = array_search( $oObj->oxobject2category__oxobjectid->value, $aNewOrder ) ) !== false ) {
00180 $oObj->oxobject2category__oxpos->setValue($iNewPos);
00181 $oObj->save();
00182 }
00183 }
00184
00185 oxSession::setVar( 'neworder_sess', null );
00186 }
00187 }
00188 }
00189
00195 public function remNewOrder()
00196 {
00197 $oCategory = oxNew( "oxcategory" );
00198 if ( $oCategory->load( oxConfig::getParameter( "oxid" ) ) ) {
00199
00200
00201 $oDb = oxDb::getDb();
00202 $sSelect = "update oxobject2category set oxpos = '0' where oxobject2category.oxcatnid=" . $oDb->quote( $oCategory->getId() );
00203 $oDb->execute( $sSelect );
00204
00205 oxSession::setVar( 'neworder_sess', null );
00206 }
00207 }
00208 }