OXID eShop CE  4.10.7
 All Classes Namespaces Files Functions Variables Pages
newsletter_selection_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  // active AJAX component
34  $sGroupTable = $this->_getViewName('oxgroups');
35  $oDb = oxDb::getDb();
36  $sDiscountId = $this->getConfig()->getRequestParameter('oxid');
37  $sSynchDiscountId = $this->getConfig()->getRequestParameter('synchoxid');
38 
39  // category selected or not ?
40  if (!$sDiscountId) {
41  $sQAdd = " from $sGroupTable where 1 ";
42  } else {
43  $sQAdd = " from oxobject2group left join $sGroupTable on oxobject2group.oxgroupsid=$sGroupTable.oxid ";
44  $sQAdd .= " where oxobject2group.oxobjectid = " . $oDb->quote($sDiscountId);
45  }
46 
47  if ($sSynchDiscountId && $sSynchDiscountId != $sDiscountId) {
48  $sQAdd .= " and $sGroupTable.oxid not in ( ";
49  $sQAdd .= " select $sGroupTable.oxid from oxobject2group left join $sGroupTable on oxobject2group.oxgroupsid=$sGroupTable.oxid ";
50  $sQAdd .= " where oxobject2group.oxobjectid = " . $oDb->quote($sSynchDiscountId) . " ) ";
51  }
52 
53  // creating AJAX component
54  return $sQAdd;
55  }
56 
60  public function removeGroupFromNewsletter()
61  {
62  $aRemoveGroups = $this->_getActionIds('oxobject2group.oxid');
63  if ($this->getConfig()->getRequestParameter('all')) {
64 
65  $sQ = $this->_addFilter("delete oxobject2group.* " . $this->_getQuery());
66  oxDb::getDb()->Execute($sQ);
67 
68  } elseif ($aRemoveGroups && is_array($aRemoveGroups)) {
69  $sQ = "delete from oxobject2group where oxobject2group.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aRemoveGroups)) . ") ";
70  oxDb::getDb()->Execute($sQ);
71  }
72  }
73 
77  public function addGroupToNewsletter()
78  {
79  $aAddGroups = $this->_getActionIds('oxgroups.oxid');
80  $soxId = $this->getConfig()->getRequestParameter('synchoxid');
81 
82  if ($this->getConfig()->getRequestParameter('all')) {
83  $sGroupTable = $this->_getViewName('oxgroups');
84  $aAddGroups = $this->_getAll($this->_addFilter("select $sGroupTable.oxid " . $this->_getQuery()));
85  }
86  if ($soxId && $soxId != "-1" && is_array($aAddGroups)) {
87  foreach ($aAddGroups as $sAddgroup) {
88  $oNewGroup = oxNew("oxobject2group");
89  $oNewGroup->oxobject2group__oxobjectid = new oxField($soxId);
90  $oNewGroup->oxobject2group__oxgroupsid = new oxField($sAddgroup);
91  $oNewGroup->save();
92  }
93  }
94  }
95 }