Go to the documentation of this file.00001 <?php
00002
00008 class oxNewsletter extends oxBase
00009 {
00015 protected $_sHtmlText = null;
00016
00022 protected $_sPlainText = null;
00023
00029 protected $_oGroups = null;
00030
00036 protected $_oUser = null;
00037
00043 protected $_sClassName = 'oxnewsletter';
00044
00049 public function __construct()
00050 {
00051 parent::__construct();
00052 $this->init( 'oxnewsletter' );
00053 }
00054
00062 public function delete( $sOxId = null )
00063 {
00064 if ( !$sOxId) {
00065 $sOxId = $this->getId();
00066 }
00067 if ( !$sOxId) {
00068 return false;
00069 }
00070
00071 $blDeleted = parent::delete( $sOxId );
00072
00073 if ( $blDeleted ) {
00074 $oDb = oxDb::getDb();
00075 $sDelete = "delete from oxobject2group where oxobject2group.oxshopid = '".$this->getShopId()."' and oxobject2group.oxobjectid = ".$oDb->quote( $sOxId );
00076 $oDb->execute( $sDelete );
00077 }
00078
00079 return $blDeleted;
00080 }
00081
00087 public function getGroups()
00088 {
00089 if ( isset( $this->_oGroups ) ) {
00090 return $this->_oGroups;
00091 }
00092
00093
00094 $this->_oGroups = oxNew( "oxList", "oxgroups" );
00095 $sViewName = getViewName( "oxgroups" );
00096
00097
00098 $sSelect = "select {$sViewName}.* from {$sViewName}, oxobject2group
00099 where oxobject2group.oxobjectid='".$this->getId()."'
00100 and oxobject2group.oxgroupsid={$sViewName}.oxid ";
00101 $this->_oGroups->selectString( $sSelect );
00102
00103 return $this->_oGroups;
00104 }
00105
00111 public function getHtmlText()
00112 {
00113 return $this->_sHtmlText;
00114 }
00115
00121 public function getPlainText()
00122 {
00123 return $this->_sPlainText;
00124 }
00125
00135 public function prepare( $sUserid, $blPerfLoadAktion = false )
00136 {
00137
00138 $blAdmin = $this->isAdmin();
00139 $this->setAdminMode( false );
00140
00141
00142 $this->_setUser( $sUserid );
00143
00144 $this->_setParams( $blPerfLoadAktion );
00145
00146
00147 $this->setAdminMode( $blAdmin );
00148 }
00149
00157 public function send()
00158 {
00159 $oxEMail = oxNew( 'oxemail' );
00160 $blSend = $oxEMail->sendNewsletterMail( $this, $this->_oUser );
00161
00162
00163 if ( !$blSend ) {
00164 $oDb = oxDb::getDb();
00165 $oDb->execute( "update oxnewssubscribed set oxemailfailed = '1' where oxemail = ".$oDb->quote( $this->_oUser->oxuser__oxusername->value ) );
00166 }
00167
00168 return $blSend;
00169 }
00170
00180 protected function _setParams( $blPerfLoadAktion = false )
00181 {
00182 $myConfig = $this->getConfig();
00183
00184 $oShop = oxNew( 'oxshop' );
00185 $oShop->load( $myConfig->getShopId() );
00186
00187 $oView = oxNew( 'oxubase' );
00188 $oShop = $oView->addGlobalParams( $oShop );
00189
00190 $oView->addTplParam( 'myshop', $oShop );
00191 $oView->addTplParam( 'shop', $oShop );
00192 $oView->addTplParam( 'oViewConf', $oShop );
00193 $oView->addTplParam( 'oView', $oView );
00194 $oView->addTplParam( 'mycurrency', $myConfig->getActShopCurrencyObject() );
00195 $oView->addTplParam( 'myuser', $this->_oUser );
00196
00197 $this->_assignProducts( $oView, $blPerfLoadAktion );
00198
00199 $aInput[] = array( $this->getId().'html', $this->oxnewsletter__oxtemplate->value );
00200 $aInput[] = array( $this->getId().'plain', $this->oxnewsletter__oxplaintemplate->value );
00201 $aRes = oxUtilsView::getInstance()->parseThroughSmarty( $aInput, null, $oView, true );
00202
00203 $this->_sHtmlText = $aRes[0];
00204 $this->_sPlainText = $aRes[1];
00205 }
00206
00214 protected function _setUser( $sUserid )
00215 {
00216 if ( is_string( $sUserid )) {
00217 $oUser = oxNew( 'oxuser' );
00218 if ( $oUser->load( $sUserid ) ) {
00219 $this->_oUser = $oUser;
00220 }
00221 } else {
00222 $this->_oUser = $sUserid;
00223 }
00224 }
00225
00235 protected function _assignProducts( $oView, $blPerfLoadAktion = false )
00236 {
00237 if ( $blPerfLoadAktion ) {
00238 $oArtList = oxNew( 'oxarticlelist' );
00239 $oArtList->loadAktionArticles( 'OXNEWSLETTER' );
00240 $oView->addTplParam( 'articlelist', $oArtList );
00241 }
00242
00243 if ( $this->_oUser->getId() ) {
00244 $oArticle = oxNew( 'oxarticle' );
00245 $sArticleTable = $oArticle->getViewName();
00246
00247
00248 $sSelect = "select $sArticleTable.* from oxorder left join oxorderarticles on oxorderarticles.oxorderid = oxorder.oxid";
00249 $sSelect .= " left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid";
00250 $sSelect .= " where ".$oArticle->getSqlActiveSnippet();
00251 $sSelect .= " and oxorder.oxuserid = '".$this->_oUser->getId()."' order by oxorder.oxorderdate desc";
00252
00253 if ( $oArticle->assignRecord( $sSelect ) ) {
00254 $oSimList = $oArticle->getSimilarProducts();
00255 if ( $oSimList && $oSimList->count() ) {
00256 $oView->addTplParam( 'simlist', $oSimList );
00257 $iCnt = 0;
00258 foreach ( $oSimList as $oArt ) {
00259 $oView->addTplParam( "simarticle$iCnt", $oArt );
00260 $iCnt++;
00261 }
00262 }
00263 }
00264 }
00265 }
00266
00276 protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT )
00277 {
00278 if ( 'oxtemplate' === $sFieldName || 'oxplaintemplate' === $sFieldName ) {
00279 $iDataType = oxField::T_RAW;
00280 }
00281 return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00282 }
00283 }