OXID eShop CE  4.9.7
 All Classes Files Functions Variables Pages
discount_users_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('oxusername', 'oxuser', 1, 0, 0),
16  array('oxlname', 'oxuser', 0, 0, 0),
17  array('oxfname', 'oxuser', 0, 0, 0),
18  array('oxstreet', 'oxuser', 0, 0, 0),
19  array('oxstreetnr', 'oxuser', 0, 0, 0),
20  array('oxcity', 'oxuser', 0, 0, 0),
21  array('oxzip', 'oxuser', 0, 0, 0),
22  array('oxfon', 'oxuser', 0, 0, 0),
23  array('oxbirthdate', 'oxuser', 0, 0, 0),
24  array('oxid', 'oxuser', 0, 0, 1),
25  ),
26  'container2' => array(
27  array('oxusername', 'oxuser', 1, 0, 0),
28  array('oxlname', 'oxuser', 0, 0, 0),
29  array('oxfname', 'oxuser', 0, 0, 0),
30  array('oxstreet', 'oxuser', 0, 0, 0),
31  array('oxstreetnr', 'oxuser', 0, 0, 0),
32  array('oxcity', 'oxuser', 0, 0, 0),
33  array('oxzip', 'oxuser', 0, 0, 0),
34  array('oxfon', 'oxuser', 0, 0, 0),
35  array('oxbirthdate', 'oxuser', 0, 0, 0),
36  array('oxid', 'oxobject2discount', 0, 0, 1),
37  )
38  );
39 
45  protected function _getQuery()
46  {
47  $oConfig = $this->getConfig();
48 
49  $sUserTable = $this->_getViewName('oxuser');
50  $oDb = oxDb::getDb();
51  $sId = $oConfig->getRequestParameter('oxid');
52  $sSynchId = $oConfig->getRequestParameter('synchoxid');
53 
54  // category selected or not ?
55  if (!$sId) {
56  $sQAdd = " from $sUserTable where 1 ";
57  if (!$oConfig->getConfigParam('blMallUsers')) {
58  $sQAdd .= " and oxshopid = '" . $oConfig->getShopId() . "' ";
59  }
60  } else {
61  // selected group ?
62  if ($sSynchId && $sSynchId != $sId) {
63  $sQAdd = " from oxobject2group left join $sUserTable on $sUserTable.oxid = oxobject2group.oxobjectid where oxobject2group.oxgroupsid = " . $oDb->quote($sId);
64  if (!$oConfig->getConfigParam('blMallUsers')) {
65  $sQAdd .= " and $sUserTable.oxshopid = '" . $oConfig->getShopId() . "' ";
66  }
67 
68  } else {
69  $sQAdd = " from oxobject2discount, $sUserTable where $sUserTable.oxid=oxobject2discount.oxobjectid ";
70  $sQAdd .= " and oxobject2discount.oxdiscountid = " . $oDb->quote($sId) . " and oxobject2discount.oxtype = 'oxuser' ";
71  }
72  }
73 
74  if ($sSynchId && $sSynchId != $sId) {
75  $sQAdd .= " and $sUserTable.oxid not in ( select $sUserTable.oxid from oxobject2discount, $sUserTable where $sUserTable.oxid=oxobject2discount.oxobjectid ";
76  $sQAdd .= " and oxobject2discount.oxdiscountid = " . $oDb->quote($sSynchId) . " and oxobject2discount.oxtype = 'oxuser' ) ";
77  }
78 
79  return $sQAdd;
80  }
81 
85  public function removeDiscUser()
86  {
87  $oConfig = $this->getConfig();
88 
89  $aRemoveGroups = $this->_getActionIds('oxobject2discount.oxid');
90  if ($oConfig->getRequestParameter('all')) {
91 
92  $sQ = $this->_addFilter("delete oxobject2discount.* " . $this->_getQuery());
93  oxDb::getDb()->Execute($sQ);
94 
95  } elseif ($aRemoveGroups && is_array($aRemoveGroups)) {
96  $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aRemoveGroups)) . ") ";
97  oxDb::getDb()->Execute($sQ);
98  }
99  }
100 
104  public function addDiscUser()
105  {
106  $oConfig = $this->getConfig();
107  $aChosenUsr = $this->_getActionIds('oxuser.oxid');
108  $soxId = $oConfig->getRequestParameter('synchoxid');
109 
110 
111  if ($oConfig->getRequestParameter('all')) {
112  $sUserTable = $this->_getViewName('oxuser');
113  $aChosenUsr = $this->_getAll($this->_addFilter("select $sUserTable.oxid " . $this->_getQuery()));
114  }
115  if ($soxId && $soxId != "-1" && is_array($aChosenUsr)) {
116  foreach ($aChosenUsr as $sChosenUsr) {
117  $oObject2Discount = oxNew("oxbase");
118  $oObject2Discount->init('oxobject2discount');
119  $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
120  $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenUsr);
121  $oObject2Discount->oxobject2discount__oxtype = new oxField("oxuser");
122  $oObject2Discount->save();
123  }
124  }
125  }
126 }