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( 'oxprice', 'oxarticles', 0, 0, 0 ),
00008 array( 'oxstock', 'oxarticles', 0, 0, 0 ),
00009 array( 'oxid', 'oxarticles', 0, 0, 1 )
00010 ),
00011 'container2' => array(
00012 array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00013 array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
00014 array( 'oxean', 'oxarticles', 1, 0, 0 ),
00015 array( 'oxprice', 'oxarticles', 0, 0, 0 ),
00016 array( 'oxstock', 'oxarticles', 0, 0, 0 ),
00017 array( 'oxid', 'oxobject2category', 0, 0, 1 )
00018 )
00019 );
00020
00021
00025 class ajaxComponent extends ajaxListComponent
00026 {
00032 protected function _getQuery()
00033 {
00034 $myConfig = $this->getConfig();
00035
00036 $sArticleTable = getViewName('oxarticles');
00037 $sO2CView = getViewName('oxobject2category');
00038
00039 $sOxid = oxConfig::getParameter( 'oxid' );
00040 $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00041 $oDb = oxDb::getDb();
00042
00043 $sShopID = $myConfig->getShopId();
00044
00045
00046 if ( !$sOxid && $sSynchOxid ) {
00047
00048
00049 $sQAdd = ' from '.$sArticleTable.' where 1 ';
00050 } else {
00051
00052
00053 $sJoin = $myConfig->getConfigParam( 'blVariantsSelection' )? ' ('.$sArticleTable.'.oxparentid='.$sO2CView.'.oxobjectid or '.$sArticleTable.'.oxid='.$sO2CView.'.oxobjectid ) ' : ' '.$sArticleTable.'.oxid='.$sO2CView.'.oxobjectid ';
00054
00055 $sSubSelect = '';
00056 if ( $sSynchOxid && $sOxid != $sSynchOxid) {
00057
00058 $sSubSelect = ' and '.$sArticleTable.'.oxid not in ( ';
00059 $sSubSelect .= "select $sArticleTable.oxid from $sO2CView left join $sArticleTable ";
00060 $sSubSelect .= "on $sJoin where $sO2CView.oxcatnid = " . $oDb->quote( $sSynchOxid ) . " ";
00061 $sSubSelect .= 'and '.$sArticleTable.'.oxid is not null ) ';
00062 }
00063
00064 $sQAdd = " from $sO2CView join $sArticleTable ";
00065 $sQAdd .= " on $sJoin where $sO2CView.oxcatnid = '" . $sOxid . "' ";
00066 $sQAdd .= " and $sArticleTable.oxid is not null $sSubSelect ";
00067 }
00068
00069 return $sQAdd;
00070 }
00071
00079 protected function _getDataQuery( $sQ )
00080 {
00081 $sArtTable = getViewName('oxarticles');
00082 $sQ = parent::_getDataQuery( $sQ );
00083
00084
00085 $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00086 return $sQ;
00087 }
00088
00095 public function addarticle()
00096 {
00097 $myConfig = $this->getConfig();
00098
00099 $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
00100 $sCategoryID = oxConfig::getParameter( 'synchoxid');
00101 $sShopID = $myConfig->getShopId();
00102
00103
00104 if ( oxConfig::getParameter( 'all' ) ) {
00105 $sArticleTable = getViewName( 'oxarticles' );
00106 $aArticles = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00107 }
00108
00109 if ( is_array($aArticles)) {
00110
00111 $oDb = oxDb::getDb();
00112
00113 $sO2CView = getViewName('oxobject2category');
00114
00115 $oNew = oxNew( 'oxbase' );
00116 $oNew->init( 'oxobject2category' );
00117 $myUtilsObject = oxUtilsObject::getInstance();
00118 $oActShop = $myConfig->getActiveShop();
00119
00120 foreach ( $aArticles as $sAdd) {
00121
00122
00123 $sSelect = "select 1 from $sO2CView as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sCategoryID ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $sAdd ) . "";
00124 if ( $oDb->getOne( $sSelect ) )
00125 continue;
00126
00127 $oNew->oxobject2category__oxid = new oxField($oNew->setId( $myUtilsObject->generateUID() ));
00128 $oNew->oxobject2category__oxobjectid = new oxField($sAdd);
00129 $oNew->oxobject2category__oxcatnid = new oxField($sCategoryID);
00130 $oNew->oxobject2category__oxtime = new oxField(time());
00131 $oNew->save();
00132 }
00133
00134 $this->resetCounter( "catArticle", $sCategoryID );
00135 }
00136 }
00137
00143 public function removearticle()
00144 {
00145 $aArticles = $this->_getActionIds( 'oxobject2category.oxid' );
00146 $sCategoryID = oxConfig::getParameter( 'oxid');
00147 $sShopID = $this->getConfig()->getShopId();
00148 $oDb = oxDb::getDb();
00149
00150
00151 if ( oxConfig::getParameter( 'all' ) ) {
00152
00153 $sO2CView = getViewName('oxobject2category');
00154 $sQ = $this->_addFilter( "delete $sO2CView.* ".$this->_getQuery() );
00155 $oDb->Execute( $sQ );
00156
00157 } elseif ( is_array( $aArticles ) && count( $aArticles ) ) {
00158
00159 $sQ = "delete from oxobject2category where oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) ) . ")";
00160 $oDb->Execute( $sQ );
00161
00162 }
00163
00164 $this->resetCounter( "catArticle", $sCategoryID );
00165 }
00166
00173 protected function _getQueryCols()
00174 {
00175 $myConfig = $this->getConfig();
00176 $sLangTag = oxLang::getInstance()->getLanguageTag();
00177
00178 $sQ = '';
00179 $blSep = false;
00180 $aVisiblecols = $this->_getVisibleColNames();
00181 foreach ( $aVisiblecols as $iCnt => $aCol ) {
00182 if ( $blSep )
00183 $sQ .= ', ';
00184 $sViewTable = getViewName( $aCol[1] );
00185
00186 $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00187 if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00188 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00189 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00190 } else {
00191 $sQ .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00192 }
00193 $blSep = true;
00194 }
00195
00196 $aIdentCols = $this->_getIdentColNames();
00197 foreach ( $aIdentCols as $iCnt => $aCol ) {
00198 if ( $blSep )
00199 $sQ .= ', ';
00200
00201
00202 $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00203 $sQ .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00204 }
00205
00206 return " $sQ ";
00207 }
00208
00209 }