00001 <?php
00002
00006 class deliveryset_country_ajax extends ajaxListComponent
00007 {
00008
00014 protected $_aColumns = array('container1' => array(
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', 'oxobject2delivery', 0, 0, 1)
00027 )
00028 );
00029
00035 protected function _getQuery()
00036 {
00037 $oDb = oxDb::getDb();
00038 $sId = $this->getConfig()->getRequestParameter('oxid');
00039 $sSynchId = $this->getConfig()->getRequestParameter('synchoxid');
00040
00041 $sCountryTable = $this->_getViewName('oxcountry');
00042
00043
00044 if (!$sId) {
00045 $sQAdd = " from {$sCountryTable} where {$sCountryTable}.oxactive = '1' ";
00046 } else {
00047 $sQAdd = " from oxobject2delivery, {$sCountryTable} " .
00048 "where oxobject2delivery.oxdeliveryid = " . $oDb->quote($sId) .
00049 " and oxobject2delivery.oxobjectid = {$sCountryTable}.oxid " .
00050 "and oxobject2delivery.oxtype = 'oxdelset' ";
00051 }
00052
00053 if ($sSynchId && $sSynchId != $sId) {
00054 $sQAdd .= "and {$sCountryTable}.oxid not in ( select {$sCountryTable}.oxid " .
00055 "from oxobject2delivery, {$sCountryTable} " .
00056 "where oxobject2delivery.oxdeliveryid = " . $oDb->quote($sSynchId) .
00057 "and oxobject2delivery.oxobjectid = {$sCountryTable}.oxid " .
00058 "and oxobject2delivery.oxtype = 'oxdelset' ) ";
00059 }
00060
00061 return $sQAdd;
00062 }
00063
00067 public function removeCountryFromSet()
00068 {
00069 $aChosenCntr = $this->_getActionIds('oxobject2delivery.oxid');
00070
00071 if ($this->getConfig()->getRequestParameter('all')) {
00072
00073 $sQ = $this->_addFilter("delete oxobject2delivery.* " . $this->_getQuery());
00074 oxDb::getDb()->Execute($sQ);
00075
00076 } elseif (is_array($aChosenCntr)) {
00077 $sChosenCountries = implode(", ", oxDb::getInstance()->quoteArray($aChosenCntr));
00078 $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . $sChosenCountries . ") ";
00079 oxDb::getDb()->Execute($sQ);
00080 }
00081 }
00082
00086 public function addCountryToSet()
00087 {
00088 $aChosenCntr = $this->_getActionIds('oxcountry.oxid');
00089 $soxId = $this->getConfig()->getRequestParameter('synchoxid');
00090
00091
00092 if ($this->getConfig()->getRequestParameter('all')) {
00093 $sCountryTable = $this->_getViewName('oxcountry');
00094 $aChosenCntr = $this->_getAll($this->_addFilter("select $sCountryTable.oxid " . $this->_getQuery()));
00095 }
00096
00097 if ($soxId && $soxId != "-1" && is_array($aChosenCntr)) {
00098 foreach ($aChosenCntr as $sChosenCntr) {
00099 $oObject2Delivery = oxNew('oxbase');
00100 $oObject2Delivery->init('oxobject2delivery');
00101 $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
00102 $oObject2Delivery->oxobject2delivery__oxobjectid = new oxField($sChosenCntr);
00103 $oObject2Delivery->oxobject2delivery__oxtype = new oxField("oxdelset");
00104 $oObject2Delivery->save();
00105 }
00106 }
00107 }
00108 }