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
00131         if ( !$oUser->exists() ) {
00132 
00133             // and subscribe is off - error, on - create
00134             if ( !$blSubscribe ) {
00135 
00136                 oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_EMAIL_NOT_EXIST');
00137                 return;
00138 
00139             } else {
00140                 $oUser->oxuser__oxactive    = new oxField(1, oxField::T_RAW);
00141                 $oUser->oxuser__oxrights    = new oxField('user', oxField::T_RAW);
00142                 $oUser->oxuser__oxshopid    = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00143                 $oUser->oxuser__oxfname     = new oxField($aParams['oxuser__oxfname'], oxField::T_RAW);
00144                 $oUser->oxuser__oxlname     = new oxField($aParams['oxuser__oxlname'], oxField::T_RAW);
00145                 $oUser->oxuser__oxsal       = new oxField($aParams['oxuser__oxsal'], oxField::T_RAW);
00146                 $oUser->oxuser__oxcountryid = new oxField($aParams['oxuser__oxcountryid'], oxField::T_RAW);
00147                 $blUserLoaded = $oUser->save();
00148             }
00149 
00150         } else {
00151             $blUserLoaded = $oUser->load( $oUser->getId() );
00152         }
00153 
00154 
00155 
00156         // if user was added/loaded successfully and subscribe is on - subscribing to newsletter
00157         if ( $blSubscribe && $blUserLoaded ) {
00158             //removing user from subscribe list before adding
00159             $oUser->setNewsSubscription( false, false );
00160 
00161             $blOrderOptInEmail = $this->getConfig()->getConfigParam( 'blOrderOptInEmail' );
00162             if ( $oUser->setNewsSubscription( true, $blOrderOptInEmail ) ) {
00163                 // done, confirmation required?
00164                 if ( $blOrderOptInEmail ) {
00165                     $this->_iNewsletterStatus = 1;
00166                 } else {
00167                     $this->_iNewsletterStatus = 2;
00168                 }
00169             } else {
00170                 oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_NOTABLETOSENDEMAIL');
00171             }
00172         } elseif ( !$blSubscribe && $blUserLoaded ) {
00173             // unsubscribing user
00174             $oUser->setNewsSubscription( false, false );
00175             $this->_iNewsletterStatus = 3;
00176         }
00177     }
00178 
00187     public function addme()
00188     {
00189         // user exists ?
00190         $oUser = oxNew( 'oxuser' );
00191         if ( $oUser->load( oxConfig::getParameter( 'uid' ) ) ) {
00192             $oUser->getNewsSubscription()->setOptInStatus( 1 );
00193             $oUser->addToGroup( 'oxidnewsletter' );
00194             $this->_iNewsletterStatus = 2;
00195         }
00196     }
00197 
00206     public function removeme()
00207     {
00208         // existing user ?
00209         $oUser = oxNew( 'oxuser' );
00210         if ( $oUser->load( oxConfig::getParameter( 'uid' ) ) ) {
00211             $oUser->getNewsSubscription()->setOptInStatus( 0 );
00212 
00213             // removing from group ..
00214             if ( !$this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) ) {
00215                 $oUser->removeFromGroup( 'oxidnewsletter' );
00216             }
00217 
00218             $this->_iNewsletterStatus = 3;
00219         }
00220     }
00221 
00227     public function getTopStartActionArticles()
00228     {
00229         if ( $this->_oActionArticles === null ) {
00230             $this->_oActionArticles = false;
00231             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) ) {
00232                 $oArtList = oxNew( 'oxarticlelist' );
00233                 $oArtList->loadAktionArticles( 'OXTOPSTART' );
00234                 if ( $oArtList->count() ) {
00235                     $this->_oTopArticle     = $oArtList->current();
00236                     $this->_oActionArticles = $oArtList;
00237                 }
00238             }
00239         }
00240         return $this->_oActionArticles;
00241     }
00242 
00248     public function getTopStartArticle()
00249     {
00250         if ( $this->_oTopArticle === null ) {
00251             $this->_oTopArticle = false;
00252             if ( $this->getTopStartActionArticles() ) {
00253                 return $this->_oTopArticle;
00254             }
00255         }
00256         return $this->_oTopArticle;
00257     }
00258 
00264     public function getHomeCountryId()
00265     {
00266         if ( $this->_sHomeCountryId === null ) {
00267             $this->_sHomeCountryId = false;
00268             $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
00269             if ( is_array( $aHomeCountry ) ) {
00270                 $this->_sHomeCountryId = current( $aHomeCountry );
00271             }
00272         }
00273         return $this->_sHomeCountryId;
00274     }
00275 
00281     public function getNewsletterStatus()
00282     {
00283         return $this->_iNewsletterStatus;
00284     }
00285 
00291     public function getRegParams()
00292     {
00293         return $this->_aRegParams;
00294     }
00295 }