OXID eShop CE  4.10.5
 All Classes Namespaces Files Functions Variables Pages
discount_categories_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', 'oxcategories', 1, 1, 0),
16  array('oxdesc', 'oxcategories', 1, 1, 0),
17  array('oxid', 'oxcategories', 0, 0, 0),
18  array('oxid', 'oxcategories', 0, 0, 1)
19  ),
20  'container2' => array(
21  array('oxtitle', 'oxcategories', 1, 1, 0),
22  array('oxdesc', 'oxcategories', 1, 1, 0),
23  array('oxid', 'oxcategories', 0, 0, 0),
24  array('oxid', 'oxobject2discount', 0, 0, 1),
25  array('oxid', 'oxcategories', 0, 0, 1)
26  ),
27  );
28 
34  protected function _getQuery()
35  {
36  $oDb = oxDb::getDb();
37  $oConfig = $this->getConfig();
38  $sId = $oConfig->getRequestParameter('oxid');
39  $sSynchId = $oConfig->getRequestParameter('synchoxid');
40 
41  $sCategoryTable = $this->_getViewName('oxcategories');
42 
43  // category selected or not ?
44  if (!$sId) {
45  $sQAdd = " from {$sCategoryTable}";
46  } else {
47  $sQAdd = " from oxobject2discount, {$sCategoryTable} " .
48  "where {$sCategoryTable}.oxid=oxobject2discount.oxobjectid " .
49  " and oxobject2discount.oxdiscountid = " . $oDb->quote($sId) .
50  " and oxobject2discount.oxtype = 'oxcategories' ";
51  }
52 
53  if ($sSynchId && $sSynchId != $sId) {
54  // performance
55  $sSubSelect = " select {$sCategoryTable}.oxid from oxobject2discount, {$sCategoryTable} " .
56  "where {$sCategoryTable}.oxid=oxobject2discount.oxobjectid " .
57  " and oxobject2discount.oxdiscountid = " . $oDb->quote($sSynchId) .
58  " and oxobject2discount.oxtype = 'oxcategories' ";
59  if (stristr($sQAdd, 'where') === false) {
60  $sQAdd .= ' where ';
61  } else {
62  $sQAdd .= ' and ';
63  }
64  $sQAdd .= " {$sCategoryTable}.oxid not in ( $sSubSelect ) ";
65  }
66 
67  return $sQAdd;
68  }
69 
73  public function removeDiscCat()
74  {
75  $oConfig = $this->getConfig();
76  $aChosenCat = $this->_getActionIds('oxobject2discount.oxid');
77 
78 
79  if ($oConfig->getRequestParameter('all')) {
80 
81  $sQ = $this->_addFilter("delete oxobject2discount.* " . $this->_getQuery());
82  oxDb::getDb()->Execute($sQ);
83 
84  } elseif (is_array($aChosenCat)) {
85  $sChosenCategories = implode(", ", oxDb::getInstance()->quoteArray($aChosenCat));
86  $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . $sChosenCategories . ") ";
87  oxDb::getDb()->Execute($sQ);
88  }
89  }
90 
94  public function addDiscCat()
95  {
96  $oConfig = $this->getConfig();
97  $aChosenCat = $this->_getActionIds('oxcategories.oxid');
98  $soxId = $oConfig->getRequestParameter('synchoxid');
99 
100 
101  if ($oConfig->getRequestParameter('all')) {
102  $sCategoryTable = $this->_getViewName('oxcategories');
103  $aChosenCat = $this->_getAll($this->_addFilter("select $sCategoryTable.oxid " . $this->_getQuery()));
104  }
105  if ($soxId && $soxId != "-1" && is_array($aChosenCat)) {
106  foreach ($aChosenCat as $sChosenCat) {
107  $oObject2Discount = oxNew("oxbase");
108  $oObject2Discount->init('oxobject2discount');
109  $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
110  $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenCat);
111  $oObject2Discount->oxobject2discount__oxtype = new oxField("oxcategories");
112  $oObject2Discount->save();
113  }
114  }
115 
116  }
117 }