00001 <?php
00002
00006 class article_selection_ajax extends ajaxListComponent
00007 {
00013 protected $_aColumns = array( 'container1' => array(
00014 array( 'oxtitle', 'oxselectlist', 1, 1, 0 ),
00015 array( 'oxident', 'oxselectlist', 1, 0, 0 ),
00016 array( 'oxvaldesc', 'oxselectlist', 1, 0, 0 ),
00017 array( 'oxid', 'oxselectlist', 0, 0, 1 )
00018 ),
00019 'container2' => array(
00020 array( 'oxtitle', 'oxselectlist', 1, 1, 0 ),
00021 array( 'oxident', 'oxselectlist', 1, 0, 0 ),
00022 array( 'oxvaldesc', 'oxselectlist', 1, 0, 0 ),
00023 array( 'oxid', 'oxobject2selectlist', 0, 0, 1 )
00024 )
00025 );
00026
00032 protected function _getQuery()
00033 {
00034 $sSLViewName = $this->_getViewName('oxselectlist');
00035 $sArtViewName = $this->_getViewName('oxarticles');
00036 $oDb = oxDb::getDb();
00037
00038 $sArtId = oxConfig::getParameter( 'oxid' );
00039 $sSynchArtId = oxConfig::getParameter( 'synchoxid' );
00040
00041 $sOxid = ( $sArtId ) ? $sArtId : $sSynchArtId;
00042 $sQ = "select oxparentid from $sArtViewName where oxid = " . $oDb->quote( $sOxid ) . " and oxparentid != '' ";
00043 $sQ .= "and (select count(oxobjectid) from oxobject2selectlist where oxobjectid = " . $oDb->quote( $sOxid ) . ") = 0";
00044 $sParentId = oxDb::getDb()->getOne( $sQ, false, false );
00045
00046
00047 $sQAdd = " from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
00048 $sQAdd .= " where oxobject2selectlist.oxobjectid = " . $oDb->quote( $sOxid ) . " ";
00049 if ( $sParentId ) {
00050 $sQAdd .= "or oxobject2selectlist.oxobjectid = " . $oDb->quote( $sParentId ) . " ";
00051 }
00052
00053 if ( $sSynchArtId ) {
00054 $sQAdd = " from $sSLViewName where $sSLViewName.oxid not in ( select oxobject2selectlist.oxselnid $sQAdd ) ";
00055 }
00056
00057 return $sQAdd;
00058 }
00059
00065 public function removeSel()
00066 {
00067 $aChosenArt = $this->_getActionIds( 'oxobject2selectlist.oxid' );
00068 if ( oxConfig::getParameter( 'all' ) ) {
00069
00070 $sQ = $this->_addFilter( "delete oxobject2selectlist.* ".$this->_getQuery() );
00071 oxDb::getDb()->Execute( $sQ );
00072 } elseif ( is_array( $aChosenArt ) ) {
00073 $sQ = "delete from oxobject2selectlist where oxobject2selectlist.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00074 oxDb::getDb()->Execute( $sQ );
00075 }
00076
00077 }
00078
00084 public function addSel()
00085 {
00086 $aAddSel = $this->_getActionIds( 'oxselectlist.oxid' );
00087 $soxId = oxConfig::getParameter( 'synchoxid');
00088
00089
00090 if ( oxConfig::getParameter( 'all' ) ) {
00091 $sSLViewName = $this->_getViewName('oxselectlist');
00092 $aAddSel = $this->_getAll( $this->_addFilter( "select $sSLViewName.oxid ".$this->_getQuery() ) );
00093 }
00094
00095 if ( $soxId && $soxId != "-1" && is_array( $aAddSel ) ) {
00096 $oDb = oxDb::getDb();
00097 foreach ($aAddSel as $sAdd) {
00098 $oNew = oxNew( "oxbase" );
00099 $oNew->init( "oxobject2selectlist" );
00100 $oNew->oxobject2selectlist__oxobjectid = new oxField($soxId);
00101 $oNew->oxobject2selectlist__oxselnid = new oxField($sAdd);
00102 $oNew->oxobject2selectlist__oxsort = new oxField( ( int ) $oDb->getOne( "select max(oxsort) + 1 from oxobject2selectlist where oxobjectid = " . $oDb->quote( $soxId ) . " ", false, false ) );
00103 $oNew->save();
00104 }
00105
00106 }
00107 }
00108 }