OXID eShop CE  4.9.10
 All Classes Files Functions Variables Pages
newsletter_selection.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
16  protected $_iUserCount = null;
17 
25  public function render()
26  {
28 
29  $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
30  if ($soxId != "-1" && isset($soxId)) {
31  // load object
32  $oNewsletter = oxNew("oxnewsletter");
33  if ($oNewsletter->load($soxId)) {
34  $this->_aViewData["edit"] = $oNewsletter;
35 
36  if (oxRegistry::getConfig()->getRequestParameter("aoc")) {
37  $oNewsletterSelectionAjax = oxNew('newsletter_selection_ajax');
38  $this->_aViewData['oxajax'] = $oNewsletterSelectionAjax->getColumns();
39 
40  return "popups/newsletter_selection.tpl";
41  }
42  }
43  }
44 
45  return "newsletter_selection.tpl";
46  }
47 
53  public function getUserCount()
54  {
55  if ($this->_iUserCount === null) {
56  $this->_iUserCount = 0;
57 
58  // load object
59  $oNewsletter = oxNew("oxnewsletter");
60  if ($oNewsletter->load($this->getEditObjectId())) {
61  // get nr. of users in these groups
62  // we do not use lists here as we dont need this overhead right now
63  $oDB = oxDb::getDb();
64  $blSep = false;
65  $sSelectGroups = " ( oxobject2group.oxgroupsid in ( ";
66 
67  // remove already added groups
68  foreach ($oNewsletter->getGroups() as $oInGroup) {
69  if ($blSep) {
70  $sSelectGroups .= ",";
71  }
72  $sSelectGroups .= $oDB->quote($oInGroup->oxgroups__oxid->value);
73  $blSep = true;
74  }
75 
76  $sSelectGroups .= " ) ) ";
77 
78  // no group selected
79  if (!$blSep) {
80  $sSelectGroups = " oxobject2group.oxobjectid is null ";
81  }
82  $sShopId = $this->getConfig()->getShopID();
83  $sQ = "select count(*) from ( select oxnewssubscribed.oxemail as _icnt from oxnewssubscribed left join
84  oxobject2group on oxobject2group.oxobjectid = oxnewssubscribed.oxuserid
85  where ( oxobject2group.oxshopid = '{$sShopId}'
86  or oxobject2group.oxshopid is null ) and {$sSelectGroups} and
87  oxnewssubscribed.oxdboptin = 1 and ( not ( oxnewssubscribed.oxemailfailed = '1') )
88  and (not(oxnewssubscribed.oxemailfailed = '1')) and oxnewssubscribed.oxshopid = '{$sShopId}'
89  group by oxnewssubscribed.oxemail ) as _tmp";
90 
91  $this->_iUserCount = $oDB->getOne($sQ, false, false);
92  }
93  }
94 
95  return $this->_iUserCount;
96  }
97 
101  public function save()
102  {
103  $soxId = $this->getEditObjectId();
104  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
105  $aParams['oxnewsletter__oxshopid'] = $this->getConfig()->getShopId();
106 
107  $oNewsletter = oxNew("oxNewsLetter");
108  if ($soxId != "-1") {
109  $oNewsletter->load($soxId);
110  } else {
111  $aParams['oxnewsletter__oxid'] = null;
112  }
113 
114  $oNewsletter->assign($aParams);
115  $oNewsletter->save();
116 
117  // set oxid if inserted
118  $this->setEditObjectId($oNewsletter->getId());
119  }
120 }