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 function _getQuery()
00035 {
00036 $myConfig = $this->getConfig();
00037
00038 $sArticleTable = getViewName('oxarticles');
00039 $sO2CView = getViewName('oxobject2category');
00040
00041 $sOxid = oxConfig::getParameter( 'oxid' );
00042 $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00043 $oDb = oxDb::getDb();
00044
00045 $sShopID = $myConfig->getShopId();
00046
00047
00048 if ( !$sOxid && $sSynchOxid ) {
00049
00050
00051 $sQAdd = ' from '.$sArticleTable.' where 1 ';
00052 } else {
00053
00054
00055 $sJoin = " {$sArticleTable}.oxid={$sO2CView}.oxobjectid ";
00056
00057 $sSubSelect = '';
00058 if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
00059
00060 $sSubSelect = ' and '.$sArticleTable.'.oxid not in ( ';
00061 $sSubSelect .= "select $sArticleTable.oxid from $sO2CView left join $sArticleTable ";
00062 $sSubSelect .= "on $sJoin where $sO2CView.oxcatnid = " . $oDb->quote( $sSynchOxid ) . " ";
00063 $sSubSelect .= 'and '.$sArticleTable.'.oxid is not null ) ';
00064 }
00065
00066 $sQAdd = " from $sO2CView join $sArticleTable ";
00067 $sQAdd .= " on $sJoin where $sO2CView.oxcatnid = '" . $sOxid . "' ";
00068 $sQAdd .= " and $sArticleTable.oxid is not null $sSubSelect ";
00069 }
00070
00071 return $sQAdd;
00072 }
00073
00081 protected function _addFilter( $sQ )
00082 {
00083 $sArtTable = getViewName('oxarticles');
00084 $sQ = parent::_addFilter( $sQ );
00085
00086
00087 if ( !$this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00088 $sQ .= " and {$sArtTable}.oxparentid = '' ";
00089 }
00090
00091 return $sQ;
00092 }
00093
00100 public function addarticle()
00101 {
00102 $myConfig = $this->getConfig();
00103
00104 $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00105 $sCategoryID = oxConfig::getParameter( 'synchoxid');
00106 $sShopID = $myConfig->getShopId();
00107 $oDb = oxDb::getDb();
00108 $sArticleTable = getViewName( 'oxarticles' );
00109
00110
00111 if ( oxConfig::getParameter( 'all' ) ) {
00112 $aArticles = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00113 } else {
00114
00115 $aVariants = $this->_getAll( "select $sArticleTable.oxid from $sArticleTable where $sArticleTable.oxparentid in ( " . implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) ) . ")" );
00116 if ( count( $aVariants ) ) {
00117 $aArticles = array_merge( $aArticles, $aVariants );
00118 }
00119 }
00120
00121 if ( is_array($aArticles)) {
00122
00123
00124 $sO2CView = getViewName('oxobject2category');
00125
00126 $oNew = oxNew( 'oxbase' );
00127 $oNew->init( 'oxobject2category' );
00128 $myUtilsObject = oxUtilsObject::getInstance();
00129 $oActShop = $myConfig->getActiveShop();
00130
00131 foreach ( $aArticles as $sAdd) {
00132
00133
00134 $sSelect = "select 1 from $sO2CView as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sCategoryID ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $sAdd ) . "";
00135 if ( $oDb->getOne( $sSelect ) )
00136 continue;
00137
00138 $oNew->oxobject2category__oxid = new oxField($oNew->setId( $myUtilsObject->generateUID() ));
00139 $oNew->oxobject2category__oxobjectid = new oxField($sAdd);
00140 $oNew->oxobject2category__oxcatnid = new oxField($sCategoryID);
00141 $oNew->oxobject2category__oxtime = new oxField(time());
00142 $oNew->save();
00143 }
00144
00145 $this->resetArtSeoUrl( $aArticles );
00146 $this->resetCounter( "catArticle", $sCategoryID );
00147 }
00148 }
00149
00155 public function removearticle()
00156 {
00157 $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00158 $sCategoryID = oxConfig::getParameter( 'oxid');
00159 $sShopID = $this->getConfig()->getShopId();
00160 $oDb = oxDb::getDb();
00161
00162
00163 if ( oxConfig::getParameter( 'all' ) ) {
00164
00165 $sO2CView = getViewName('oxobject2category');
00166 $sQ = $this->_addFilter( "delete $sO2CView.* ".$this->_getQuery() );
00167 $oDb->Execute( $sQ );
00168
00169 } elseif ( is_array( $aArticles ) && count( $aArticles ) ) {
00170 if ( $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00171 $sQ = "delete from oxobject2category where oxcatnid=".$oDb->quote( $sCategoryID )." and oxobjectid in ( select oxid from oxarticles where oxparentid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) ) . ") )";
00172 $oDb->execute( $sQ );
00173 }
00174 $sQ = "delete from oxobject2category where oxcatnid=".$oDb->quote( $sCategoryID )." and oxobjectid in ( " . implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) ) . ")";
00175 $oDb->execute( $sQ );
00176
00177 }
00178
00179 $this->resetArtSeoUrl( $sAdd );
00180 $this->resetCounter( "catArticle", $sCategoryID );
00181 }
00182
00189 protected function _getQueryCols()
00190 {
00191 $myConfig = $this->getConfig();
00192 $sLangTag = oxLang::getInstance()->getLanguageTag();
00193
00194 $sQ = '';
00195 $blSep = false;
00196 $aVisiblecols = $this->_getVisibleColNames();
00197 foreach ( $aVisiblecols as $iCnt => $aCol ) {
00198 if ( $blSep )
00199 $sQ .= ', ';
00200 $sViewTable = getViewName( $aCol[1] );
00201
00202 $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00203 if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00204 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00205 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00206 } else {
00207 $sQ .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00208 }
00209 $blSep = true;
00210 }
00211
00212 $aIdentCols = $this->_getIdentColNames();
00213 foreach ( $aIdentCols as $iCnt => $aCol ) {
00214 if ( $blSep )
00215 $sQ .= ', ';
00216
00217
00218 $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00219 $sQ .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00220 }
00221
00222 return " $sQ ";
00223 }
00224
00225 }