Go to the documentation of this file.00001 <?php
00002
00009 class oxNewsletter extends oxBase
00010 {
00011
00017 protected $_sHtmlText = null;
00018
00024 protected $_sPlainText = null;
00025
00031 protected $_oGroups = null;
00032
00038 protected $_oUser = null;
00039
00045 protected $_sClassName = 'oxnewsletter';
00046
00051 public function __construct()
00052 {
00053 parent::__construct();
00054 $this->init('oxnewsletter');
00055 }
00056
00064 public function delete($sOxId = null)
00065 {
00066 if (!$sOxId) {
00067 $sOxId = $this->getId();
00068 }
00069 if (!$sOxId) {
00070 return false;
00071 }
00072
00073 $blDeleted = parent::delete($sOxId);
00074
00075 if ($blDeleted) {
00076 $oDb = oxDb::getDb();
00077 $sDelete = "delete from oxobject2group where oxobject2group.oxshopid = '" . $this->getShopId() . "' and oxobject2group.oxobjectid = " . $oDb->quote($sOxId);
00078 $oDb->execute($sDelete);
00079 }
00080
00081 return $blDeleted;
00082 }
00083
00089 public function getGroups()
00090 {
00091 if (isset($this->_oGroups)) {
00092 return $this->_oGroups;
00093 }
00094
00095
00096 $this->_oGroups = oxNew("oxList", "oxgroups");
00097 $sViewName = getViewName("oxgroups");
00098
00099
00100 $sSelect = "select {$sViewName}.* from {$sViewName}, oxobject2group
00101 where oxobject2group.oxobjectid='" . $this->getId() . "'
00102 and oxobject2group.oxgroupsid={$sViewName}.oxid ";
00103 $this->_oGroups->selectString($sSelect);
00104
00105 return $this->_oGroups;
00106 }
00107
00113 public function getHtmlText()
00114 {
00115 return $this->_sHtmlText;
00116 }
00117
00123 public function getPlainText()
00124 {
00125 return $this->_sPlainText;
00126 }
00127
00135 public function prepare($sUserid, $blPerfLoadAktion = false)
00136 {
00137
00138 $blAdmin = $this->isAdmin();
00139 $this->setAdminMode(false);
00140
00141
00142 $this->_setUser($sUserid);
00143 $this->_setParams($blPerfLoadAktion);
00144
00145
00146 $this->setAdminMode($blAdmin);
00147 }
00148
00156 public function send()
00157 {
00158 $oxEMail = oxNew('oxemail');
00159 $blSend = $oxEMail->sendNewsletterMail($this, $this->_oUser, $this->oxnewsletter__oxsubject->value);
00160
00161 return $blSend;
00162 }
00163
00171 protected function _setParams($blPerfLoadAktion = false)
00172 {
00173 $myConfig = $this->getConfig();
00174
00175 $oShop = oxNew('oxshop');
00176 $oShop->load($myConfig->getShopId());
00177
00178 $oView = oxNew('oxubase');
00179 $oShop = $oView->addGlobalParams($oShop);
00180
00181 $oView->addTplParam('myshop', $oShop);
00182 $oView->addTplParam('shop', $oShop);
00183 $oView->addTplParam('oViewConf', $oShop);
00184 $oView->addTplParam('oView', $oView);
00185 $oView->addTplParam('mycurrency', $myConfig->getActShopCurrencyObject());
00186 $oView->addTplParam('myuser', $this->_oUser);
00187
00188 $this->_assignProducts($oView, $blPerfLoadAktion);
00189
00190 $aInput[] = array($this->getId() . 'html', $this->oxnewsletter__oxtemplate->value);
00191 $aInput[] = array($this->getId() . 'plain', $this->oxnewsletter__oxplaintemplate->value);
00192 $aRes = oxRegistry::get("oxUtilsView")->parseThroughSmarty($aInput, null, $oView, true);
00193
00194 $this->_sHtmlText = $aRes[0];
00195 $this->_sPlainText = $aRes[1];
00196 }
00197
00203 protected function _setUser($sUserid)
00204 {
00205 if (is_string($sUserid)) {
00206 $oUser = oxNew('oxuser');
00207 if ($oUser->load($sUserid)) {
00208 $this->_oUser = $oUser;
00209 }
00210 } else {
00211 $this->_oUser = $sUserid;
00212 }
00213 }
00214
00222 protected function _assignProducts($oView, $blPerfLoadAktion = false)
00223 {
00224 if ($blPerfLoadAktion) {
00225 $oArtList = oxNew('oxarticlelist');
00226 $oArtList->loadActionArticles('OXNEWSLETTER');
00227 $oView->addTplParam('articlelist', $oArtList);
00228 }
00229
00230 if ($this->_oUser->getId()) {
00231 $oArticle = oxNew('oxarticle');
00232 $sArticleTable = $oArticle->getViewName();
00233
00234
00235 $sSelect = "select $sArticleTable.* from oxorder left join oxorderarticles on oxorderarticles.oxorderid = oxorder.oxid";
00236 $sSelect .= " left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid";
00237 $sSelect .= " where " . $oArticle->getSqlActiveSnippet();
00238 $sSelect .= " and oxorder.oxuserid = '" . $this->_oUser->getId() . "' order by oxorder.oxorderdate desc limit 1";
00239
00240 if ($oArticle->assignRecord($sSelect)) {
00241 $oSimList = $oArticle->getSimilarProducts();
00242 if ($oSimList && $oSimList->count()) {
00243 $oView->addTplParam('simlist', $oSimList);
00244 $iCnt = 0;
00245 foreach ($oSimList as $oArt) {
00246 $oView->addTplParam("simarticle$iCnt", $oArt);
00247 $iCnt++;
00248 }
00249 }
00250 }
00251 }
00252 }
00253
00263 protected function _setFieldData($sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00264 {
00265 if ('oxtemplate' === $sFieldName || 'oxplaintemplate' === $sFieldName) {
00266 $iDataType = oxField::T_RAW;
00267 }
00268
00269 return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00270 }
00271 }