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, false, false ) )
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
00145 $oNew->save();
00146
00147 if ( $sProdIds ) {
00148 $sProdIds .= ",";
00149 }
00150 $sProdIds .= $oDb->quote( $sAdd ) ;
00151 }
00152
00153
00154 $this->_updateOxTime( $sProdIds );
00155
00156 $this->resetArtSeoUrl( $aArticles );
00157 $this->resetCounter( "catArticle", $sCategoryID );
00158 }
00159 }
00160
00168 protected function _updateOxTime( $sProdIds )
00169 {
00170 if ( $sProdIds ) {
00171 $sO2CView = $this->_getViewName('oxobject2category');
00172 $sQ = "update oxobject2category set oxtime = 0 where oxid in (
00173 select _tmp.oxid from (
00174 select oxobject2category.oxid from (
00175 select min(oxtime) as oxtime, oxobjectid from {$sO2CView} where oxobjectid in ( {$sProdIds} ) group by oxobjectid
00176 ) as _subtmp
00177 left join oxobject2category on oxobject2category.oxtime = _subtmp.oxtime and oxobject2category.oxobjectid = _subtmp.oxobjectid
00178 ) as _tmp
00179 )";
00180
00181 oxDb::getDb()->execute( $sQ );
00182 }
00183 }
00184
00190 public function removearticle()
00191 {
00192 $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00193 $sCategoryID = oxConfig::getParameter( 'oxid');
00194 $sShopID = $this->getConfig()->getShopId();
00195 $oDb = oxDb::getDb();
00196
00197
00198 if ( oxConfig::getParameter( 'all' ) ) {
00199 $sArticleTable = $this->_getViewName( 'oxarticles' );
00200 $aArticles = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00201 }
00202
00203
00204 if ( is_array( $aArticles ) && count( $aArticles ) ) {
00205 $sProdIds = implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) );
00206
00207 $sDelete = "delete from oxobject2category where";
00208 $sWhere = " oxcatnid=".$oDb->quote( $sCategoryID );
00209 if ( !$this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00210 $sQ = $sDelete.$sWhere." and oxobjectid in ( select oxid from oxarticles where oxparentid in ( {$sProdIds} ) )";
00211 $oDb->execute( $sQ );
00212 }
00213 $sQ = $sDelete.$sWhere." and oxobjectid in ( {$sProdIds} )";
00214 $oDb->execute( $sQ );
00215
00216
00217
00218 $this->_updateOxTime( $sProdIds );
00219 }
00220
00221 $this->resetArtSeoUrl( $aArticles, $sCategoryID );
00222 $this->resetCounter( "catArticle", $sCategoryID );
00223 }
00224 }