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