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', 'oxaccessoire2article', 0, 0, 1 )
00018 )
00019 );
00020
00024 class ajaxComponent extends ajaxListComponent
00025 {
00031 protected function _getQuery()
00032 {
00033 $myConfig = $this->getConfig();
00034 $sSelId = oxConfig::getParameter( 'oxid' );
00035 $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00036 $oDb = oxDb::getDb();
00037
00038 $sArticleTable = getViewName('oxarticles');
00039 $sO2CView = getViewName('oxobject2category');
00040
00041
00042 if ( !$sSelId ) {
00043 $sQAdd = " from $sArticleTable where 1 ";
00044 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00045 } else {
00046
00047 if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00048 $sQAdd = " from $sO2CView left join $sArticleTable on ";
00049 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid )":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
00050 $sQAdd .= " where $sO2CView.oxcatnid = " . $oDb->quote( $sSelId ) . " ";
00051 } else {
00052 $sQAdd = " from oxaccessoire2article left join $sArticleTable on oxaccessoire2article.oxobjectid=$sArticleTable.oxid ";
00053 $sQAdd .= " where oxaccessoire2article.oxarticlenid = " . $oDb->quote( $sSelId ) . " ";
00054 }
00055 }
00056
00057 if ( $sSynchSelId && $sSynchSelId != $sSelId ) {
00058
00059 $sSubSelect .= " select oxaccessoire2article.oxobjectid from oxaccessoire2article ";
00060 $sSubSelect .= " where oxaccessoire2article.oxarticlenid = " . $oDb->quote( $sSynchSelId ) . " ";
00061 $sQAdd .= " and $sArticleTable.oxid not in ( $sSubSelect ) ";
00062 }
00063
00064
00065 return $sQAdd;
00066 }
00067
00075 protected function _getDataQuery( $sQ )
00076 {
00077 $sArtTable = getViewName('oxarticles');
00078 $sQ = parent::_getDataQuery( $sQ );
00079
00080
00081 $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00082 return $sQ;
00083 }
00084
00090 public function removearticleacc()
00091 {
00092 $aChosenArt = $this->_getActionIds( 'oxaccessoire2article.oxid' );
00093
00094 if ( oxConfig::getParameter( 'all' ) ) {
00095
00096 $sQ = $this->_addFilter( "delete oxaccessoire2article.* ".$this->_getQuery() );
00097 oxDb::getDb()->Execute( $sQ );
00098
00099 } elseif ( is_array( $aChosenArt ) ) {
00100 $sQ = "delete from oxaccessoire2article where oxaccessoire2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00101 oxDb::getDb()->Execute( $sQ );
00102 }
00103
00104 }
00105
00111 public function addarticleacc()
00112 {
00113 $oArticle = oxNew( "oxarticle" );
00114 $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00115 $soxId = oxConfig::getParameter( 'synchoxid');
00116
00117
00118 if ( oxConfig::getParameter( 'all' ) ) {
00119 $sArtTable = getViewName('oxarticles');
00120 $aChosenArt = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00121 }
00122
00123 if ( $oArticle->load( $soxId ) && $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00124 foreach ( $aChosenArt as $sChosenArt ) {
00125 $oNewGroup = oxNew( "oxbase" );
00126 $oNewGroup->init( "oxaccessoire2article" );
00127 $oNewGroup->oxaccessoire2article__oxobjectid = new oxField($sChosenArt);
00128 $oNewGroup->oxaccessoire2article__oxarticlenid = new oxField($oArticle->oxarticles__oxid->value);
00129 $oNewGroup->oxaccessoire2article__oxsort = new oxField(0);
00130 $oNewGroup->save();
00131 }
00132 }
00133 }
00134
00141 protected function _getQueryCols()
00142 {
00143 $myConfig = $this->getConfig();
00144 $sLangTag = oxLang::getInstance()->getLanguageTag();
00145
00146 $sQ = '';
00147 $blSep = false;
00148 $aVisiblecols = $this->_getVisibleColNames();
00149 foreach ( $aVisiblecols as $iCnt => $aCol ) {
00150 if ( $blSep )
00151 $sQ .= ', ';
00152 $sViewTable = getViewName( $aCol[1] );
00153
00154 $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00155 if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00156 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00157 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00158 } else {
00159 $sQ .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00160 }
00161 $blSep = true;
00162 }
00163
00164 $aIdentCols = $this->_getIdentColNames();
00165 foreach ( $aIdentCols as $iCnt => $aCol ) {
00166 if ( $blSep )
00167 $sQ .= ', ';
00168
00169
00170 $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00171 $sQ .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00172 }
00173
00174 return " $sQ ";
00175 }
00176
00177 }