selectlist_main.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', 0, 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', 0, 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',     'oxobject2selectlist', 0, 0, 1 ),
00020                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00021                                         ),
00022                      'container3' => array(
00023                                         array( 'oxtitle',   'oxselectlist', 1, 1, 0 ),
00024                                         array( 'oxsort',    'oxobject2selectlist', 1, 0, 0 ),
00025                                         array( 'oxident',   'oxselectlist', 0, 0, 0 ),
00026                                         array( 'oxvaldesc', 'oxselectlist', 0, 0, 0 ),
00027                                         array( 'oxid',      'oxselectlist', 0, 0, 1 )
00028                                                                                             )
00029                                     );
00030 
00034 class ajaxComponent extends ajaxListComponent
00035 {
00041     protected function _getQuery()
00042     {
00043         $myConfig = $this->getConfig();
00044 
00045         // looking for table/view
00046         $sArtTable = getViewName('oxarticles');
00047         $sCatTable = getViewName('oxcategories');
00048         $sO2CView  = getViewName('oxobject2category');
00049 
00050         $sSelId      = oxConfig::getParameter( 'oxid' );
00051         $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00052 
00053         // category selected or not ?
00054         if ( !$sSelId) {
00055             // dodger performance
00056             $sQAdd  = " from $sArtTable where 1 ";
00057             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00058         } else {
00059             // selected category ?
00060             if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00061                 $sQAdd  = " from $sO2CView as oxobject2category left join $sArtTable on ";
00062                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid=oxobject2category.oxobjectid or $sArtTable.oxparentid=oxobject2category.oxobjectid ) ":" $sArtTable.oxid=oxobject2category.oxobjectid ";
00063                 $sQAdd .= " where oxobject2category.oxcatnid = '$sSelId' ";
00064             } else {
00065                 $sQAdd  = " from $sArtTable left join oxobject2selectlist on $sArtTable.oxid=oxobject2selectlist.oxobjectid ";
00066                 $sQAdd .= " where oxobject2selectlist.oxselnid = '$sSelId' ";
00067             }
00068         }
00069 
00070         if ( $sSynchSelId && $sSynchSelId != $sSelId ) {
00071             // dodger performance
00072             $sQAdd .= " and $sArtTable.oxid not in ( select oxobject2selectlist.oxobjectid from oxobject2selectlist ";
00073             $sQAdd .= " where oxobject2selectlist.oxselnid = '$sSynchSelId' ) ";
00074         }
00075 
00076         return $sQAdd;
00077     }
00078 
00086     protected function _addFilter( $sQ )
00087     {
00088         $sArtTable = getViewName('oxarticles');
00089         $sQ = parent::_addFilter( $sQ );
00090 
00091         // display variants or not ?
00092         $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00093         return $sQ;
00094     }
00095 
00101     public function removeartfromsel()
00102     {
00103         $aChosenArt = $this->_getActionIds( 'oxobject2selectlist.oxid' );
00104         if ( oxConfig::getParameter( 'all' ) ) {
00105 
00106             $sQ = $this->_addFilter( "delete oxobject2selectlist.* ".$this->_getQuery() );
00107             oxDb::getDb()->Execute( $sQ );
00108 
00109         } elseif ( is_array( $aChosenArt ) ) {
00110             $sQ = "delete from oxobject2selectlist where oxobject2selectlist.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00111             oxDb::getDb()->Execute( $sQ );
00112         }
00113     }
00114 
00120     public function addarttosel()
00121     {
00122         $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00123         $soxId       = oxConfig::getParameter( 'synchoxid');
00124 
00125         if ( oxConfig::getParameter( 'all' ) ) {
00126             $sArtTable = getViewName('oxarticles');
00127             $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00128         }
00129 
00130         if ( $soxId && $soxId != "-1" && is_array( $aAddArticle ) ) {
00131             $oDb = oxDb::getDb();
00132             foreach ($aAddArticle as $sAdd) {
00133                 $oNewGroup = oxNew( "oxbase" );
00134                 $oNewGroup->init( "oxobject2selectlist" );
00135                 $oNewGroup->oxobject2selectlist__oxobjectid = new oxField( $sAdd );
00136                 $oNewGroup->oxobject2selectlist__oxselnid = new oxField( $soxId );
00137                 $oNewGroup->oxobject2selectlist__oxsort   = new oxField( ( int ) $oDb->getOne( "select max(oxsort) + 1 from oxobject2selectlist where oxobjectid =  " . $oDb->quote( $sAdd ) . " " ) );
00138                 $oNewGroup->save();
00139             }
00140         }
00141     }
00142 
00149     protected function _getQueryCols()
00150     {
00151         $myConfig = $this->getConfig();
00152         $sLangTag = oxLang::getInstance()->getLanguageTag();
00153 
00154         $sQ = '';
00155         $blSep = false;
00156         $aVisiblecols = $this->_getVisibleColNames();
00157         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00158             if ( $blSep )
00159                 $sQ .= ', ';
00160             $sViewTable = getViewName( $aCol[1] );
00161             // multilanguage
00162             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00163             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00164                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00165                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00166             } else {
00167                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00168             }
00169             $blSep = true;
00170         }
00171 
00172         $aIdentCols = $this->_getIdentColNames();
00173         foreach ( $aIdentCols as $iCnt => $aCol ) {
00174             if ( $blSep )
00175                 $sQ .= ', ';
00176 
00177             // multilanguage
00178             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00179             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00180         }
00181 
00182         return " $sQ ";
00183     }
00184 
00185 }