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