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 $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
00173 protected function _setParams( $blPerfLoadAktion = false )
00174 {
00175 $myConfig = $this->getConfig();
00176
00177 $oShop = oxNew( 'oxshop' );
00178 $oShop->load( $myConfig->getShopId() );
00179
00180 $oView = oxNew( 'oxubase' );
00181 $oShop = $oView->addGlobalParams( $oShop );
00182
00183 $oView->addTplParam( 'myshop', $oShop );
00184 $oView->addTplParam( 'shop', $oShop );
00185 $oView->addTplParam( 'oViewConf', $oShop );
00186 $oView->addTplParam( 'oView', $oView );
00187 $oView->addTplParam( 'mycurrency', $myConfig->getActShopCurrencyObject() );
00188 $oView->addTplParam( 'myuser', $this->_oUser );
00189
00190 $this->_assignProducts( $oView, $blPerfLoadAktion );
00191
00192 $aInput[] = array( $this->getId().'html', $this->oxnewsletter__oxtemplate->value );
00193 $aInput[] = array( $this->getId().'plain', $this->oxnewsletter__oxplaintemplate->value );
00194 $aRes = oxUtilsView::getInstance()->parseThroughSmarty( $aInput, null, $oView, true );
00195
00196 $this->_sHtmlText = $aRes[0];
00197 $this->_sPlainText = $aRes[1];
00198 }
00199
00207 protected function _setUser( $sUserid )
00208 {
00209 if ( is_string( $sUserid )) {
00210 $oUser = oxNew( 'oxuser' );
00211 if ( $oUser->load( $sUserid ) ) {
00212 $this->_oUser = $oUser;
00213 }
00214 } else {
00215 $this->_oUser = $sUserid;
00216 }
00217 }
00218
00228 protected function _assignProducts( $oView, $blPerfLoadAktion = false )
00229 {
00230 if ( $blPerfLoadAktion ) {
00231 $oArtList = oxNew( 'oxarticlelist' );
00232 $oArtList->loadAktionArticles( 'OXNEWSLETTER' );
00233 $oView->addTplParam( 'articlelist', $oArtList );
00234 }
00235
00236 if ( $this->_oUser->getId() ) {
00237 $oArticle = oxNew( 'oxarticle' );
00238 $sArticleTable = $oArticle->getViewName();
00239
00240
00241 $sSelect = "select $sArticleTable.* from oxorder left join oxorderarticles on oxorderarticles.oxorderid = oxorder.oxid";
00242 $sSelect .= " left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid";
00243 $sSelect .= " where ".$oArticle->getSqlActiveSnippet();
00244 $sSelect .= " and oxorder.oxuserid = '".$this->_oUser->getId()."' order by oxorder.oxorderdate desc limit 1";
00245
00246 if ( $oArticle->assignRecord( $sSelect ) ) {
00247 $oSimList = $oArticle->getSimilarProducts();
00248 if ( $oSimList && $oSimList->count() ) {
00249 $oView->addTplParam( 'simlist', $oSimList );
00250 $iCnt = 0;
00251 foreach ( $oSimList as $oArt ) {
00252 $oView->addTplParam( "simarticle$iCnt", $oArt );
00253 $iCnt++;
00254 }
00255 }
00256 }
00257 }
00258 }
00259
00269 protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT )
00270 {
00271 if ( 'oxtemplate' === $sFieldName || 'oxplaintemplate' === $sFieldName ) {
00272 $iDataType = oxField::T_RAW;
00273 }
00274 return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00275 }
00276 }