payment_country_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class payment_country_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', 'oxobject2payment', 0, 0, 1 )
00026                                         )
00027                                 );
00028 
00034     protected function _getQuery()
00035     {
00036         // looking for table/view
00037         $sCountryTable = $this->_getViewName('oxcountry');
00038         $oDb = oxDb::getDb();
00039         $sCountryId = $this->getConfig()->getRequestParameter( 'oxid' );
00040         $sSynchCountryId = $this->getConfig()->getRequestParameter( 'synchoxid' );
00041 
00042         // category selected or not ?
00043         if ( !$sCountryId) {
00044             // which fields to load ?
00045             $sQAdd = " from $sCountryTable where $sCountryTable.oxactive = '1' ";
00046         } else {
00047 
00048             $sQAdd  = " from oxobject2payment left join $sCountryTable on $sCountryTable.oxid=oxobject2payment.oxobjectid ";
00049             $sQAdd .= "where $sCountryTable.oxactive = '1' and oxobject2payment.oxpaymentid = ".$oDb->quote( $sCountryId )." and oxobject2payment.oxtype = 'oxcountry' ";
00050         }
00051 
00052         if ( $sSynchCountryId && $sSynchCountryId != $sCountryId ) {
00053             $sQAdd .= "and $sCountryTable.oxid not in ( ";
00054             $sQAdd .= "select $sCountryTable.oxid from oxobject2payment left join $sCountryTable on $sCountryTable.oxid=oxobject2payment.oxobjectid ";
00055             $sQAdd .= "where oxobject2payment.oxpaymentid = ".$oDb->quote( $sSynchCountryId )." and oxobject2payment.oxtype = 'oxcountry' ) ";
00056         }
00057 
00058         return $sQAdd;
00059     }
00060 
00066     public function addPayCountry()
00067     {
00068         $aChosenCntr = $this->_getActionIds( 'oxcountry.oxid' );
00069         $soxId       = $this->getConfig()->getRequestParameter( 'synchoxid');
00070 
00071         if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00072             $sCountryTable = $this->_getViewName('oxcountry');
00073             $aChosenCntr = $this->_getAll( $this->_addFilter( "select $sCountryTable.oxid ".$this->_getQuery() ) );
00074         }
00075         if ( $soxId && $soxId != "-1" && is_array( $aChosenCntr ) ) {
00076             foreach ( $aChosenCntr as $sChosenCntr) {
00077                 $oObject2Payment = oxNew( 'oxbase' );
00078                 $oObject2Payment->init( 'oxobject2payment' );
00079                 $oObject2Payment->oxobject2payment__oxpaymentid = new oxField($soxId);
00080                 $oObject2Payment->oxobject2payment__oxobjectid  = new oxField($sChosenCntr);
00081                 $oObject2Payment->oxobject2payment__oxtype      = new oxField("oxcountry");
00082                 $oObject2Payment->save();
00083             }
00084         }
00085     }
00086 
00092     public function removePayCountry()
00093     {
00094         $aChosenCntr = $this->_getActionIds( 'oxobject2payment.oxid' );
00095         if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00096 
00097             $sQ = $this->_addFilter( "delete oxobject2payment.* ".$this->_getQuery() );
00098             oxDb::getDb()->Execute( $sQ );
00099 
00100         } elseif ( is_array( $aChosenCntr ) ) {
00101             $sQ = "delete from oxobject2payment where oxobject2payment.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCntr ) ) . ") ";
00102             oxDb::getDb()->Execute( $sQ );
00103         }
00104     }
00105 }