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         $sCountryTable = $this->_getViewName('oxcountry');
00037         $oDb = oxDb::getDb();
00038         $sId = oxConfig::getParameter( 'oxid' );
00039         $sSynchId = oxConfig::getParameter( 'synchoxid' );
00040 
00041         // category selected or not ?
00042         if ( !$sId) {
00043             $sQAdd  = " from $sCountryTable where $sCountryTable.oxactive = '1' ";
00044         } else {
00045             $sQAdd  = " from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid ";
00046             $sQAdd .= "and oxobject2discount.oxdiscountid = ".$oDb->quote( $sId )." and oxobject2discount.oxtype = 'oxcountry' ";
00047         }
00048 
00049         if ( $sSynchId && $sSynchId != $sId) {
00050             $sQAdd .= "and $sCountryTable.oxid not in ( select $sCountryTable.oxid from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid ";
00051             $sQAdd .= "and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchId )." and oxobject2discount.oxtype = 'oxcountry' ) ";
00052         }
00053 
00054         return $sQAdd;
00055     }
00056 
00062     public function removeDiscCountry()
00063     {
00064 
00065         $aChosenCntr = $this->_getActionIds( 'oxobject2discount.oxid' );
00066         if ( oxConfig::getParameter( 'all' ) ) {
00067 
00068             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00069             oxDb::getDb()->Execute( $sQ );
00070 
00071         } elseif ( is_array( $aChosenCntr ) ) {
00072             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCntr ) ) . ") ";
00073             oxDb::getDb()->Execute( $sQ );
00074         }
00075     }
00076 
00082     public function addDiscCountry()
00083     {
00084         $aChosenCntr = $this->_getActionIds( 'oxcountry.oxid' );
00085         $soxId       = oxConfig::getParameter( 'synchoxid');
00086 
00087 
00088         if ( oxConfig::getParameter( 'all' ) ) {
00089             $sCountryTable = $this->_getViewName('oxcountry');
00090             $aChosenCntr = $this->_getAll( $this->_addFilter( "select $sCountryTable.oxid ".$this->_getQuery() ) );
00091         }
00092         if ( $soxId && $soxId != "-1" && is_array( $aChosenCntr ) ) {
00093             foreach ( $aChosenCntr as $sChosenCntr) {
00094                 $oObject2Discount = oxNew( "oxbase" );
00095                 $oObject2Discount->init( 'oxobject2discount' );
00096                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00097                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenCntr);
00098                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxcountry");
00099                 $oObject2Discount->save();
00100             }
00101         }
00102     }
00103 }