OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
discount_groups_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', 'oxgroups', 1, 0, 0),
16  array('oxid', 'oxgroups', 0, 0, 0),
17  array('oxid', 'oxgroups', 0, 0, 1),
18  ),
19  'container2' => array(
20  array('oxtitle', 'oxgroups', 1, 0, 0),
21  array('oxid', 'oxgroups', 0, 0, 0),
22  array('oxid', 'oxobject2discount', 0, 0, 1),
23  )
24  );
25 
31  protected function _getQuery()
32  {
33  $oConfig = $this->getConfig();
34  // active AJAX component
35  $sGroupTable = $this->_getViewName('oxgroups');
36  $oDb = oxDb::getDb();
37  $sId = $oConfig->getRequestParameter('oxid');
38  $sSynchId = $oConfig->getRequestParameter('synchoxid');
39 
40  // category selected or not ?
41  if (!$sId) {
42  $sQAdd = " from {$sGroupTable} where 1 ";
43  } else {
44  $sQAdd .= " from oxobject2discount, {$sGroupTable} where {$sGroupTable}.oxid=oxobject2discount.oxobjectid ";
45  $sQAdd .= " and oxobject2discount.oxdiscountid = " . $oDb->quote($sId) .
46  " and oxobject2discount.oxtype = 'oxgroups' ";
47  }
48 
49  if ($sSynchId && $sSynchId != $sId) {
50  $sQAdd .= " and {$sGroupTable}.oxid not in ( select {$sGroupTable}.oxid " .
51  "from oxobject2discount, {$sGroupTable} where {$sGroupTable}.oxid=oxobject2discount.oxobjectid " .
52  " and oxobject2discount.oxdiscountid = " . $oDb->quote($sSynchId) .
53  " and oxobject2discount.oxtype = 'oxgroups' ) ";
54  }
55 
56  return $sQAdd;
57  }
58 
62  public function removeDiscGroup()
63  {
64  $oConfig = $this->getConfig();
65 
66  $aRemoveGroups = $this->_getActionIds('oxobject2discount.oxid');
67  if ($oConfig->getRequestParameter('all')) {
68 
69  $sQ = $this->_addFilter("delete oxobject2discount.* " . $this->_getQuery());
70  oxDb::getDb()->Execute($sQ);
71 
72  } elseif ($aRemoveGroups && is_array($aRemoveGroups)) {
73  $sRemoveGroups = implode(", ", oxDb::getInstance()->quoteArray($aRemoveGroups));
74  $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . $sRemoveGroups . ") ";
75  oxDb::getDb()->Execute($sQ);
76  }
77  }
78 
82  public function addDiscGroup()
83  {
84  $oConfig = $this->getConfig();
85  $aChosenCat = $this->_getActionIds('oxgroups.oxid');
86  $soxId = $oConfig->getRequestParameter('synchoxid');
87 
88 
89  if ($oConfig->getRequestParameter('all')) {
90  $sGroupTable = $this->_getViewName('oxgroups');
91  $aChosenCat = $this->_getAll($this->_addFilter("select $sGroupTable.oxid " . $this->_getQuery()));
92  }
93  if ($soxId && $soxId != "-1" && is_array($aChosenCat)) {
94  foreach ($aChosenCat as $sChosenCat) {
95  $oObject2Discount = oxNew("oxbase");
96  $oObject2Discount->init('oxobject2discount');
97  $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
98  $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenCat);
99  $oObject2Discount->oxobject2discount__oxtype = new oxField("oxgroups");
100  $oObject2Discount->save();
101  }
102  }
103  }
104 }