00001 <?php
00002
00009 class Account_Newsletter extends Account
00010 {
00015 protected $_sThisTemplate = 'account_newsletter.tpl';
00016
00022 protected $_blNewsletter = null;
00023
00029 protected $_iSubscriptionStatus = 0;
00030
00041 public function render()
00042 {
00043 parent::render();
00044
00045
00046 $oUser = $this->getUser();
00047 if ( !$oUser ) {
00048 return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00049 }
00050
00051
00052 $this->_aViewData['blnewsletter'] = $this->isNewsletter();
00053
00054
00055 $this->_aViewData['actshop'] = $this->getConfig()->getActiveShop();
00056
00057 return $this->_sThisTemplate;
00058 }
00059
00060
00066 public function isNewsletter()
00067 {
00068 if ( $this->_blNewsletter === null ) {
00069
00070
00071 $this->_blNewsletter = false;
00072
00073
00074 $oUser = $this->getUser();
00075 if ( $oUser && $oUser->inGroup( 'oxidnewsletter' ) && ( $oUser->getNewsSubscription()->getOptInStatus() == 1 ) ) {
00076 $this->_blNewsletter = true;
00077 }
00078 }
00079
00080 return $this->_blNewsletter;
00081 }
00082
00089 public function subscribe()
00090 {
00091
00092 $oUser = $this->getUser();
00093 if ( !$oUser ) {
00094 return false;
00095 }
00096
00097 if ( ! ( $iStatus = oxConfig::getParameter( 'status' ) ) ) {
00098 $oUser->removeFromGroup( 'oxidnewsletter' );
00099 $oUser->getNewsSubscription()->setOptInStatus( 0 );
00100 $this->_iSubscriptionStatus = -1;
00101 } else {
00102
00103 $oUser->addToGroup( 'oxidnewsletter' );
00104 $oUser->getNewsSubscription()->setOptInEmailStatus( 0 );
00105 $oUser->getNewsSubscription()->setOptInStatus( 1 );
00106 $this->_iSubscriptionStatus = 1;
00107 }
00108
00109
00110 if ( $this->getSubscriptionStatus() == 1) {
00111 $this->_aViewData['blsubscribed'] = true;
00112 }
00113 if ( $this->getSubscriptionStatus() == -1) {
00114 $this->_aViewData['blsubscribed'] = false;
00115 }
00116 }
00117
00124 public function getSubscriptionStatus()
00125 {
00126 return $this->_iSubscriptionStatus;
00127 }
00128 }