00001 <?php
00002
00009 class oxNewsletter extends oxBase
00010 {
00016 protected $_oSmarty = null;
00017
00023 protected $_sHtmlText = null;
00024
00030 protected $_sPlainText = null;
00031
00037 protected $_oGroups = null;
00038
00044 protected $_oUser = null;
00045
00051 protected $_sClassName = 'oxnewsletter';
00052
00057 public function __construct()
00058 {
00059 parent::__construct();
00060
00061 $this->init( 'oxnewsletter' );
00062
00063 $this->_oSmarty = oxUtilsView::getInstance()->getSmarty();
00064 $this->_oSmarty->force_compile = true;
00065 }
00066
00074 public function delete( $sOxId = null )
00075 {
00076 if( !$sOxId) {
00077 $sOxId = $this->getId();
00078 }
00079 if( !$sOxId) {
00080 return false;
00081 }
00082
00083 $blDeleted = parent::delete( $sOxId );
00084
00085 if ( $blDeleted ) {
00086 $sDelete = "delete from oxobject2group where oxobject2group.oxshopid = '".$this->getShopId()."' and oxobject2group.oxobjectid = '$sOxId' ";
00087 oxDb::getDb()->execute( $sDelete );
00088 }
00089
00090 return $blDeleted;
00091 }
00092
00098 public function getGroups()
00099 {
00100 if ( isset( $this->_oGroups ) ) {
00101 return $this->_oGroups;
00102 }
00103
00104
00105 $this->_oGroups = oxNew( "oxList", "oxgroups" );
00106
00107
00108 $sSelect = 'select oxgroups.* from oxgroups, oxobject2group ';
00109 $sSelect .= 'where oxobject2group.oxobjectid="'.$this->getId().'" ';
00110 $sSelect .= 'and oxobject2group.oxgroupsid=oxgroups.oxid ';
00111 $this->_oGroups->selectString( $sSelect );
00112
00113 return $this->_oGroups;
00114 }
00115
00121 public function getHtmlText()
00122 {
00123 return $this->_sHtmlText;
00124 }
00125
00131 public function getPlainText()
00132 {
00133 return $this->_sPlainText;
00134 }
00135
00145 public function prepare( $sUserid, $blPerfLoadAktion = false )
00146 {
00147
00148 $blAdmin = $this->isAdmin();
00149 $this->setAdminMode( false );
00150
00151 $myConfig = $this->getConfig();
00152
00153 $oShop = oxNew( 'oxshop' );
00154 $oShop->load( $myConfig->getShopId() );
00155 $oView = $myConfig->getActiveView();
00156 $oShop = $oView->addGlobalParams( $oShop );
00157
00158
00159 $this->_setUser( $sUserid );
00160
00161 $this->_setParams( $oShop, $myConfig->getActShopCurrencyObject(), $blPerfLoadAktion );
00162
00163 $this->setAdminMode( $blAdmin );
00164 }
00165
00173 public function send()
00174 {
00175 $oxEMail = oxNew( 'oxemail' );
00176 $blSend = $oxEMail->sendNewsletterMail( $this, $this->_oUser );
00177
00178
00179 if ( !$blSend ) {
00180 oxDb::getDb()->Execute( "update oxnewssubscribed set oxemailfailed = '1' where oxemail = '".$this->_oUser->oxuser__oxusername->value."'");
00181 }
00182
00183 return $blSend;
00184 }
00185
00197 protected function _setParams( $oShop, $oCurrency, $blPerfLoadAktion = false )
00198 {
00199 $this->_oSmarty->assign( 'myshop', $oShop );
00200 $this->_oSmarty->assign( 'shop', $oShop );
00201 $this->_oSmarty->assign( 'mycurrency', $oCurrency );
00202 $this->_oSmarty->assign( 'myuser', $this->_oUser );
00203
00204 $this->_assignProducts( $blPerfLoadAktion );
00205
00206
00207
00208
00209 $this->_oSmarty->oxidcache = clone $this->oxnewsletter__oxtemplate;
00210 $this->_sHtmlText = $this->_oSmarty->fetch( 'ox:'.$this->oxnewsletter__oxid->value.'oxnewsletter__oxtemplate' );
00211
00212 $this->_oSmarty->oxidcache = clone $this->oxnewsletter__oxplaintemplate;
00213 $this->_sPlainText = $this->_oSmarty->fetch( 'ox:'.$this->oxnewsletter__oxid->value.'oxnewsletter__oxplaintemplate' );
00214 }
00215
00223 protected function _setUser( $sUserid )
00224 {
00225 if ( is_string( $sUserid )) {
00226 $oUser = oxNew( 'oxuser' );
00227 if ( $oUser->load( $sUserid ) ) {
00228 $this->_oUser = $oUser;
00229 }
00230 } else {
00231 $this->_oUser = $sUserid;
00232 }
00233 }
00234
00243 protected function _assignProducts( $blPerfLoadAktion = false )
00244 {
00245 if ( $blPerfLoadAktion ) {
00246 $oArtList = oxNew( 'oxarticlelist' );
00247 $oArtList->loadAktionArticles( 'OXNEWSLETTER' );
00248 $this->_oSmarty->assign( 'articlelist', $oArtList );
00249 }
00250
00251 if ( $this->_oUser->getId() ) {
00252 $oArticle = oxNew( 'oxarticle' );
00253 $sArticleTable = $oArticle->getViewName();
00254
00255
00256 $sSelect = "select $sArticleTable.* from oxorder left join oxorderarticles on oxorderarticles.oxorderid = oxorder.oxid";
00257 $sSelect .= " left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid";
00258 $sSelect .= " where ".$oArticle->getSqlActiveSnippet();
00259 $sSelect .= " and oxorder.oxuserid = '".$this->_oUser->oxuser__oxid->value."' order by oxorder.oxorderdate desc";
00260
00261 $oArtList = oxNew( 'oxarticlelist' );
00262 $oArtList->selectString( $sSelect );
00263
00264 $oOneArt = null;
00265 $oOneOrder = null;
00266 $aSimList = array();
00267
00268 if ( $oArtList->count() ) {
00269 $oOneArt = $oArtList->current();
00270 }
00271
00272 if ( $oOneArt ) {
00273 $oSimList = $oOneArt->getSimilarProducts();
00274 }
00275
00276 if ( $oSimList && $oSimList->count() ) {
00277 $this->_oSmarty->assign( 'simlist', $oSimList );
00278 $iCnt = 0;
00279 foreach ( $oSimList as $oArt ) {
00280 $sName = "simarticle$iCnt";
00281 $this->_oSmarty->assign( $sName, $oArt );
00282 $iCnt++;
00283 }
00284 }
00285 }
00286 }
00287
00297 protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT )
00298 {
00299 if ( 'oxtemplate' === $sFieldName || 'oxplaintemplate' === $sFieldName ) {
00300 $iDataType = oxField::T_RAW;
00301 }
00302 return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00303 }
00304 }