deliveryset_country_ajax.php

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