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         $oConfig = $this->getConfig();
00048 
00049         $sArticleTable = $this->_getViewName('oxarticles');
00050         $sO2CView      = $this->_getViewName('oxobject2category');
00051 
00052         $oDb = oxDb::getDb();
00053         $sOxid = $oConfig->getRequestParameter( 'oxid' );
00054         $sSynchOxid = $oConfig->getRequestParameter( 'synchoxid' );
00055 
00056         // category selected or not ?
00057         if ( !$sOxid && $sSynchOxid ) {
00058             $sQAdd  = " from $sArticleTable where 1 ";
00059             $sQAdd .= $oConfig->getConfigParam( 'blVariantsSelection' )?'':"and $sArticleTable.oxparentid = '' ";
00060         } else {
00061             // selected category ?
00062             if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
00063                 $sQAdd  = " from $sO2CView left join $sArticleTable on ";
00064                 $sQAdd .= $oConfig->getConfigParam( 'blVariantsSelection' )?"($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
00065                 $sQAdd .= " where $sO2CView.oxcatnid = ".$oDb->quote( $sOxid )." and $sArticleTable.oxid is not null ";
00066 
00067                 // resetting
00068                 $sId = null;
00069             } else {
00070                 $sQAdd  = " from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00071                 $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sOxid )." and oxobject2discount.oxtype = 'oxarticles' ";
00072             }
00073         }
00074 
00075         if ( $sSynchOxid && $sSynchOxid != $sOxid) {
00076             // dodger performance
00077             $sSubSelect .= " select $sArticleTable.oxid from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00078             $sSubSelect .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchOxid )." and oxobject2discount.oxtype = 'oxarticles' ";
00079 
00080             if ( stristr( $sQAdd, 'where' ) === false )
00081                 $sQAdd .= ' where ';
00082             else
00083                 $sQAdd .= ' and ';
00084             $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
00085         }
00086 
00087         return $sQAdd;
00088     }
00089 
00095     public function removeDiscArt()
00096     {
00097         $aChosenArt = $this->_getActionIds( 'oxobject2discount.oxid' );
00098 
00099 
00100         if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00101 
00102             $sQ = parent::_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00103             oxDb::getDb()->Execute( $sQ );
00104 
00105         } elseif ( is_array( $aChosenArt ) ) {
00106             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00107             oxDb::getDb()->Execute( $sQ );
00108         }
00109     }
00110 
00116     public function addDiscArt()
00117     {
00118         $oConfig = $this->getConfig();
00119         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00120         $soxId      = $oConfig->getRequestParameter('synchoxid');
00121 
00122 
00123         // adding
00124         if ( $oConfig->getRequestParameter( 'all' ) ) {
00125             $sArticleTable = $this->_getViewName('oxarticles');
00126             $aChosenArt = $this->_getAll( parent::_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00127         }
00128         if ( $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00129             foreach ( $aChosenArt as $sChosenArt) {
00130                 $oObject2Discount = oxNew( "oxbase" );
00131                 $oObject2Discount->init( 'oxobject2discount' );
00132                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00133                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenArt);
00134                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxarticles");
00135                 $oObject2Discount->save();
00136 
00137             }
00138         }
00139     }
00140 
00141 
00142 }