discount_main.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',     'oxcountry', 1, 1, 0 ),
00005                                         array( 'oxisoalpha2', 'oxcountry', 1, 0, 0 ),
00006                                         array( 'oxisoalpha3', 'oxcountry', 0, 0, 0 ),
00007                                         array( 'oxunnum3',    'oxcountry', 0, 0, 0 ),
00008                                         array( 'oxid',        'oxcountry', 0, 0, 1 )
00009                                         ),
00010                      'container2' => array(
00011                                         array( 'oxtitle',     'oxcountry', 1, 1, 0 ),
00012                                         array( 'oxisoalpha2', 'oxcountry', 1, 0, 0 ),
00013                                         array( 'oxisoalpha3', 'oxcountry', 0, 0, 0 ),
00014                                         array( 'oxunnum3',    'oxcountry', 0, 0, 0 ),
00015                                         array( 'oxid', 'oxobject2discount', 0, 0, 1 )
00016                                         )
00017                     );
00021 class ajaxComponent extends ajaxListComponent
00022 {
00028     protected function _getQuery()
00029     {
00030         $sCountryTable = getViewName('oxcountry');
00031         $sId      = oxConfig::getParameter( 'oxid' );
00032         $sSynchId = oxConfig::getParameter( 'synchoxid' );
00033 
00034         // category selected or not ?
00035         if ( !$sId) {
00036             $sQAdd  = " from $sCountryTable where $sCountryTable.oxactive = '1' ";
00037         } else {
00038             $sQAdd  = " from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid ";
00039             $sQAdd .= "and oxobject2discount.oxdiscountid = '$sId' and oxobject2discount.oxtype = 'oxcountry' ";
00040         }
00041 
00042         if ( $sSynchId && $sSynchId != $sId) {
00043             $sQAdd .= "and $sCountryTable.oxid not in ( select $sCountryTable.oxid from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid ";
00044             $sQAdd .= "and oxobject2discount.oxdiscountid = '$sSynchId' and oxobject2discount.oxtype = 'oxcountry' ) ";
00045         }
00046 
00047         return $sQAdd;
00048     }
00049 
00055     public function removedisccountry()
00056     {
00057         $aChosenCntr = $this->_getActionIds( 'oxobject2discount.oxid' );
00058         if ( oxConfig::getParameter( 'all' ) ) {
00059 
00060             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00061             oxDb::getDb()->Execute( $sQ );
00062 
00063         } elseif ( is_array( $aChosenCntr ) ) {
00064             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCntr ) ) . ") ";
00065             oxDb::getDb()->Execute( $sQ );
00066         }
00067     }
00068 
00074     public function adddisccountry()
00075     {
00076         $aChosenCntr = $this->_getActionIds( 'oxcountry.oxid' );
00077         $soxId       = oxConfig::getParameter( 'synchoxid');
00078 
00079         if ( oxConfig::getParameter( 'all' ) ) {
00080             $sCountryTable = getViewName('oxcountry');
00081             $aChosenCntr = $this->_getAll( $this->_addFilter( "select $sCountryTable.oxid ".$this->_getQuery() ) );
00082         }
00083         if ( $soxId && $soxId != "-1" && is_array( $aChosenCntr ) ) {
00084             foreach ( $aChosenCntr as $sChosenCntr) {
00085                 $oObject2Discount = oxNew( "oxbase" );
00086                 $oObject2Discount->init( 'oxobject2discount' );
00087                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00088                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenCntr);
00089                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxcountry");
00090                 $oObject2Discount->save();
00091             }
00092         }
00093     }
00094 }