00001 <?php
00002
00006 class category_main_ajax extends ajaxListComponent
00007 {
00013 protected $_blAllowExtColumns = true;
00014
00020 protected $_aColumns = array( 'container1' => array(
00021 array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00022 array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
00023 array( 'oxean', 'oxarticles', 1, 0, 0 ),
00024 array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
00025 array( 'oxprice', 'oxarticles', 0, 0, 0 ),
00026 array( 'oxstock', 'oxarticles', 0, 0, 0 ),
00027 array( 'oxid', 'oxarticles', 0, 0, 1 )
00028 ),
00029 'container2' => array(
00030 array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00031 array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
00032 array( 'oxean', 'oxarticles', 1, 0, 0 ),
00033 array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
00034 array( 'oxprice', 'oxarticles', 0, 0, 0 ),
00035 array( 'oxstock', 'oxarticles', 0, 0, 0 ),
00036 array( 'oxid', 'oxarticles', 0, 0, 1 )
00037 )
00038 );
00039
00045 protected function _getQuery()
00046 {
00047 $myConfig = $this->getConfig();
00048
00049 $sArticleTable = $this->_getViewName('oxarticles');
00050 $sO2CView = $this->_getViewName('oxobject2category');
00051
00052 $sOxid = oxConfig::getParameter( 'oxid' );
00053 $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00054 $oDb = oxDb::getDb();
00055
00056 $sShopID = $myConfig->getShopId();
00057
00058
00059 if ( !$sOxid && $sSynchOxid ) {
00060
00061
00062 $sQAdd = ' from '.$sArticleTable.' where 1 ';
00063 } else {
00064
00065
00066 $sJoin = " {$sArticleTable}.oxid={$sO2CView}.oxobjectid ";
00067
00068 $sSubSelect = '';
00069 if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
00070
00071 $sSubSelect = ' and '.$sArticleTable.'.oxid not in ( ';
00072 $sSubSelect .= "select $sArticleTable.oxid from $sO2CView left join $sArticleTable ";
00073 $sSubSelect .= "on $sJoin where $sO2CView.oxcatnid = " . $oDb->quote( $sSynchOxid ) . " ";
00074 $sSubSelect .= 'and '.$sArticleTable.'.oxid is not null ) ';
00075 }
00076
00077 $sQAdd = " from $sO2CView join $sArticleTable ";
00078 $sQAdd .= " on $sJoin where $sO2CView.oxcatnid = " . $oDb->quote( $sOxid );
00079 $sQAdd .= " and $sArticleTable.oxid is not null $sSubSelect ";
00080 }
00081
00082 return $sQAdd;
00083 }
00084
00092 protected function _addFilter( $sQ )
00093 {
00094 $sArtTable = $this->_getViewName('oxarticles');
00095 $sQ = parent::_addFilter( $sQ );
00096
00097
00098 if ( !$this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00099 $sQ .= " and {$sArtTable}.oxparentid = '' ";
00100 }
00101
00102 return $sQ;
00103 }
00104
00111 public function addArticle()
00112 {
00113 $myConfig = $this->getConfig();
00114
00115 $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00116 $sCategoryID = oxConfig::getParameter( 'synchoxid');
00117 $sShopID = $myConfig->getShopId();
00118 $oDb = oxDb::getDb();
00119 $sArticleTable = $this->_getViewName( 'oxarticles' );
00120
00121
00122 if ( oxConfig::getParameter( 'all' ) ) {
00123 $aArticles = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00124 }
00125
00126 if ( is_array($aArticles)) {
00127
00128
00129 $sO2CView = $this->_getViewName('oxobject2category');
00130
00131 $oNew = oxNew( 'oxbase' );
00132 $oNew->init( 'oxobject2category' );
00133 $myUtilsObject = oxUtilsObject::getInstance();
00134 $oActShop = $myConfig->getActiveShop();
00135
00136 $sProdIds = "";
00137 foreach ( $aArticles as $sAdd) {
00138
00139
00140 $sSelect = "select 1 from $sO2CView as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sCategoryID ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $sAdd ) . "";
00141 if ( $oDb->getOne( $sSelect, false, false ) )
00142 continue;
00143
00144 $oNew->oxobject2category__oxid = new oxField( $oNew->setId( $myUtilsObject->generateUID() ) );
00145 $oNew->oxobject2category__oxobjectid = new oxField( $sAdd );
00146 $oNew->oxobject2category__oxcatnid = new oxField( $sCategoryID );
00147 $oNew->oxobject2category__oxtime = new oxField( time() );
00148
00149 $oNew->save();
00150
00151 if ( $sProdIds ) {
00152 $sProdIds .= ",";
00153 }
00154 $sProdIds .= $oDb->quote( $sAdd ) ;
00155 }
00156
00157
00158 $this->_updateOxTime( $sProdIds );
00159
00160 $this->resetArtSeoUrl( $aArticles );
00161 $this->resetCounter( "catArticle", $sCategoryID );
00162
00163
00164 }
00165 }
00166
00174 protected function _updateOxTime( $sProdIds )
00175 {
00176 if ( $sProdIds ) {
00177 $sO2CView = $this->_getViewName('oxobject2category');
00178 $sQ = "update oxobject2category set oxtime = 0 where oxid in (
00179 select _tmp.oxid from (
00180 select oxobject2category.oxid from (
00181 select min(oxtime) as oxtime, oxobjectid from {$sO2CView} where oxobjectid in ( {$sProdIds} ) group by oxobjectid
00182 ) as _subtmp
00183 left join oxobject2category on oxobject2category.oxtime = _subtmp.oxtime and oxobject2category.oxobjectid = _subtmp.oxobjectid
00184 ) as _tmp
00185 )";
00186
00187 oxDb::getDb()->execute( $sQ );
00188 }
00189 }
00190
00196 public function removeArticle()
00197 {
00198 $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00199 $sCategoryID = oxConfig::getParameter( 'oxid');
00200 $sShopID = $this->getConfig()->getShopId();
00201 $oDb = oxDb::getDb();
00202
00203
00204 if ( oxConfig::getParameter( 'all' ) ) {
00205 $sArticleTable = $this->_getViewName( 'oxarticles' );
00206 $aArticles = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00207 }
00208
00209
00210 if ( is_array( $aArticles ) && count( $aArticles ) ) {
00211 $sProdIds = implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) );
00212
00213 $sDelete = "delete from oxobject2category where";
00214 $sWhere = " oxcatnid=".$oDb->quote( $sCategoryID );
00215 if ( !$this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00216 $sQ = $sDelete.$sWhere." and oxobjectid in ( select oxid from oxarticles where oxparentid in ( {$sProdIds} ) )";
00217 $oDb->execute( $sQ );
00218 }
00219 $sQ = $sDelete.$sWhere." and oxobjectid in ( {$sProdIds} )";
00220 $oDb->execute( $sQ );
00221
00222
00223
00224 $this->_updateOxTime( $sProdIds );
00225 }
00226
00227 $this->resetArtSeoUrl( $aArticles, $sCategoryID );
00228 $this->resetCounter( "catArticle", $sCategoryID );
00229
00230 }
00231 }