OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
discount_groups_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( 'oxtitle', 'oxgroups', 1, 0, 0 ),
15  array( 'oxid', 'oxgroups', 0, 0, 0 ),
16  array( 'oxid', 'oxgroups', 0, 0, 1 ),
17  ),
18  'container2' => array(
19  array( 'oxtitle', 'oxgroups', 1, 0, 0 ),
20  array( 'oxid', 'oxgroups', 0, 0, 0 ),
21  array( 'oxid', 'oxobject2discount', 0, 0, 1 ),
22  )
23  );
24 
30  protected function _getQuery()
31  {
32  $oConfig = $this->getConfig();
33  // active AJAX component
34  $sGroupTable = $this->_getViewName('oxgroups');
35  $oDb = oxDb::getDb();
36  $sId = $oConfig->getRequestParameter( 'oxid' );
37  $sSynchId = $oConfig->getRequestParameter( 'synchoxid' );
38 
39  // category selected or not ?
40  if ( !$sId) {
41  $sQAdd = " from $sGroupTable where 1 ";
42  } else {
43  $sQAdd .= " from oxobject2discount, $sGroupTable where $sGroupTable.oxid=oxobject2discount.oxobjectid ";
44  $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sId )." and oxobject2discount.oxtype = 'oxgroups' ";
45  }
46 
47  if ( $sSynchId && $sSynchId != $sId) {
48  $sQAdd .= " and $sGroupTable.oxid not in ( select $sGroupTable.oxid from oxobject2discount, $sGroupTable where $sGroupTable.oxid=oxobject2discount.oxobjectid ";
49  $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchId )." and oxobject2discount.oxtype = 'oxgroups' ) ";
50  }
51 
52  return $sQAdd;
53  }
54 
60  public function removeDiscGroup()
61  {
62  $oConfig = $this->getConfig();
63 
64  $aRemoveGroups = $this->_getActionIds( 'oxobject2discount.oxid' );
65  if ( $oConfig->getRequestParameter( 'all' ) ) {
66 
67  $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
68  oxDb::getDb()->Execute( $sQ );
69 
70  } elseif ( $aRemoveGroups && is_array( $aRemoveGroups ) ) {
71  $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aRemoveGroups ) ) . ") ";
72  oxDb::getDb()->Execute( $sQ );
73  }
74  }
75 
81  public function addDiscGroup()
82  {
83  $oConfig = $this->getConfig();
84  $aChosenCat = $this->_getActionIds( 'oxgroups.oxid' );
85  $soxId = $oConfig->getRequestParameter( 'synchoxid' );
86 
87 
88  if ( $oConfig->getRequestParameter( 'all' ) ) {
89  $sGroupTable = $this->_getViewName('oxgroups');
90  $aChosenCat = $this->_getAll( $this->_addFilter( "select $sGroupTable.oxid ".$this->_getQuery() ) );
91  }
92  if ( $soxId && $soxId != "-1" && is_array( $aChosenCat ) ) {
93  foreach ( $aChosenCat as $sChosenCat) {
94  $oObject2Discount = oxNew( "oxbase" );
95  $oObject2Discount->init( 'oxobject2discount' );
96  $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
97  $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenCat);
98  $oObject2Discount->oxobject2discount__oxtype = new oxField("oxgroups");
99  $oObject2Discount->save();
100  }
101  }
102  }
103 }