article_selection_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class article_selection_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
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         // all selectlists article is in
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         // all not assigned selectlists
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 
00083     public function addSel()
00084     {
00085         $aAddSel = $this->_getActionIds( 'oxselectlist.oxid' );
00086         $soxId   = oxConfig::getParameter( 'synchoxid');
00087 
00088         // adding
00089         if ( oxConfig::getParameter( 'all' ) ) {
00090             $sSLViewName = $this->_getViewName('oxselectlist');
00091             $aAddSel = $this->_getAll( $this->_addFilter( "select $sSLViewName.oxid ".$this->_getQuery() ) );
00092         }
00093 
00094         if ( $soxId && $soxId != "-1" && is_array( $aAddSel ) ) {
00095             $oDb = oxDb::getDb();
00096             foreach ($aAddSel as $sAdd) {
00097                 $oNew = oxNew( "oxbase" );
00098                 $oNew->init( "oxobject2selectlist" );
00099                 $oNew->oxobject2selectlist__oxobjectid = new oxField($soxId);
00100                 $oNew->oxobject2selectlist__oxselnid   = new oxField($sAdd);
00101                 $oNew->oxobject2selectlist__oxsort     = new oxField( ( int ) $oDb->getOne( "select max(oxsort) + 1 from oxobject2selectlist where oxobjectid =  " . $oDb->quote( $soxId ) . " ", false, false ) );
00102                 $oNew->save();
00103             }
00104         }
00105     }
00106 }