discount_articles_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class discount_articles_ajax extends ajaxListComponent
00007 {
00013     protected $_blAllowExtColumns = true;
00014     
00020     protected $_aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00021                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00022                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00023                                         array( 'oxean',    'oxarticles', 1, 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', 1, 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',     'oxobject2discount', 0, 0, 1 )
00037                                         )
00038                                 );
00039 
00045     protected function _getQuery()
00046     {
00047         $myConfig = $this->getConfig();
00048 
00049         $sArticleTable = $this->_getViewName('oxarticles');
00050         $sCatTable     = $this->_getViewName('oxcategories');
00051         $sO2CView      = $this->_getViewName('oxobject2category');
00052 
00053         $oDb = oxDb::getDb();
00054         $sOxid = oxConfig::getParameter( 'oxid' );
00055         $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00056 
00057         // category selected or not ?
00058         if ( !$sOxid && $sSynchOxid ) {
00059             $sQAdd  = " from $sArticleTable where 1 ";
00060             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':"and $sArticleTable.oxparentid = '' ";
00061         } else {
00062             // selected category ?
00063             if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
00064                 $sQAdd  = " from $sO2CView left join $sArticleTable on ";
00065                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?"($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
00066                 $sQAdd .= " where $sO2CView.oxcatnid = ".$oDb->quote( $sOxid )." and $sArticleTable.oxid is not null ";
00067 
00068                 // resetting
00069                 $sId = null;
00070             } else {
00071                 $sQAdd  = " from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00072                 $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sOxid )." and oxobject2discount.oxtype = 'oxarticles' ";
00073             }
00074         }
00075 
00076         if ( $sSynchOxid && $sSynchOxid != $sOxid) {
00077             // dodger performance
00078             $sSubSelect .= " select $sArticleTable.oxid from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00079             $sSubSelect .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchOxid )." and oxobject2discount.oxtype = 'oxarticles' ";
00080 
00081             if ( stristr( $sQAdd, 'where' ) === false )
00082                 $sQAdd .= ' where ';
00083             else
00084                 $sQAdd .= ' and ';
00085             $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
00086         }
00087 
00088         return $sQAdd;
00089     }
00090 
00096     public function removeDiscArt()
00097     {
00098         $aChosenArt = $this->_getActionIds( 'oxobject2discount.oxid' );
00099         if ( oxConfig::getParameter( 'all' ) ) {
00100 
00101             $sQ = parent::_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00102             oxDb::getDb()->Execute( $sQ );
00103 
00104         } elseif ( is_array( $aChosenArt ) ) {
00105             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00106             oxDb::getDb()->Execute( $sQ );
00107         }
00108     }
00109 
00115     public function addDiscArt()
00116     {
00117         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00118         $soxId      = oxConfig::getParameter( 'synchoxid');
00119 
00120         // adding
00121         if ( oxConfig::getParameter( 'all' ) ) {
00122             $sArticleTable = $this->_getViewName('oxarticles');
00123             $aChosenArt = $this->_getAll( parent::_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00124         }
00125         if ( $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00126             foreach ( $aChosenArt as $sChosenArt) {
00127                 $oObject2Discount = oxNew( "oxbase" );
00128                 $oObject2Discount->init( 'oxobject2discount' );
00129                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00130                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenArt);
00131                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxarticles");
00132                 $oObject2Discount->save();
00133             }
00134         }
00135     }
00136 }