discount_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class discount_main_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00014                                         array( 'oxtitle',     'oxcountry', 1, 1, 0 ),
00015                                         array( 'oxisoalpha2', 'oxcountry', 1, 0, 0 ),
00016                                         array( 'oxisoalpha3', 'oxcountry', 0, 0, 0 ),
00017                                         array( 'oxunnum3',    'oxcountry', 0, 0, 0 ),
00018                                         array( 'oxid',        'oxcountry', 0, 0, 1 )
00019                                         ),
00020                                     'container2' => array(
00021                                         array( 'oxtitle',     'oxcountry', 1, 1, 0 ),
00022                                         array( 'oxisoalpha2', 'oxcountry', 1, 0, 0 ),
00023                                         array( 'oxisoalpha3', 'oxcountry', 0, 0, 0 ),
00024                                         array( 'oxunnum3',    'oxcountry', 0, 0, 0 ),
00025                                         array( 'oxid', 'oxobject2discount', 0, 0, 1 )
00026                                         )
00027                                 );
00028 
00034     protected function _getQuery()
00035     {
00036         $oConfig = $this->getConfig();
00037         $sCountryTable = $this->_getViewName('oxcountry');
00038         $oDb = oxDb::getDb();
00039         $sId = $oConfig->getRequestParameter( 'oxid' );
00040         $sSynchId = $oConfig->getRequestParameter( 'synchoxid' );
00041 
00042         // category selected or not ?
00043         if ( !$sId) {
00044             $sQAdd  = " from $sCountryTable where $sCountryTable.oxactive = '1' ";
00045         } else {
00046             $sQAdd  = " from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid ";
00047             $sQAdd .= "and oxobject2discount.oxdiscountid = ".$oDb->quote( $sId )." and oxobject2discount.oxtype = 'oxcountry' ";
00048         }
00049 
00050         if ( $sSynchId && $sSynchId != $sId) {
00051             $sQAdd .= "and $sCountryTable.oxid not in ( select $sCountryTable.oxid from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid ";
00052             $sQAdd .= "and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchId )." and oxobject2discount.oxtype = 'oxcountry' ) ";
00053         }
00054 
00055         return $sQAdd;
00056     }
00057 
00063     public function removeDiscCountry()
00064     {
00065         $oConfig = $this->getConfig();
00066 
00067         $aChosenCntr = $this->_getActionIds( 'oxobject2discount.oxid' );
00068         if ( $oConfig->getRequestParameter( 'all' ) ) {
00069 
00070             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00071             oxDb::getDb()->Execute( $sQ );
00072 
00073         } elseif ( is_array( $aChosenCntr ) ) {
00074             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCntr ) ) . ") ";
00075             oxDb::getDb()->Execute( $sQ );
00076         }
00077     }
00078 
00084     public function addDiscCountry()
00085     {
00086         $oConfig = $this->getConfig();
00087         $aChosenCntr = $this->_getActionIds( 'oxcountry.oxid' );
00088         $soxId       = $oConfig->getRequestParameter( 'synchoxid');
00089 
00090 
00091         if ( $oConfig->getRequestParameter( 'all' ) ) {
00092             $sCountryTable = $this->_getViewName('oxcountry');
00093             $aChosenCntr = $this->_getAll( $this->_addFilter( "select $sCountryTable.oxid ".$this->_getQuery() ) );
00094         }
00095         if ( $soxId && $soxId != "-1" && is_array( $aChosenCntr ) ) {
00096             foreach ( $aChosenCntr as $sChosenCntr) {
00097                 $oObject2Discount = oxNew( "oxbase" );
00098                 $oObject2Discount->init( 'oxobject2discount' );
00099                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00100                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenCntr);
00101                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxcountry");
00102                 $oObject2Discount->save();
00103             }
00104         }
00105     }
00106 }