oxnewsletter.php

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         // usergroups
00094         $this->_oGroups = oxNew( "oxList", "oxgroups" );
00095 
00096         // performance
00097         $sSelect  = 'select oxgroups.* from oxgroups, oxobject2group ';
00098         $sSelect .= 'where oxobject2group.oxobjectid="'.$this->getId().'" ';
00099         $sSelect .= 'and oxobject2group.oxgroupsid=oxgroups.oxid ';
00100         $this->_oGroups->selectString( $sSelect );
00101 
00102         return $this->_oGroups;
00103     }
00104 
00110     public function getHtmlText()
00111     {
00112         return $this->_sHtmlText;
00113     }
00114 
00120     public function getPlainText()
00121     {
00122         return $this->_sPlainText;
00123     }
00124 
00134     public function prepare( $sUserid, $blPerfLoadAktion = false )
00135     {
00136         // switching off admin
00137         $blAdmin = $this->isAdmin();
00138         $this->setAdminMode( false );
00139 
00140         // add currency
00141         $this->_setUser( $sUserid );
00142 
00143         $this->_setParams( $blPerfLoadAktion );
00144 
00145         // restoring mode ..
00146         $this->setAdminMode( $blAdmin );
00147     }
00148 
00156     public function send()
00157     {
00158         $oxEMail = oxNew( 'oxemail' );
00159         $blSend = $oxEMail->sendNewsletterMail( $this, $this->_oUser );
00160         //print_r($oxEMail);
00161         // store failed info
00162         if ( !$blSend ) {
00163             $oDb = oxDb::getDb();
00164             $oDb->execute( "update oxnewssubscribed set oxemailfailed = '1' where oxemail = ".$oDb->quote( $this->_oUser->oxuser__oxusername->value ) );
00165         }
00166 
00167         return $blSend;
00168     }
00169 
00179     protected function _setParams( $blPerfLoadAktion = false )
00180     {
00181         $myConfig = $this->getConfig();
00182 
00183         $oShop = oxNew( 'oxshop' );
00184         $oShop->load( $myConfig->getShopId() );
00185 
00186         $oView = oxNew( 'oxubase' );
00187         $oShop = $oView->addGlobalParams( $oShop );
00188 
00189         $oView->addTplParam( 'myshop', $oShop );
00190         $oView->addTplParam( 'shop', $oShop );
00191         $oView->addTplParam( 'oViewConf', $oShop );
00192         $oView->addTplParam( 'oView', $oView );
00193         $oView->addTplParam( 'mycurrency', $myConfig->getActShopCurrencyObject() );
00194         $oView->addTplParam( 'myuser', $this->_oUser );
00195 
00196         $this->_assignProducts( $oView, $blPerfLoadAktion );
00197 
00198         $aInput[] = array( $this->getId().'html', $this->oxnewsletter__oxtemplate->value );
00199         $aInput[] = array( $this->getId().'plain', $this->oxnewsletter__oxplaintemplate->value );
00200         $aRes = oxUtilsView::getInstance()->parseThroughSmarty( $aInput, null, $oView, true );
00201 
00202         $this->_sHtmlText  = $aRes[0];
00203         $this->_sPlainText = $aRes[1];
00204     }
00205 
00213     protected function _setUser( $sUserid )
00214     {
00215         if ( is_string( $sUserid )) {
00216             $oUser = oxNew( 'oxuser' );
00217             if ( $oUser->load( $sUserid ) ) {
00218                 $this->_oUser = $oUser;
00219             }
00220         } else {
00221             $this->_oUser = $sUserid;   // we expect a full and valid user object
00222         }
00223     }
00224 
00234     protected function _assignProducts( $oView, $blPerfLoadAktion = false )
00235     {
00236         if ( $blPerfLoadAktion ) {
00237             $oArtList = oxNew( 'oxarticlelist' );
00238             $oArtList->loadAktionArticles( 'OXNEWSLETTER' );
00239             $oView->addTplParam( 'articlelist', $oArtList );
00240         }
00241 
00242         if ( $this->_oUser->getId() ) {
00243             $oArticle = oxNew( 'oxarticle' );
00244             $sArticleTable = $oArticle->getViewName();
00245 
00246             // add products which fit to the last order of this user
00247             $sSelect  = "select $sArticleTable.* from oxorder left join oxorderarticles on oxorderarticles.oxorderid = oxorder.oxid";
00248             $sSelect .= " left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid";
00249             $sSelect .= " where ".$oArticle->getSqlActiveSnippet();
00250             $sSelect .= " and oxorder.oxuserid = '".$this->_oUser->getId()."' order by oxorder.oxorderdate desc";
00251 
00252             if ( $oArticle->assignRecord( $sSelect ) ) {
00253                 $oSimList = $oArticle->getSimilarProducts();
00254                 if ( $oSimList && $oSimList->count() ) {
00255                     $oView->addTplParam( 'simlist', $oSimList );
00256                     $iCnt = 0;
00257                     foreach ( $oSimList as $oArt ) {
00258                         $oView->addTplParam( "simarticle$iCnt", $oArt );
00259                         $iCnt++;
00260                     }
00261                 }
00262             }
00263         }
00264     }
00265 
00275     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT )
00276     {
00277         if ( 'oxtemplate' === $sFieldName || 'oxplaintemplate' === $sFieldName ) {
00278             $iDataType = oxField::T_RAW;
00279         }
00280         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00281     }
00282 }

Generated by  doxygen 1.6.2