OXID eShop CE  4.9.11
 All Classes Files Functions Variables Pages
news_main_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('oxtitle', 'oxgroups', 1, 0, 0),
16  array('oxid', 'oxgroups', 0, 0, 0),
17  array('oxid', 'oxgroups', 0, 0, 1),
18  ),
19  'container2' => array(
20  array('oxtitle', 'oxgroups', 1, 0, 0),
21  array('oxid', 'oxgroups', 0, 0, 0),
22  array('oxid', 'oxobject2group', 0, 0, 1),
23  )
24  );
25 
31  protected function _getQuery()
32  {
33  // active AJAX component
34  $sGroupTable = $this->_getViewName('oxgroups');
35  $oDb = oxDb::getDb();
36  $sDiscountId = $this->getConfig()->getRequestParameter('oxid');
37  $sSynchDiscountId = $this->getConfig()->getRequestParameter('synchoxid');
38 
39  // category selected or not ?
40  if (!$sDiscountId) {
41  $sQAdd = " from $sGroupTable where 1 ";
42  } else {
43  $sQAdd = " from oxobject2group left join $sGroupTable on oxobject2group.oxgroupsid=$sGroupTable.oxid ";
44  $sQAdd .= " where oxobject2group.oxobjectid = " . $oDb->quote($sDiscountId);
45  }
46 
47  if ($sSynchDiscountId && $sSynchDiscountId != $sDiscountId) {
48  $sQAdd .= ' and ' . $sGroupTable . '.oxid not in ( select ' . $sGroupTable . '.oxid from oxobject2group left join ' . $sGroupTable . ' on oxobject2group.oxgroupsid=' . $sGroupTable . '.oxid ';
49  $sQAdd .= " where oxobject2group.oxobjectid = " . $oDb->quote($sSynchDiscountId) . " ) ";
50  }
51 
52  return $sQAdd;
53  }
54 
58  public function removeGroupFromNews()
59  {
60  $aRemoveGroups = $this->_getActionIds('oxobject2group.oxid');
61  if ($this->getConfig()->getRequestParameter('all')) {
62 
63  $sQ = $this->_addFilter("delete oxobject2group.* " . $this->_getQuery());
64  oxDb::getDb()->Execute($sQ);
65 
66  } elseif ($aRemoveGroups && is_array($aRemoveGroups)) {
67  $sQ = "delete from oxobject2group where oxobject2group.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aRemoveGroups)) . ") ";
68  oxDb::getDb()->Execute($sQ);
69  }
70  }
71 
75  public function addGroupToNews()
76  {
77  $aAddGroups = $this->_getActionIds('oxgroups.oxid');
78  $soxId = $this->getConfig()->getRequestParameter('synchoxid');
79 
80  if ($this->getConfig()->getRequestParameter('all')) {
81  $sGroupTable = $this->_getViewName('oxgroups');
82  $aAddGroups = $this->_getAll($this->_addFilter("select $sGroupTable.oxid " . $this->_getQuery()));
83  }
84  if ($soxId && $soxId != "-1" && is_array($aAddGroups)) {
85  foreach ($aAddGroups as $sAddgroup) {
86  $oNewGroup = oxNew("oxobject2group");
87  $oNewGroup->oxobject2group__oxobjectid = new oxField($soxId);
88  $oNewGroup->oxobject2group__oxgroupsid = new oxField($sAddgroup);
89  $oNewGroup->save();
90  }
91  }
92  }
93 }