OXID eShop CE  4.10.5
 All Classes Namespaces Files Functions Variables Pages
newsletter_send.php
Go to the documentation of this file.
1 <?php
2 
8 {
9 
15  protected $_aMailErrors = array();
16 
24  public function render()
25  {
27 
28  // calculating
29  $iUserCount = $this->getUserCount();
30 
31  $iStart = (int) oxRegistry::getConfig()->getRequestParameter("iStart");
32 
33  $oNewsletter = oxNew("oxNewsLetter");
34  $oNewsletter->load($this->getEditObjectId());
35  $oNewsletterGroups = $oNewsletter->getGroups();
36 
37  // send emails....
38  $oDB = oxDb::getDb(oxDB::FETCH_MODE_ASSOC);
39  $sQGroups = " ( oxobject2group.oxgroupsid in ( ";
40  $blSep = false;
41  foreach ($oNewsletterGroups as $sInGroup) {
42  $sSearchKey = $sInGroup->oxgroups__oxid->value;
43  if ($blSep) {
44  $sQGroups .= ",";
45  }
46  $sQGroups .= $oDB->quote($sSearchKey);
47  $blSep = true;
48  }
49  $sQGroups .= ") )";
50 
51  // no group selected
52  if (!$blSep) {
53  $sQGroups = " oxobject2group.oxobjectid is null ";
54  }
55 
56  $myConfig = $this->getConfig();
57 
58  $iSendCnt = 0;
59  $iMaxCnt = (int) $myConfig->getConfigParam('iCntofMails');
60  $sShopId = $myConfig->getShopId();
61 
62  $sQ = "select oxnewssubscribed.oxuserid, oxnewssubscribed.oxemail, oxnewssubscribed.oxsal,
63  oxnewssubscribed.oxfname, oxnewssubscribed.oxlname, oxnewssubscribed.oxemailfailed
64  from oxnewssubscribed left join oxobject2group on
65  oxobject2group.oxobjectid = oxnewssubscribed.oxuserid where
66  ( oxobject2group.oxshopid = '{$sShopId}' or oxobject2group.oxshopid is null ) and
67  $sQGroups and oxnewssubscribed.oxdboptin = 1 and oxnewssubscribed.oxshopid = '{$sShopId}'
68  group by oxnewssubscribed.oxemail";
69 
70  $oRs = $oDB->selectLimit($sQ, 100, $iStart);
71  $blContinue = ($oRs != false && $oRs->recordCount() > 0);
72 
73  if ($blContinue) {
74  $blLoadAction = $myConfig->getConfigParam('bl_perfLoadAktion');
75  while (!$oRs->EOF && $iSendCnt < $iMaxCnt) {
76 
77  if ($oRs->fields['oxemailfailed'] != "1") {
78  $sUserId = $oRs->fields['oxuserid'];
79  $iSendCnt++;
80 
81  // must check if such user is in DB
82  if (!$oDB->getOne("select oxid from oxuser where oxid = " . $oDB->quote($sUserId), false, false)) {
83  $sUserId = null;
84  }
85 
86  // #559
87  if (!isset($sUserId) || !$sUserId) {
88  // there is no user object so we fake one
89  $oUser = oxNew("oxuser");
90  $oUser->oxuser__oxusername = new oxField($oRs->fields['oxemail']);
91  $oUser->oxuser__oxsal = new oxField($oRs->fields['oxsal']);
92  $oUser->oxuser__oxfname = new oxField($oRs->fields['oxfname']);
93  $oUser->oxuser__oxlname = new oxField($oRs->fields['oxlname']);
94  $oNewsletter->prepare($oUser, $blLoadAction);
95  } else {
96  $oNewsletter->prepare($sUserId, $blLoadAction);
97  }
98 
99  if ($oNewsletter->send($iSendCnt)) {
100  // add user history
101  $oRemark = oxNew("oxremark");
102  $oRemark->oxremark__oxtext = new oxField($oNewsletter->getPlainText());
103  $oRemark->oxremark__oxparentid = new oxField($sUserId);
104  $oRemark->oxremark__oxshopid = new oxField($sShopId);
105  $oRemark->oxremark__oxtype = new oxField("n");
106  $oRemark->save();
107  } else {
108  $this->_aMailErrors[] = "problem sending to : " . $oRs->fields['oxemail'];
109  }
110  }
111 
112  $oRs->moveNext();
113  $iStart++;
114  }
115  }
116 
117  $iSend = $iSendCnt + (ceil($iStart / $iMaxCnt) - 1) * $iMaxCnt;
118  $iSend = $iSend > $iUserCount ? $iUserCount : $iSend;
119 
120  $this->_aViewData["iStart"] = $iStart;
121  $this->_aViewData["iSend"] = $iSend;
122 
123  // end ?
124  if ($blContinue) {
125  return "newsletter_send.tpl";
126  } else {
127  $this->resetUserCount();
128 
129  return "newsletter_done.tpl";
130  }
131  }
132 
138  public function getUserCount()
139  {
140  $iCnt = oxRegistry::getSession()->getVariable("iUserCount");
141  if ($iCnt === null) {
142  $iCnt = parent::getUserCount();
143  oxRegistry::getSession()->setVariable("iUserCount", $iCnt);
144  }
145 
146  return $iCnt;
147  }
148 
152  public function resetUserCount()
153  {
154  oxRegistry::getSession()->deleteVariable("iUserCount");
155  $this->_iUserCount = null;
156  }
157 
163  public function getMailErrors()
164  {
165  return $this->_aMailErrors;
166  }
167 
173  protected function _setupNavigation($sNode)
174  {
175  $sNode = 'newsletter_list';
176 
177  $myAdminNavig = $this->getNavigation();
178 
179  // active tab
180  $iActTab = 3;
181 
182  // tabs
183  $this->_aViewData['editnavi'] = $myAdminNavig->getTabs($sNode, $iActTab);
184 
185  // active tab
186  $this->_aViewData['actlocation'] = $myAdminNavig->getActiveTab($sNode, $iActTab);
187 
188  // default tab
189  $this->_aViewData['default_edit'] = $myAdminNavig->getActiveTab($sNode, $this->_iDefEdit);
190 
191  // passign active tab number
192  $this->_aViewData['actedit'] = $iActTab;
193  }
194 
198  public function getListSorting()
199  {
200  }
201 }