OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
deliveryset_country_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_aColumns = array('container1' => array( // field , table, visible, multilanguage, ident
15  array('oxtitle', 'oxcountry', 1, 1, 0),
16  array('oxisoalpha2', 'oxcountry', 1, 0, 0),
17  array('oxisoalpha3', 'oxcountry', 0, 0, 0),
18  array('oxunnum3', 'oxcountry', 0, 0, 0),
19  array('oxid', 'oxcountry', 0, 0, 1)
20  ),
21  'container2' => array(
22  array('oxtitle', 'oxcountry', 1, 1, 0),
23  array('oxisoalpha2', 'oxcountry', 1, 0, 0),
24  array('oxisoalpha3', 'oxcountry', 0, 0, 0),
25  array('oxunnum3', 'oxcountry', 0, 0, 0),
26  array('oxid', 'oxobject2delivery', 0, 0, 1)
27  )
28  );
29 
35  protected function _getQuery()
36  {
37  $oDb = oxDb::getDb();
38  $sId = $this->getConfig()->getRequestParameter('oxid');
39  $sSynchId = $this->getConfig()->getRequestParameter('synchoxid');
40 
41  $sCountryTable = $this->_getViewName('oxcountry');
42 
43  // category selected or not ?
44  if (!$sId) {
45  $sQAdd = " from {$sCountryTable} where {$sCountryTable}.oxactive = '1' ";
46  } else {
47  $sQAdd = " from oxobject2delivery, {$sCountryTable} " .
48  "where oxobject2delivery.oxdeliveryid = " . $oDb->quote($sId) .
49  " and oxobject2delivery.oxobjectid = {$sCountryTable}.oxid " .
50  "and oxobject2delivery.oxtype = 'oxdelset' ";
51  }
52 
53  if ($sSynchId && $sSynchId != $sId) {
54  $sQAdd .= "and {$sCountryTable}.oxid not in ( select {$sCountryTable}.oxid " .
55  "from oxobject2delivery, {$sCountryTable} " .
56  "where oxobject2delivery.oxdeliveryid = " . $oDb->quote($sSynchId) .
57  "and oxobject2delivery.oxobjectid = {$sCountryTable}.oxid " .
58  "and oxobject2delivery.oxtype = 'oxdelset' ) ";
59  }
60 
61  return $sQAdd;
62  }
63 
67  public function removeCountryFromSet()
68  {
69  $aChosenCntr = $this->_getActionIds('oxobject2delivery.oxid');
70  // removing all
71  if ($this->getConfig()->getRequestParameter('all')) {
72 
73  $sQ = $this->_addFilter("delete oxobject2delivery.* " . $this->_getQuery());
74  oxDb::getDb()->Execute($sQ);
75 
76  } elseif (is_array($aChosenCntr)) {
77  $sChosenCountries = implode(", ", oxDb::getInstance()->quoteArray($aChosenCntr));
78  $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . $sChosenCountries . ") ";
79  oxDb::getDb()->Execute($sQ);
80  }
81  }
82 
86  public function addCountryToSet()
87  {
88  $aChosenCntr = $this->_getActionIds('oxcountry.oxid');
89  $soxId = $this->getConfig()->getRequestParameter('synchoxid');
90 
91  // adding
92  if ($this->getConfig()->getRequestParameter('all')) {
93  $sCountryTable = $this->_getViewName('oxcountry');
94  $aChosenCntr = $this->_getAll($this->_addFilter("select $sCountryTable.oxid " . $this->_getQuery()));
95  }
96 
97  if ($soxId && $soxId != "-1" && is_array($aChosenCntr)) {
98  foreach ($aChosenCntr as $sChosenCntr) {
99  $oObject2Delivery = oxNew('oxbase');
100  $oObject2Delivery->init('oxobject2delivery');
101  $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
102  $oObject2Delivery->oxobject2delivery__oxobjectid = new oxField($sChosenCntr);
103  $oObject2Delivery->oxobject2delivery__oxtype = new oxField("oxdelset");
104  $oObject2Delivery->save();
105  }
106  }
107  }
108 }