discount_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class discount_main_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_aColumns = array('container1' => array( // field , table,         visible, multilanguage, ident
00015         array('oxtitle', 'oxcountry', 1, 1, 0),
00016         array('oxisoalpha2', 'oxcountry', 1, 0, 0),
00017         array('oxisoalpha3', 'oxcountry', 0, 0, 0),
00018         array('oxunnum3', 'oxcountry', 0, 0, 0),
00019         array('oxid', 'oxcountry', 0, 0, 1)
00020     ),
00021                                  'container2' => array(
00022                                      array('oxtitle', 'oxcountry', 1, 1, 0),
00023                                      array('oxisoalpha2', 'oxcountry', 1, 0, 0),
00024                                      array('oxisoalpha3', 'oxcountry', 0, 0, 0),
00025                                      array('oxunnum3', 'oxcountry', 0, 0, 0),
00026                                      array('oxid', 'oxobject2discount', 0, 0, 1)
00027                                  )
00028     );
00029 
00035     protected function _getQuery()
00036     {
00037         $oConfig = $this->getConfig();
00038         $sCountryTable = $this->_getViewName('oxcountry');
00039         $oDb = oxDb::getDb();
00040         $sId = $oConfig->getRequestParameter('oxid');
00041         $sSynchId = $oConfig->getRequestParameter('synchoxid');
00042 
00043         // category selected or not ?
00044         if (!$sId) {
00045             $sQAdd = " from $sCountryTable where $sCountryTable.oxactive = '1' ";
00046         } else {
00047             $sQAdd = " from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid ";
00048             $sQAdd .= "and oxobject2discount.oxdiscountid = " . $oDb->quote($sId) . " and oxobject2discount.oxtype = 'oxcountry' ";
00049         }
00050 
00051         if ($sSynchId && $sSynchId != $sId) {
00052             $sQAdd .= "and $sCountryTable.oxid not in ( select $sCountryTable.oxid from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid ";
00053             $sQAdd .= "and oxobject2discount.oxdiscountid = " . $oDb->quote($sSynchId) . " and oxobject2discount.oxtype = 'oxcountry' ) ";
00054         }
00055 
00056         return $sQAdd;
00057     }
00058 
00062     public function removeDiscCountry()
00063     {
00064         $oConfig = $this->getConfig();
00065 
00066         $aChosenCntr = $this->_getActionIds('oxobject2discount.oxid');
00067         if ($oConfig->getRequestParameter('all')) {
00068 
00069             $sQ = $this->_addFilter("delete oxobject2discount.* " . $this->_getQuery());
00070             oxDb::getDb()->Execute($sQ);
00071 
00072         } elseif (is_array($aChosenCntr)) {
00073             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aChosenCntr)) . ") ";
00074             oxDb::getDb()->Execute($sQ);
00075         }
00076     }
00077 
00081     public function addDiscCountry()
00082     {
00083         $oConfig = $this->getConfig();
00084         $aChosenCntr = $this->_getActionIds('oxcountry.oxid');
00085         $soxId = $oConfig->getRequestParameter('synchoxid');
00086 
00087 
00088         if ($oConfig->getRequestParameter('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 }