delivery_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class delivery_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', 'oxobject2delivery', 0, 0, 1 )
00026                                         )
00027                                 );
00028 
00034     protected function _getQuery()
00035     {
00036         $sCountryTable = $this->_getViewName('oxcountry');
00037         $oDb = oxDb::getDb();
00038         $sId = $this->getConfig()->getRequestParameter( 'oxid' );
00039         $sSynchId = $this->getConfig()->getRequestParameter( 'synchoxid' );
00040 
00041         // category selected or not ?
00042         if ( !$sId) {
00043             $sQAdd  = " from $sCountryTable where $sCountryTable.oxactive = '1' ";
00044         } else {
00045             $sQAdd  = " from oxobject2delivery left join $sCountryTable on $sCountryTable.oxid=oxobject2delivery.oxobjectid ";
00046             $sQAdd .= " where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sId )." and oxobject2delivery.oxtype = 'oxcountry' ";
00047         }
00048 
00049         if ( $sSynchId && $sSynchId != $sId ) {
00050             $sQAdd .= " and $sCountryTable.oxid not in ( select $sCountryTable.oxid from oxobject2delivery left join $sCountryTable on $sCountryTable.oxid=oxobject2delivery.oxobjectid ";
00051             $sQAdd .= " where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sSynchId )." and oxobject2delivery.oxtype = 'oxcountry' ) ";
00052         }
00053 
00054         return $sQAdd;
00055     }
00056 
00062     public function removeCountryFromDel()
00063     {
00064         $aChosenCntr = $this->_getActionIds( 'oxobject2delivery.oxid' );
00065         if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00066 
00067             $sQ = $this->_addFilter( "delete oxobject2delivery.* ".$this->_getQuery() );
00068             oxDb::getDb()->Execute( $sQ );
00069 
00070         } elseif ( is_array( $aChosenCntr ) ) {
00071             $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCntr ) ) . ") ";
00072             oxDb::getDb()->Execute( $sQ );
00073         }
00074     }
00075 
00081     public function addCountryToDel()
00082     {
00083         $aChosenCntr = $this->_getActionIds( 'oxcountry.oxid' );
00084         $soxId       = $this->getConfig()->getRequestParameter( 'synchoxid');
00085 
00086         // adding
00087         if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00088             $sCountryTable = $this->_getViewName('oxcountry');
00089             $aChosenCntr = $this->_getAll( $this->_addFilter( "select $sCountryTable.oxid ".$this->_getQuery() ) );
00090         }
00091 
00092         if ( $soxId && $soxId != "-1" && is_array( $aChosenCntr ) ) {
00093             foreach ( $aChosenCntr as $sChosenCntr) {
00094                 $oObject2Delivery = oxNew( 'oxbase' );
00095                 $oObject2Delivery->init( 'oxobject2delivery' );
00096                 $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
00097                 $oObject2Delivery->oxobject2delivery__oxobjectid   = new oxField($sChosenCntr);
00098                 $oObject2Delivery->oxobject2delivery__oxtype       = new oxField('oxcountry');
00099                 $oObject2Delivery->save();
00100             }
00101         }
00102     }
00103 }