article_accessories.inc.php

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