article_selection.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00004                                         array( 'oxtitle',   'oxselectlist', 1, 1, 0 ),
00005                                         array( 'oxident',   'oxselectlist', 1, 0, 0 ),
00006                                         array( 'oxvaldesc', 'oxselectlist', 1, 0, 0 ),
00007                                         array( 'oxid',      'oxselectlist', 0, 0, 1 )
00008                                         ),
00009                      'container2' => array(
00010                                         array( 'oxtitle',   'oxselectlist', 1, 1, 0 ),
00011                                         array( 'oxident',   'oxselectlist', 1, 0, 0 ),
00012                                         array( 'oxvaldesc', 'oxselectlist', 1, 0, 0 ),
00013                                         array( 'oxid',      'oxobject2selectlist', 0, 0, 1 )
00014                                         )
00015                     );
00019 class ajaxComponent extends ajaxListComponent
00020 {
00026     protected function _getQuery()
00027     {
00028         $sSLViewName  = $this->_getViewName('oxselectlist');
00029         $sArtViewName = $this->_getViewName('oxarticles');
00030         $oDb          = oxDb::getDb();
00031 
00032         $sArtId      = oxConfig::getParameter( 'oxid' );
00033         $sSynchArtId = oxConfig::getParameter( 'synchoxid' );
00034 
00035         $sOxid = ( $sArtId ) ? $sArtId : $sSynchArtId;
00036         $sQ = "select oxparentid from $sArtViewName where oxid = " . $oDb->quote( $sOxid ) . " and oxparentid != '' ";
00037         $sQ .= "and (select count(oxobjectid) from oxobject2selectlist where oxobjectid = " . $oDb->quote( $sOxid ) . ") = 0";
00038         $sParentId = oxDb::getDb()->getOne( $sQ );
00039 
00040         // all selectlists article is in
00041         $sQAdd  = " from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
00042         $sQAdd .= " where oxobject2selectlist.oxobjectid = " . $oDb->quote( $sOxid ) . " ";
00043         if ( $sParentId ) {
00044             $sQAdd .= "or oxobject2selectlist.oxobjectid = " . $oDb->quote( $sParentId ) . " ";
00045         }
00046         // all not assigned selectlists
00047         if ( $sSynchArtId ) {
00048             $sQAdd  = " from $sSLViewName  where $sSLViewName.oxid not in ( select oxobject2selectlist.oxselnid $sQAdd ) ";
00049         }
00050 
00051         return $sQAdd;
00052     }
00053 
00059     public function removesel()
00060     {
00061         $aChosenArt = $this->_getActionIds( 'oxobject2selectlist.oxid' );
00062         if ( oxConfig::getParameter( 'all' ) ) {
00063 
00064             $sQ = $this->_addFilter( "delete oxobject2selectlist.* ".$this->_getQuery() );
00065             oxDb::getDb()->Execute( $sQ );
00066 
00067         } elseif ( is_array( $aChosenArt ) ) {
00068             $sQ = "delete from oxobject2selectlist where oxobject2selectlist.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00069             oxDb::getDb()->Execute( $sQ );
00070         }
00071     }
00072 
00078     public function addsel()
00079     {
00080         $aAddSel = $this->_getActionIds( 'oxselectlist.oxid' );
00081         $soxId   = oxConfig::getParameter( 'synchoxid');
00082 
00083         // adding
00084         if ( oxConfig::getParameter( 'all' ) ) {
00085             $sSLViewName = $this->_getViewName('oxselectlist');
00086             $aAddSel = $this->_getAll( $this->_addFilter( "select $sSLViewName.oxid ".$this->_getQuery() ) );
00087         }
00088 
00089         if ( $soxId && $soxId != "-1" && is_array( $aAddSel ) ) {
00090             $oDb = oxDb::getDb();
00091             foreach ($aAddSel as $sAdd) {
00092                 $oNew = oxNew( "oxbase" );
00093                 $oNew->init( "oxobject2selectlist" );
00094                 $oNew->oxobject2selectlist__oxobjectid = new oxField($soxId);
00095                 $oNew->oxobject2selectlist__oxselnid   = new oxField($sAdd);
00096                 $oNew->oxobject2selectlist__oxsort     = new oxField( ( int ) $oDb->getOne( "select max(oxsort) + 1 from oxobject2selectlist where oxobjectid =  " . $oDb->quote( $soxId ) . " " ) );
00097                 $oNew->save();
00098             }
00099         }
00100     }
00101 }