00001 <?php
00002
00009 class oxNewsSubscribed extends oxBase
00010 {
00016 protected $_blWasSubscribed = false;
00017
00023 protected $_sClassName = 'oxnewssubscribed';
00024
00025
00029 public function __construct()
00030 {
00031
00032 parent::__construct();
00033
00034 $this->init( 'oxnewssubscribed' );
00035 }
00036
00037
00045 public function load( $oxId )
00046 {
00047 $blRet = parent::load( $oxId );
00048
00049 if ( $this->oxnewssubscribed__oxdboptin->value == 1) {
00050 $this->_blWasSubscribed = true;
00051 }
00052
00053 return $blRet;
00054 }
00055
00063 public function loadFromEmail( $sEmailAddress )
00064 {
00065 $sOxId = oxDb::getDb( true )->getOne( "select oxid from oxnewssubscribed where oxemail = '$sEmailAddress' " );
00066
00067 return $this->load( $sOxId );
00068 }
00069
00077 public function loadFromUserId( $sOxUserId )
00078 {
00079 $sOxId = oxDb::getDb( true )->getOne( "select oxid from oxnewssubscribed where oxuserid = '$sOxUserId' " );
00080 return $this->load( $sOxId );
00081 }
00082
00088 protected function _insert()
00089 {
00090
00091 $this->oxnewssubscribed__oxsubscribed = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
00092 return parent::_insert();
00093 }
00094
00100 protected function _update()
00101 {
00102 if ( $this->_blWasSubscribed && !$this->oxnewssubscribed__oxdboptin->value ) {
00103
00104 $this->oxnewssubscribed__oxunsubscribed->setValue(date( 'Y-m-d H:i:s' ));
00105 } else {
00106
00107 $this->_aSkipSaveFields[] = 'oxunsubscribed';
00108 }
00109
00110 return parent::_update();
00111 }
00112
00118 public function getOptInStatus()
00119 {
00120 return $this->oxnewssubscribed__oxdboptin->value;
00121 }
00122
00130 public function setOptInStatus( $iStatus )
00131 {
00132 $this->oxnewssubscribed__oxdboptin = new oxField($iStatus, oxField::T_RAW);
00133 $this->save();
00134 }
00135
00141 public function getOptInEmailStatus()
00142 {
00143 return $this->oxnewssubscribed__oxemailfailed->value;
00144 }
00145
00153 public function setOptInEmailStatus( $iStatus )
00154 {
00155 $this->oxnewssubscribed__oxemailfailed = new oxField($iStatus, oxField::T_RAW);
00156 $this->save();
00157 }
00158
00167 public function updateSubscription( $oUser )
00168 {
00169
00170 if ( $oUser->oxuser__oxusername->value && $this->oxnewssubscribed__oxemail->value != $oUser->oxuser__oxusername->value ) {
00171 $this->oxnewssubscribed__oxemail = new oxField( $oUser->oxuser__oxusername->value, oxField::T_RAW );
00172 }
00173
00174
00175 $this->oxnewssubscribed__oxsal = new oxField( $oUser->oxuser__oxsal->value, oxField::T_RAW );
00176 $this->oxnewssubscribed__oxfname = new oxField( $oUser->oxuser__oxfname->value, oxField::T_RAW );
00177 $this->oxnewssubscribed__oxlname = new oxField( $oUser->oxuser__oxlname->value, oxField::T_RAW );
00178
00179 return (bool) $this->save();
00180 }
00181 }