00001 <?php
00002
00003 $aColumns = array( 'container1' => array(
00004 array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00005 array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
00006 array( 'oxean', 'oxarticles', 1, 0, 0 ),
00007 array( 'oxmpn', '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', 1, 0, 0 ),
00016 array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
00017 array( 'oxprice', 'oxarticles', 0, 0, 0 ),
00018 array( 'oxstock', 'oxarticles', 0, 0, 0 ),
00019 array( 'oxid', 'oxarticles', 0, 0, 1 )
00020 )
00021 );
00022
00023
00027 class ajaxComponent extends ajaxListComponent
00028 {
00034 protected $_blAllowExtColumns = true;
00035
00041 protected function _getQuery()
00042 {
00043 $myConfig = $this->getConfig();
00044
00045 $sArticleTable = $this->_getViewName('oxarticles');
00046 $sO2CView = $this->_getViewName('oxobject2category');
00047
00048 $sOxid = oxConfig::getParameter( 'oxid' );
00049 $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00050 $oDb = oxDb::getDb();
00051
00052 $sShopID = $myConfig->getShopId();
00053
00054
00055 if ( !$sOxid && $sSynchOxid ) {
00056
00057
00058 $sQAdd = ' from '.$sArticleTable.' where 1 ';
00059 } else {
00060
00061
00062 $sJoin = " {$sArticleTable}.oxid={$sO2CView}.oxobjectid ";
00063
00064 $sSubSelect = '';
00065 if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
00066
00067 $sSubSelect = ' and '.$sArticleTable.'.oxid not in ( ';
00068 $sSubSelect .= "select $sArticleTable.oxid from $sO2CView left join $sArticleTable ";
00069 $sSubSelect .= "on $sJoin where $sO2CView.oxcatnid = " . $oDb->quote( $sSynchOxid ) . " ";
00070 $sSubSelect .= 'and '.$sArticleTable.'.oxid is not null ) ';
00071 }
00072
00073 $sQAdd = " from $sO2CView join $sArticleTable ";
00074 $sQAdd .= " on $sJoin where $sO2CView.oxcatnid = " . $oDb->quote( $sOxid );
00075 $sQAdd .= " and $sArticleTable.oxid is not null $sSubSelect ";
00076 }
00077
00078 return $sQAdd;
00079 }
00080
00088 protected function _addFilter( $sQ )
00089 {
00090 $sArtTable = $this->_getViewName('oxarticles');
00091 $sQ = parent::_addFilter( $sQ );
00092
00093
00094 if ( !$this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00095 $sQ .= " and {$sArtTable}.oxparentid = '' ";
00096 }
00097
00098 return $sQ;
00099 }
00100
00107 public function addarticle()
00108 {
00109 $myConfig = $this->getConfig();
00110
00111 $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00112 $sCategoryID = oxConfig::getParameter( 'synchoxid');
00113 $sShopID = $myConfig->getShopId();
00114 $oDb = oxDb::getDb();
00115 $sArticleTable = $this->_getViewName( 'oxarticles' );
00116
00117
00118 if ( oxConfig::getParameter( 'all' ) ) {
00119 $aArticles = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00120 }
00121
00122 if ( is_array($aArticles)) {
00123
00124
00125 $sO2CView = $this->_getViewName('oxobject2category');
00126
00127 $oNew = oxNew( 'oxbase' );
00128 $oNew->init( 'oxobject2category' );
00129 $myUtilsObject = oxUtilsObject::getInstance();
00130 $oActShop = $myConfig->getActiveShop();
00131
00132 $sProdIds = "";
00133 foreach ( $aArticles as $sAdd) {
00134
00135
00136 $sSelect = "select 1 from $sO2CView as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sCategoryID ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $sAdd ) . "";
00137 if ( $oDb->getOne( $sSelect ) )
00138 continue;
00139
00140 $oNew->oxobject2category__oxid = new oxField( $oNew->setId( $myUtilsObject->generateUID() ) );
00141 $oNew->oxobject2category__oxobjectid = new oxField( $sAdd );
00142 $oNew->oxobject2category__oxcatnid = new oxField( $sCategoryID );
00143 $oNew->oxobject2category__oxtime = new oxField( time() );
00144 $oNew->save();
00145
00146 if ( $sProdIds ) {
00147 $sProdIds .= ",";
00148 }
00149 $sProdIds .= $oDb->quote( $sAdd ) ;
00150 }
00151
00152
00153 $this->_updateOxTime( $sProdIds );
00154
00155 $this->resetArtSeoUrl( $aArticles );
00156 $this->resetCounter( "catArticle", $sCategoryID );
00157 }
00158 }
00159
00167 protected function _updateOxTime( $sProdIds )
00168 {
00169 if ( $sProdIds ) {
00170 $sO2CView = $this->_getViewName('oxobject2category');
00171 $sQ = "update oxobject2category set oxtime = 0 where oxid in (
00172 select _tmp.oxid from (
00173 select oxobject2category.oxid from (
00174 select min(oxtime) as oxtime, oxobjectid from {$sO2CView} where oxobjectid in ( {$sProdIds} ) group by oxobjectid
00175 ) as _subtmp
00176 left join oxobject2category on oxobject2category.oxtime = _subtmp.oxtime and oxobject2category.oxobjectid = _subtmp.oxobjectid
00177 ) as _tmp
00178 )";
00179
00180 oxDb::getDb()->execute( $sQ );
00181 }
00182 }
00183
00189 public function removearticle()
00190 {
00191 $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00192 $sCategoryID = oxConfig::getParameter( 'oxid');
00193 $sShopID = $this->getConfig()->getShopId();
00194 $oDb = oxDb::getDb();
00195
00196
00197 if ( oxConfig::getParameter( 'all' ) ) {
00198 $sArticleTable = $this->_getViewName( 'oxarticles' );
00199 $aArticles = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00200 }
00201
00202
00203 if ( is_array( $aArticles ) && count( $aArticles ) ) {
00204 $sProdIds = implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) );
00205
00206 $sDelete = "delete from oxobject2category where";
00207 $sWhere = " oxcatnid=".$oDb->quote( $sCategoryID );
00208 if ( !$this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00209 $sQ = $sDelete.$sWhere." and oxobjectid in ( select oxid from oxarticles where oxparentid in ( {$sProdIds} ) )";
00210 $oDb->execute( $sQ );
00211 }
00212 $sQ = $sDelete.$sWhere." and oxobjectid in ( {$sProdIds} )";
00213 $oDb->execute( $sQ );
00214
00215
00216
00217 $this->_updateOxTime( $sProdIds );
00218 }
00219
00220 $this->resetArtSeoUrl( $aArticles, $sCategoryID );
00221 $this->resetCounter( "catArticle", $sCategoryID );
00222 }
00223 }