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

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5