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 = '" . $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 foreach ( $aArticles as $sAdd) {
00133
00134
00135 $sSelect = "select 1 from $sO2CView as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sCategoryID ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $sAdd ) . "";
00136 if ( $oDb->getOne( $sSelect ) )
00137 continue;
00138
00139 $oNew->oxobject2category__oxid = new oxField($oNew->setId( $myUtilsObject->generateUID() ));
00140 $oNew->oxobject2category__oxobjectid = new oxField($sAdd);
00141 $oNew->oxobject2category__oxcatnid = new oxField($sCategoryID);
00142 $oNew->oxobject2category__oxtime = new oxField(time());
00143 $oNew->save();
00144 }
00145
00146 $this->resetArtSeoUrl( $aArticles );
00147 $this->resetCounter( "catArticle", $sCategoryID );
00148 }
00149 }
00150
00156 public function removearticle()
00157 {
00158 $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00159 $sCategoryID = oxConfig::getParameter( 'oxid');
00160 $sShopID = $this->getConfig()->getShopId();
00161 $oDb = oxDb::getDb();
00162
00163
00164 if ( oxConfig::getParameter( 'all' ) ) {
00165
00166 $sO2CView = $this->_getViewName('oxobject2category');
00167 $sQ = $this->_addFilter( "delete $sO2CView.* ".$this->_getQuery() );
00168 $oDb->Execute( $sQ );
00169
00170 } elseif ( is_array( $aArticles ) && count( $aArticles ) ) {
00171 if ( !$this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00172 $sQ = "delete from oxobject2category where oxcatnid=".$oDb->quote( $sCategoryID )." and oxobjectid in ( select oxid from oxarticles where oxparentid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) ) . ") )";
00173 $oDb->execute( $sQ );
00174 }
00175 $sQ = "delete from oxobject2category where oxcatnid=".$oDb->quote( $sCategoryID )." and oxobjectid in ( " . implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) ) . ")";
00176 $oDb->execute( $sQ );
00177
00178 }
00179
00180 $this->resetArtSeoUrl( $sAdd );
00181 $this->resetCounter( "catArticle", $sCategoryID );
00182 }
00183 }