00001 <?php
00002
00006 class selectlist_main_ajax extends ajaxListComponent
00007 {
00013 protected $_blAllowExtColumns = true;
00014
00020 protected $_aColumns = array( 'container1' => array(
00021 array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00022 array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
00023 array( 'oxean', 'oxarticles', 0, 0, 0 ),
00024 array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
00025 array( 'oxprice', 'oxarticles', 0, 0, 0 ),
00026 array( 'oxstock', 'oxarticles', 0, 0, 0 ),
00027 array( 'oxid', 'oxarticles', 0, 0, 1 )
00028 ),
00029 'container2' => array(
00030 array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00031 array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
00032 array( 'oxean', 'oxarticles', 0, 0, 0 ),
00033 array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
00034 array( 'oxprice', 'oxarticles', 0, 0, 0 ),
00035 array( 'oxstock', 'oxarticles', 0, 0, 0 ),
00036 array( 'oxid', 'oxobject2selectlist', 0, 0, 1 ),
00037 array( 'oxid', 'oxarticles', 0, 0, 1 )
00038 ),
00039 'container3' => array(
00040 array( 'oxtitle', 'oxselectlist', 1, 1, 0 ),
00041 array( 'oxsort', 'oxobject2selectlist', 1, 0, 0 ),
00042 array( 'oxident', 'oxselectlist', 0, 0, 0 ),
00043 array( 'oxvaldesc', 'oxselectlist', 0, 0, 0 ),
00044 array( 'oxid', 'oxselectlist', 0, 0, 1 )
00045 )
00046 );
00047
00053 protected function _getQuery()
00054 {
00055 $myConfig = $this->getConfig();
00056
00057
00058 $sArtTable = $this->_getViewName('oxarticles');
00059 $sCatTable = $this->_getViewName('oxcategories');
00060 $sO2CView = $this->_getViewName('oxobject2category');
00061 $oDb = oxDb::getDb();
00062 $sSelId = oxConfig::getParameter( 'oxid' );
00063 $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00064
00065
00066 if ( !$sSelId) {
00067
00068 $sQAdd = " from $sArtTable where 1 ";
00069 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00070 } else {
00071
00072 if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00073 $sQAdd = " from $sO2CView as oxobject2category left join $sArtTable on ";
00074 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid=oxobject2category.oxobjectid or $sArtTable.oxparentid=oxobject2category.oxobjectid ) ":" $sArtTable.oxid=oxobject2category.oxobjectid ";
00075 $sQAdd .= " where oxobject2category.oxcatnid = ".$oDb->quote( $sSelId );
00076 } else {
00077 $sQAdd = " from $sArtTable left join oxobject2selectlist on $sArtTable.oxid=oxobject2selectlist.oxobjectid ";
00078 $sQAdd .= " where oxobject2selectlist.oxselnid = ".$oDb->quote( $sSelId );
00079 }
00080 }
00081
00082 if ( $sSynchSelId && $sSynchSelId != $sSelId ) {
00083
00084 $sQAdd .= " and $sArtTable.oxid not in ( select oxobject2selectlist.oxobjectid from oxobject2selectlist ";
00085 $sQAdd .= " where oxobject2selectlist.oxselnid = ".$oDb->quote( $sSynchSelId )." ) ";
00086 }
00087
00088 return $sQAdd;
00089 }
00090
00096 public function removeArtFromSel()
00097 {
00098 $aChosenArt = $this->_getActionIds( 'oxobject2selectlist.oxid' );
00099
00100
00101
00102
00103 if ( oxConfig::getParameter( 'all' ) ) {
00104
00105 $sQ = parent::_addFilter( "delete oxobject2selectlist.* ".$this->_getQuery() );
00106 oxDb::getDb()->Execute( $sQ );
00107
00108 } elseif ( is_array( $aChosenArt ) ) {
00109 $sQ = "delete from oxobject2selectlist where oxobject2selectlist.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00110 oxDb::getDb()->Execute( $sQ );
00111 }
00112 }
00113
00119 public function addArtToSel()
00120 {
00121 $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00122 $soxId = oxConfig::getParameter( 'synchoxid');
00123
00124 if ( oxConfig::getParameter( 'all' ) ) {
00125 $sArtTable = $this->_getViewName('oxarticles');
00126 $aAddArticle = $this->_getAll( parent::_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00127 }
00128
00129 if ( $soxId && $soxId != "-1" && is_array( $aAddArticle ) ) {
00130 $oDb = oxDb::getDb();
00131 foreach ($aAddArticle as $sAdd) {
00132 $oNewGroup = oxNew( "oxbase" );
00133 $oNewGroup->init( "oxobject2selectlist" );
00134 $oNewGroup->oxobject2selectlist__oxobjectid = new oxField( $sAdd );
00135 $oNewGroup->oxobject2selectlist__oxselnid = new oxField( $soxId );
00136 $oNewGroup->oxobject2selectlist__oxsort = new oxField( ( int ) $oDb->getOne( "select max(oxsort) + 1 from oxobject2selectlist where oxobjectid = " . $oDb->quote( $sAdd ) . " ", false, false ) );
00137 $oNewGroup->save();
00138
00139 }
00140 }
00141
00142
00143
00144 }
00145 }