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 = 'page/info/newsletter.tpl';
00046 
00052     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00053 
00062     public function fill()
00063     {
00064         // loads submited values
00065         $this->_aRegParams = oxConfig::getParameter( "editval" );
00066     }
00067 
00078     public function send()
00079     {
00080         $aParams  = oxConfig::getParameter("editval");
00081 
00082         // loads submited values
00083         $this->_aRegParams = $aParams;
00084 
00085         if ( !$aParams['oxuser__oxusername'] ) {
00086             oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_COMPLETEALLFIELEDS');
00087             return;
00088         } elseif ( !oxUtils::getInstance()->isValidEmail( $aParams['oxuser__oxusername'] ) ) {
00089             // #1052C - eMail validation added
00090             oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_INVALIDEMAIL');
00091             return;
00092         }
00093 
00094         $blSubscribe = oxConfig::getParameter("subscribeStatus");
00095 
00096         $oUser = oxNew( 'oxuser' );
00097         $oUser->oxuser__oxusername = new oxField($aParams['oxuser__oxusername'], oxField::T_RAW);
00098 
00099         $blUserLoaded = false;
00100 
00101         // if such user does not exist
00102         if ( !$oUser->exists() ) {
00103 
00104             // and subscribe is off - error, on - create
00105             if ( !$blSubscribe ) {
00106 
00107                 oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_EMAIL_NOT_EXIST');
00108                 return;
00109 
00110             } else {
00111                 $oUser->oxuser__oxactive    = new oxField(1, oxField::T_RAW);
00112                 $oUser->oxuser__oxrights    = new oxField('user', oxField::T_RAW);
00113                 $oUser->oxuser__oxshopid    = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00114                 $oUser->oxuser__oxfname     = new oxField($aParams['oxuser__oxfname'], oxField::T_RAW);
00115                 $oUser->oxuser__oxlname     = new oxField($aParams['oxuser__oxlname'], oxField::T_RAW);
00116                 $oUser->oxuser__oxsal       = new oxField($aParams['oxuser__oxsal'], oxField::T_RAW);
00117                 $oUser->oxuser__oxcountryid = new oxField($aParams['oxuser__oxcountryid'], oxField::T_RAW);
00118                 $blUserLoaded = $oUser->save();
00119             }
00120 
00121         } else {
00122             $blUserLoaded = $oUser->load( $oUser->getId() );
00123         }
00124 
00125 
00126 
00127         // if user was added/loaded successfully and subscribe is on - subscribing to newsletter
00128         if ( $blSubscribe && $blUserLoaded ) {
00129             //removing user from subscribe list before adding
00130             $oUser->setNewsSubscription( false, false );
00131 
00132             $blOrderOptInEmail = $this->getConfig()->getConfigParam( 'blOrderOptInEmail' );
00133             if ( $oUser->setNewsSubscription( true, $blOrderOptInEmail ) ) {
00134                 // done, confirmation required?
00135                 if ( $blOrderOptInEmail ) {
00136                     $this->_iNewsletterStatus = 1;
00137                 } else {
00138                     $this->_iNewsletterStatus = 2;
00139                 }
00140             } else {
00141                 oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_NOTABLETOSENDEMAIL');
00142             }
00143         } elseif ( !$blSubscribe && $blUserLoaded ) {
00144             // unsubscribing user
00145             $oUser->setNewsSubscription( false, false );
00146             $this->_iNewsletterStatus = 3;
00147         }
00148     }
00149 
00158     public function addme()
00159     {
00160         // user exists ?
00161         $oUser = oxNew( 'oxuser' );
00162         if ( $oUser->load( oxConfig::getParameter( 'uid' ) ) ) {
00163             $oUser->getNewsSubscription()->setOptInStatus( 1 );
00164             $oUser->addToGroup( 'oxidnewsletter' );
00165             $this->_iNewsletterStatus = 2;
00166         }
00167     }
00168 
00174     public function removeme()
00175     {
00176         // existing user ?
00177         $oUser = oxNew( 'oxuser' );
00178         if ( $oUser->load( oxConfig::getParameter( 'uid' ) ) ) {
00179             $oUser->getNewsSubscription()->setOptInStatus( 0 );
00180 
00181             // removing from group ..
00182             if ( !$this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) ) {
00183                 $oUser->removeFromGroup( 'oxidnewsletter' );
00184             }
00185 
00186             $this->_iNewsletterStatus = 3;
00187         }
00188     }
00189 
00195     public function rmvm()
00196     {
00197         $this->removeme();
00198     }
00199 
00205     public function getTopStartActionArticles()
00206     {
00207         if ( $this->_oActionArticles === null ) {
00208             $this->_oActionArticles = false;
00209             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) ) {
00210                 $oArtList = oxNew( 'oxarticlelist' );
00211                 $oArtList->loadAktionArticles( 'OXTOPSTART' );
00212                 if ( $oArtList->count() ) {
00213                     $this->_oTopArticle     = $oArtList->current();
00214                     $this->_oActionArticles = $oArtList;
00215                 }
00216             }
00217         }
00218         return $this->_oActionArticles;
00219     }
00220 
00226     public function getTopStartArticle()
00227     {
00228         if ( $this->_oTopArticle === null ) {
00229             $this->_oTopArticle = false;
00230             if ( $this->getTopStartActionArticles() ) {
00231                 return $this->_oTopArticle;
00232             }
00233         }
00234         return $this->_oTopArticle;
00235     }
00236 
00242     public function getHomeCountryId()
00243     {
00244         if ( $this->_sHomeCountryId === null ) {
00245             $this->_sHomeCountryId = false;
00246             $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
00247             if ( is_array( $aHomeCountry ) ) {
00248                 $this->_sHomeCountryId = current( $aHomeCountry );
00249             }
00250         }
00251         return $this->_sHomeCountryId;
00252     }
00253 
00259     public function getNewsletterStatus()
00260     {
00261         return $this->_iNewsletterStatus;
00262     }
00263 
00269     public function getRegParams()
00270     {
00271         return $this->_aRegParams;
00272     }
00273 
00279     public function getBreadCrumb()
00280     {
00281         $aPaths = array();
00282         $aPath  = array();
00283         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_INFO_NEWSLETTER_STAYINFORMED', oxLang::getInstance()->getBaseLanguage(), false );
00284         $aPath['link']  = $this->getLink();
00285 
00286         $aPaths[] = $aPath;
00287         return $aPaths;
00288     }
00289 }