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