newsletter.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Newsletter extends oxUBase
00010 {
00015     protected $_oActionArticles = null;
00016 
00021     protected $_oTopArticle = null;
00022 
00027     protected $_sHomeCountryId = null;
00028 
00033     protected $_iNewsletterStatus = null;
00034 
00039     protected $_aRegParams = null;
00040 
00045     protected $_sThisTemplate = 'newsletter.tpl';
00046 
00052     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00053 
00064     public function render()
00065     {
00066         $myConfig = $this->getConfig();
00067 
00068         parent::render();
00069 
00070         // topoffer
00071         $this->_aViewData['toparticle']     = $this->getTopStartArticle();
00072         $this->_aViewData['toparticlelist'] = $this->getTopStartActionArticles();
00073 
00074         $this->_aViewData['homecountryid'] = $this->getHomeCountryId();
00075 
00076         $this->_aViewData['success'] = $this->getNewsletterStatus();
00077 
00078         $this->_aViewData['aRegParams'] = $this->getRegParams();
00079 
00080         return $this->_sThisTemplate;
00081     }
00082 
00091     public function fill()
00092     {
00093         // loads submited values
00094         $this->_aRegParams = oxConfig::getParameter( "editval" );
00095     }
00096 
00107     public function send()
00108     {
00109         $aParams  = oxConfig::getParameter("editval");
00110 
00111         // loads submited values
00112         $this->_aRegParams = $aParams;
00113 
00114         if ( !$aParams['oxuser__oxusername'] ) {
00115             oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_COMPLETEALLFIELEDS');
00116             return;
00117         } elseif ( !oxUtils::getInstance()->isValidEmail( $aParams['oxuser__oxusername'] ) ) {
00118             // #1052C - eMail validation added
00119             oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_INVALIDEMAIL');
00120             return;
00121         }
00122 
00123         $blSubscribe = oxConfig::getParameter("subscribeStatus");
00124 
00125         $oUser = oxNew( 'oxuser' );
00126         $oUser->oxuser__oxusername = new oxField($aParams['oxuser__oxusername'], oxField::T_RAW);
00127 
00128         $blUserLoaded = false;
00129 
00130         // if such user does not exist and subscribe is on - creating it
00131         if ( !$oUser->exists() && $blSubscribe ) {
00132             $oUser->oxuser__oxactive    = new oxField(1, oxField::T_RAW);
00133             $oUser->oxuser__oxrights    = new oxField('user', oxField::T_RAW);
00134             $oUser->oxuser__oxshopid    = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00135             $oUser->oxuser__oxfname     = new oxField($aParams['oxuser__oxfname'], oxField::T_RAW);
00136             $oUser->oxuser__oxlname     = new oxField($aParams['oxuser__oxlname'], oxField::T_RAW);
00137             $oUser->oxuser__oxsal       = new oxField($aParams['oxuser__oxsal'], oxField::T_RAW);
00138             $oUser->oxuser__oxcountryid = new oxField($aParams['oxuser__oxcountryid'], oxField::T_RAW);
00139             $blUserLoaded = $oUser->save();
00140         } else {
00141             $blUserLoaded = $oUser->load( $oUser->getId() );
00142         }
00143 
00144         // if user was added/loaded successfully and subscribe is on - subscribing to newsletter
00145         if ( $blSubscribe && $blUserLoaded ) {
00146             //removing user from subscribe list before adding
00147             $oUser->setNewsSubscription( false, false );
00148 
00149             if ( $oUser->setNewsSubscription( true, true ) ) {
00150                 // done, confirmation required
00151                 $this->_iNewsletterStatus = 1;
00152             } else {
00153                 oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_NOTABLETOSENDEMAIL');
00154             }
00155         } elseif ( !$blSubscribe && $blUserLoaded ) {
00156             // unsubscribing user
00157             $oUser->setNewsSubscription( false, false );
00158             $this->_iNewsletterStatus = 3;
00159         }
00160     }
00161 
00170     public function addme()
00171     {
00172         // user exists ?
00173         $oUser = oxNew( 'oxuser' );
00174         if ( $oUser->load( oxConfig::getParameter( 'uid' ) ) ) {
00175             $oUser->getNewsSubscription()->setOptInStatus( 1 );
00176             $oUser->addToGroup( 'oxidnewsletter' );
00177             $this->_iNewsletterStatus = 2;
00178         }
00179     }
00180 
00189     public function removeme()
00190     {
00191         // existing user ?
00192         $oUser = oxNew( 'oxuser' );
00193         if ( $oUser->load( oxConfig::getParameter( 'uid' ) ) ) {
00194             $oUser->getNewsSubscription()->setOptInStatus( 0 );
00195 
00196             // removing from group ..
00197             if ( !$this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) ) {
00198                 $oUser->removeFromGroup( 'oxidnewsletter' );
00199             }
00200 
00201             $this->_iNewsletterStatus = 3;
00202         }
00203     }
00204 
00210     public function getTopStartActionArticles()
00211     {
00212         if ( $this->_oActionArticles === null ) {
00213             $this->_oActionArticles = false;
00214             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) ) {
00215                 $oArtList = oxNew( 'oxarticlelist' );
00216                 $oArtList->loadAktionArticles( 'OXTOPSTART' );
00217                 if ( $oArtList->count() ) {
00218                     $this->_oTopArticle     = $oArtList->current();
00219                     $this->_oActionArticles = $oArtList;
00220                 }
00221             }
00222         }
00223         return $this->_oActionArticles;
00224     }
00225 
00231     public function getTopStartArticle()
00232     {
00233         if ( $this->_oTopArticle === null ) {
00234             $this->_oTopArticle = false;
00235             if ( $this->getTopStartActionArticles() ) {
00236                 return $this->_oTopArticle;
00237             }
00238         }
00239         return $this->_oTopArticle;
00240     }
00241 
00247     public function getHomeCountryId()
00248     {
00249         if ( $this->_sHomeCountryId === null ) {
00250             $this->_sHomeCountryId = false;
00251             $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
00252             if ( is_array( $aHomeCountry ) ) {
00253                 $this->_sHomeCountryId = current( $aHomeCountry );
00254             }
00255         }
00256         return $this->_sHomeCountryId;
00257     }
00258 
00264     public function getNewsletterStatus()
00265     {
00266         return $this->_iNewsletterStatus;
00267     }
00268 
00274     public function getRegParams()
00275     {
00276         return $this->_aRegParams;
00277     }
00278 }

Generated on Wed Apr 22 12:26:31 2009 for OXID eShop CE by  doxygen 1.5.5