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 $_blAllowExtColumns = true;
00042 
00048     protected function _getQuery()
00049     {
00050         $myConfig = $this->getConfig();
00051 
00052         // looking for table/view
00053         $sArtTable = $this->_getViewName('oxarticles');
00054         $sCatTable = $this->_getViewName('oxcategories');
00055         $sO2CView  = $this->_getViewName('oxobject2category');
00056         $oDb = oxDb::getDb();
00057         $sSelId      = oxConfig::getParameter( 'oxid' );
00058         $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00059 
00060         // category selected or not ?
00061         if ( !$sSelId) {
00062             // dodger performance
00063             $sQAdd  = " from $sArtTable where 1 ";
00064             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00065         } else {
00066             // selected category ?
00067             if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00068                 $sQAdd  = " from $sO2CView as oxobject2category left join $sArtTable on ";
00069                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid=oxobject2category.oxobjectid or $sArtTable.oxparentid=oxobject2category.oxobjectid ) ":" $sArtTable.oxid=oxobject2category.oxobjectid ";
00070                 $sQAdd .= " where oxobject2category.oxcatnid = ".$oDb->quote( $sSelId );
00071             } else {
00072                 $sQAdd  = " from $sArtTable left join oxobject2selectlist on $sArtTable.oxid=oxobject2selectlist.oxobjectid ";
00073                 $sQAdd .= " where oxobject2selectlist.oxselnid = ".$oDb->quote( $sSelId );
00074             }
00075         }
00076 
00077         if ( $sSynchSelId && $sSynchSelId != $sSelId ) {
00078             // dodger performance
00079             $sQAdd .= " and $sArtTable.oxid not in ( select oxobject2selectlist.oxobjectid from oxobject2selectlist ";
00080             $sQAdd .= " where oxobject2selectlist.oxselnid = ".$oDb->quote( $sSynchSelId )." ) ";
00081         }
00082 
00083         return $sQAdd;
00084     }
00085 
00091     public function removeartfromsel()
00092     {
00093         $aChosenArt = $this->_getActionIds( 'oxobject2selectlist.oxid' );
00094         if ( oxConfig::getParameter( 'all' ) ) {
00095 
00096             $sQ = parent::_addFilter( "delete oxobject2selectlist.* ".$this->_getQuery() );
00097             oxDb::getDb()->Execute( $sQ );
00098 
00099         } elseif ( is_array( $aChosenArt ) ) {
00100             $sQ = "delete from oxobject2selectlist where oxobject2selectlist.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00101             oxDb::getDb()->Execute( $sQ );
00102         }
00103     }
00104 
00110     public function addarttosel()
00111     {
00112         $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00113         $soxId       = oxConfig::getParameter( 'synchoxid');
00114 
00115         if ( oxConfig::getParameter( 'all' ) ) {
00116             $sArtTable = $this->_getViewName('oxarticles');
00117             $aAddArticle = $this->_getAll( parent::_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00118         }
00119 
00120         if ( $soxId && $soxId != "-1" && is_array( $aAddArticle ) ) {
00121             $oDb = oxDb::getDb();
00122             foreach ($aAddArticle as $sAdd) {
00123                 $oNewGroup = oxNew( "oxbase" );
00124                 $oNewGroup->init( "oxobject2selectlist" );
00125                 $oNewGroup->oxobject2selectlist__oxobjectid = new oxField( $sAdd );
00126                 $oNewGroup->oxobject2selectlist__oxselnid = new oxField( $soxId );
00127                 $oNewGroup->oxobject2selectlist__oxsort   = new oxField( ( int ) $oDb->getOne( "select max(oxsort) + 1 from oxobject2selectlist where oxobjectid =  " . $oDb->quote( $sAdd ) . " " ) );
00128                 $oNewGroup->save();
00129             }
00130         }
00131     }
00132 }