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( '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 
00037         $sArticleTable = getViewName('oxarticles');
00038         $sO2CView      = getViewName('oxobject2category');
00039 
00040         // category selected or not ?
00041         if ( !$sSelId ) {
00042             $sQAdd  = " from $sArticleTable where 1 ";
00043             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00044         } else {
00045             // selected category ?
00046             if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00047                 $sQAdd  = " from $sO2CView left join $sArticleTable on ";
00048                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid )":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
00049                 $sQAdd .= " where $sO2CView.oxcatnid = '$sSelId' ";
00050             } else {
00051                 $sQAdd  = " from oxaccessoire2article left join $sArticleTable on oxaccessoire2article.oxobjectid=$sArticleTable.oxid ";
00052                 $sQAdd .= " where oxaccessoire2article.oxarticlenid = '$sSelId' ";
00053             }
00054         }
00055 
00056         if ( $sSynchSelId && $sSynchSelId != $sSelId ) {
00057             // dodger performance
00058             $sSubSelect .= " select oxaccessoire2article.oxobjectid from oxaccessoire2article ";
00059             $sSubSelect .= " where oxaccessoire2article.oxarticlenid = '$sSynchSelId' ";
00060             $sQAdd .= " and $sArticleTable.oxid not in ( $sSubSelect ) ";
00061         }
00062 
00063         // creating AJAX component
00064         return $sQAdd;
00065     }
00066 
00072     public function removearticleacc()
00073     {
00074         $aChosenArt = $this->_getActionIds( 'oxaccessoire2article.oxid' );
00075         // removing all
00076         if ( oxConfig::getParameter( 'all' ) ) {
00077 
00078             $sQ = $this->_addFilter( "delete oxaccessoire2article.* ".$this->_getQuery() );
00079             oxDb::getDb()->Execute( $sQ );
00080 
00081         } elseif ( is_array( $aChosenArt ) ) {
00082             $sQ = "delete from oxaccessoire2article where oxaccessoire2article.oxid in ('" . implode( "', '", $aChosenArt ) . "') ";
00083             oxDb::getDb()->Execute( $sQ );
00084         }
00085 
00086     }
00087 
00093     public function addarticleacc()
00094     {
00095         $oArticle   = oxNew( "oxarticle" );
00096         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00097         $soxId      = oxConfig::getParameter( 'synchoxid');
00098 
00099         // adding
00100         if ( oxConfig::getParameter( 'all' ) ) {
00101             $sArtTable = getViewName('oxarticles');
00102             $aChosenArt = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00103         }
00104 
00105         if ( $oArticle->load( $soxId ) && $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00106             foreach ( $aChosenArt as $sChosenArt ) {
00107                 $oNewGroup = oxNew( "oxbase" );
00108                 $oNewGroup->init( "oxaccessoire2article" );
00109                 $oNewGroup->oxaccessoire2article__oxobjectid   = new oxField($sChosenArt);
00110                 $oNewGroup->oxaccessoire2article__oxarticlenid = new oxField($oArticle->oxarticles__oxid->value);
00111                 $oNewGroup->oxaccessoire2article__oxsort       = new oxField(0);
00112                 $oNewGroup->save();
00113             }
00114         }
00115     }
00116 
00123     protected function _getQueryCols()
00124     {
00125         $myConfig = $this->getConfig();
00126         $sLangTag = oxLang::getInstance()->getLanguageTag();
00127 
00128         $sQ = '';
00129         $blSep = false;
00130         $aVisiblecols = $this->_getVisibleColNames();
00131         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00132             if ( $blSep )
00133                 $sQ .= ', ';
00134             $sViewTable = getViewName( $aCol[1] );
00135             // multilanguage
00136             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00137             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00138                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00139                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00140             } else {
00141                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00142             }
00143             $blSep = true;
00144         }
00145 
00146         $aIdentCols = $this->_getIdentColNames();
00147         foreach ( $aIdentCols as $iCnt => $aCol ) {
00148             if ( $blSep )
00149                 $sQ .= ', ';
00150 
00151             // multilanguage
00152             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00153             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00154         }
00155 
00156         return " $sQ ";
00157     }
00158 
00159 }

Generated on Wed May 13 13:25:50 2009 for OXID eShop CE by  doxygen 1.5.5