OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
oxnewsletter.php
Go to the documentation of this file.
1 <?php
2 
9 class oxNewsletter extends oxBase
10 {
11 
17  protected $_sHtmlText = null;
18 
24  protected $_sPlainText = null;
25 
31  protected $_oGroups = null;
32 
38  protected $_oUser = null;
39 
45  protected $_sClassName = 'oxnewsletter';
46 
51  public function __construct()
52  {
54  $this->init('oxnewsletter');
55  }
56 
64  public function delete($sOxId = null)
65  {
66  if (!$sOxId) {
67  $sOxId = $this->getId();
68  }
69  if (!$sOxId) {
70  return false;
71  }
72 
73  $blDeleted = parent::delete($sOxId);
74 
75  if ($blDeleted) {
76  $oDb = oxDb::getDb();
77  $sDelete = "delete from oxobject2group where oxobject2group.oxshopid = '" . $this->getShopId() . "' and oxobject2group.oxobjectid = " . $oDb->quote($sOxId);
78  $oDb->execute($sDelete);
79  }
80 
81  return $blDeleted;
82  }
83 
89  public function getGroups()
90  {
91  if (isset($this->_oGroups)) {
92  return $this->_oGroups;
93  }
94 
95  // usergroups
96  $this->_oGroups = oxNew("oxList", "oxgroups");
97  $sViewName = getViewName("oxgroups");
98 
99  // performance
100  $sSelect = "select {$sViewName}.* from {$sViewName}, oxobject2group
101  where oxobject2group.oxobjectid='" . $this->getId() . "'
102  and oxobject2group.oxgroupsid={$sViewName}.oxid ";
103  $this->_oGroups->selectString($sSelect);
104 
105  return $this->_oGroups;
106  }
107 
113  public function getHtmlText()
114  {
115  return $this->_sHtmlText;
116  }
117 
123  public function getPlainText()
124  {
125  return $this->_sPlainText;
126  }
127 
135  public function prepare($sUserid, $blPerfLoadAktion = false)
136  {
137  // switching off admin
138  $blAdmin = $this->isAdmin();
139  $this->setAdminMode(false);
140 
141  // add currency
142  $this->_setUser($sUserid);
143  $this->_setParams($blPerfLoadAktion);
144 
145  // restoring mode ..
146  $this->setAdminMode($blAdmin);
147  }
148 
156  public function send()
157  {
158  $oxEMail = oxNew('oxemail');
159  $blSend = $oxEMail->sendNewsletterMail($this, $this->_oUser, $this->oxnewsletter__oxsubject->value);
160 
161  return $blSend;
162  }
163 
171  protected function _setParams($blPerfLoadAktion = false)
172  {
173  $myConfig = $this->getConfig();
174 
175  $oShop = oxNew('oxshop');
176  $oShop->load($myConfig->getShopId());
177 
178  $oView = oxNew('oxubase');
179  $oShop = $oView->addGlobalParams($oShop);
180 
181  $oView->addTplParam('myshop', $oShop);
182  $oView->addTplParam('shop', $oShop);
183  $oView->addTplParam('oViewConf', $oShop);
184  $oView->addTplParam('oView', $oView);
185  $oView->addTplParam('mycurrency', $myConfig->getActShopCurrencyObject());
186  $oView->addTplParam('myuser', $this->_oUser);
187 
188  $this->_assignProducts($oView, $blPerfLoadAktion);
189 
190  $aInput[] = array($this->getId() . 'html', $this->oxnewsletter__oxtemplate->value);
191  $aInput[] = array($this->getId() . 'plain', $this->oxnewsletter__oxplaintemplate->value);
192  $aRes = oxRegistry::get("oxUtilsView")->parseThroughSmarty($aInput, null, $oView, true);
193 
194  $this->_sHtmlText = $aRes[0];
195  $this->_sPlainText = $aRes[1];
196  }
197 
203  protected function _setUser($sUserid)
204  {
205  if (is_string($sUserid)) {
206  $oUser = oxNew('oxuser');
207  if ($oUser->load($sUserid)) {
208  $this->_oUser = $oUser;
209  }
210  } else {
211  $this->_oUser = $sUserid; // we expect a full and valid user object
212  }
213  }
214 
222  protected function _assignProducts($oView, $blPerfLoadAktion = false)
223  {
224  if ($blPerfLoadAktion) {
225  $oArtList = oxNew('oxarticlelist');
226  $oArtList->loadActionArticles('OXNEWSLETTER');
227  $oView->addTplParam('articlelist', $oArtList);
228  }
229 
230  if ($this->_oUser->getId()) {
231  $oArticle = oxNew('oxarticle');
232  $sArticleTable = $oArticle->getViewName();
233 
234  // add products which fit to the last order of this user
235  $sSelect = "select $sArticleTable.* from oxorder left join oxorderarticles on oxorderarticles.oxorderid = oxorder.oxid";
236  $sSelect .= " left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid";
237  $sSelect .= " where " . $oArticle->getSqlActiveSnippet();
238  $sSelect .= " and oxorder.oxuserid = '" . $this->_oUser->getId() . "' order by oxorder.oxorderdate desc limit 1";
239 
240  if ($oArticle->assignRecord($sSelect)) {
241  $oSimList = $oArticle->getSimilarProducts();
242  if ($oSimList && $oSimList->count()) {
243  $oView->addTplParam('simlist', $oSimList);
244  $iCnt = 0;
245  foreach ($oSimList as $oArt) {
246  $oView->addTplParam("simarticle$iCnt", $oArt);
247  $iCnt++;
248  }
249  }
250  }
251  }
252  }
253 
263  protected function _setFieldData($sFieldName, $sValue, $iDataType = oxField::T_TEXT)
264  {
265  if ('oxtemplate' === $sFieldName || 'oxplaintemplate' === $sFieldName) {
266  $iDataType = oxField::T_RAW;
267  }
268 
269  return parent::_setFieldData($sFieldName, $sValue, $iDataType);
270  }
271 }