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

Generated on Wed May 13 13:25:51 2009 for OXID eShop CE by  doxygen 1.5.5