OXID eShop CE  4.10.3
 All Classes Namespaces Files Functions Variables Pages
voucherserie_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', 'oxobject2group', 0, 0, 1),
23  )
24  );
25 
31  protected function _getQuery()
32  {
33  // looking for table/view
34  $sGroupTable = $this->_getViewName('oxgroups');
35  $oDb = oxDb::getDb();
36  $oConfig = oxRegistry::getConfig();
37  $sVoucherId = $oConfig->getRequestParameter('oxid');
38  $sSynchVoucherId = $oConfig->getRequestParameter('synchoxid');
39 
40  // category selected or not ?
41  if (!$sVoucherId) {
42  $sQAdd = " from $sGroupTable where 1 ";
43  } else {
44  $sQAdd = " from $sGroupTable, oxobject2group where ";
45  $sQAdd .= " oxobject2group.oxobjectid = " . $oDb->quote($sVoucherId) . " and $sGroupTable.oxid = oxobject2group.oxgroupsid ";
46  }
47 
48  if ($sSynchVoucherId && $sSynchVoucherId != $sVoucherId) {
49  $sQAdd .= " and $sGroupTable.oxid not in ( select $sGroupTable.oxid from $sGroupTable, oxobject2group where ";
50  $sQAdd .= " oxobject2group.oxobjectid = " . $oDb->quote($sSynchVoucherId) . " and $sGroupTable.oxid = oxobject2group.oxgroupsid ) ";
51  }
52 
53  return $sQAdd;
54  }
55 
59  public function removeGroupFromVoucher()
60  {
61  $aRemoveGroups = $this->_getActionIds('oxobject2group.oxid');
62  if (oxRegistry::getConfig()->getRequestParameter('all')) {
63 
64  $sQ = $this->_addFilter("delete oxobject2group.* " . $this->_getQuery());
65  oxDb::getDb()->Execute($sQ);
66 
67  } elseif ($aRemoveGroups && is_array($aRemoveGroups)) {
68  $sQ = "delete from oxobject2group where oxobject2group.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aRemoveGroups)) . ") ";
69  oxDb::getDb()->Execute($sQ);
70  }
71  }
72 
76  public function addGroupToVoucher()
77  {
78  $oConfig = oxRegistry::getConfig();
79  $aChosenCat = $this->_getActionIds('oxgroups.oxid');
80  $soxId = $oConfig->getRequestParameter('synchoxid');
81 
82  if ($oConfig->getRequestParameter('all')) {
83  $sGroupTable = $this->_getViewName('oxgroups');
84  $aChosenCat = $this->_getAll($this->_addFilter("select $sGroupTable.oxid " . $this->_getQuery()));
85  }
86  if ($soxId && $soxId != "-1" && is_array($aChosenCat)) {
87  foreach ($aChosenCat as $sChosenCat) {
88  $oNewGroup = oxNew("oxobject2group");
89  $oNewGroup->oxobject2group__oxobjectid = new oxField($soxId);
90  $oNewGroup->oxobject2group__oxgroupsid = new oxField($sChosenCat);
91  $oNewGroup->save();
92  }
93  }
94  }
95 }