OXID eShop CE  4.10.7
 All Classes Namespaces Files Functions Variables Pages
delivery_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', 'oxobject2delivery', 0, 0, 1),
25  array('oxid', 'oxcategories', 0, 0, 1)
26  ),
27  );
28 
34  protected function _getQuery()
35  {
36  // looking for table/view
37  $sCatTable = $this->_getViewName('oxcategories');
38  $oDb = oxDb::getDb();
39  $sDelId = $this->getConfig()->getRequestParameter('oxid');
40  $sSynchDelId = $this->getConfig()->getRequestParameter('synchoxid');
41 
42  // category selected or not ?
43  if (!$sDelId) {
44  $sQAdd = " from {$sCatTable} ";
45  } else {
46  $sQAdd = " from oxobject2delivery left join {$sCatTable} " .
47  "on {$sCatTable}.oxid=oxobject2delivery.oxobjectid " .
48  " where oxobject2delivery.oxdeliveryid = " . $oDb->quote($sDelId) .
49  " and oxobject2delivery.oxtype = 'oxcategories' ";
50  }
51 
52  if ($sSynchDelId && $sSynchDelId != $sDelId) {
53  // performance
54  $sSubSelect = " select {$sCatTable}.oxid from oxobject2delivery left join {$sCatTable} " .
55  "on {$sCatTable}.oxid=oxobject2delivery.oxobjectid " .
56  " where oxobject2delivery.oxdeliveryid = " . $oDb->quote($sSynchDelId) .
57  " and oxobject2delivery.oxtype = 'oxcategories' ";
58  if (stristr($sQAdd, 'where') === false) {
59  $sQAdd .= ' where ';
60  } else {
61  $sQAdd .= ' and ';
62  }
63  $sQAdd .= " {$sCatTable}.oxid not in ( $sSubSelect ) ";
64  }
65 
66  return $sQAdd;
67  }
68 
72  public function removeCatFromDel()
73  {
74  $aChosenCat = $this->_getActionIds('oxobject2delivery.oxid');
75 
76  // removing all
77  if ($this->getConfig()->getRequestParameter('all')) {
78 
79  $sQ = $this->_addFilter("delete oxobject2delivery.* " . $this->_getQuery());
80  oxDb::getDb()->Execute($sQ);
81 
82  } elseif (is_array($aChosenCat)) {
83  $sChosenCategoriess = implode(", ", oxDb::getInstance()->quoteArray($aChosenCat));
84  $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . $sChosenCategoriess . ") ";
85  oxDb::getDb()->Execute($sQ);
86  }
87  }
88 
92  public function addCatToDel()
93  {
94  $aChosenCat = $this->_getActionIds('oxcategories.oxid');
95  $soxId = $this->getConfig()->getRequestParameter('synchoxid');
96 
97  // adding
98  if ($this->getConfig()->getRequestParameter('all')) {
99  $sCatTable = $this->_getViewName('oxcategories');
100  $aChosenCat = $this->_getAll($this->_addFilter("select $sCatTable.oxid " . $this->_getQuery()));
101  }
102 
103  if (isset($soxId) && $soxId != "-1" && isset($aChosenCat) && $aChosenCat) {
104  foreach ($aChosenCat as $sChosenCat) {
105  $oObject2Delivery = oxNew('oxbase');
106  $oObject2Delivery->init('oxobject2delivery');
107  $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
108  $oObject2Delivery->oxobject2delivery__oxobjectid = new oxField($sChosenCat);
109  $oObject2Delivery->oxobject2delivery__oxtype = new oxField("oxcategories");
110  $oObject2Delivery->save();
111  }
112  }
113  }
114 }