oxnewssubscribed.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxNewsSubscribed extends oxBase
00009 {
00015     protected $_blWasSubscribed = false;
00016 
00022     protected $_blWasPreSubscribed = false;
00023 
00029     protected $_sClassName = 'oxnewssubscribed';
00030 
00031 
00035     public function __construct()
00036     {
00037 
00038         parent::__construct();
00039 
00040         $this->init( 'oxnewssubscribed' );
00041     }
00042 
00043 
00051     public function load( $oxId )
00052     {
00053         $blRet = parent::load( $oxId );
00054 
00055         if ( $this->oxnewssubscribed__oxdboptin->value == 1 ) {
00056             $this->_blWasSubscribed = true;
00057         } elseif ( $this->oxnewssubscribed__oxdboptin->value == 2 ) {
00058             $this->_blWasPreSubscribed = true;
00059         }
00060 
00061         return $blRet;
00062     }
00063 
00071     public function loadFromEmail( $sEmailAddress )
00072     {
00073         $oDb = oxDb::getDb();
00074         $sEmailAddressQuoted = $oDb->quote( $sEmailAddress );
00075             $sOxId = $oDb->getOne( "select oxid from oxnewssubscribed where oxemail = {$sEmailAddressQuoted} " );
00076 
00077         return $this->load( $sOxId );
00078     }
00079 
00087     public function loadFromUserId( $sOxUserId )
00088     {
00089         $oDb = oxDb::getDb();
00090         $sOxId = $oDb->getOne( "select oxid from oxnewssubscribed where oxuserid = " . $oDb->quote( $sOxUserId ) );
00091         return $this->load( $sOxId );
00092     }
00093 
00099     protected function _insert()
00100     {
00101         // set subscription date
00102         $this->oxnewssubscribed__oxsubscribed = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
00103         return parent::_insert();
00104     }
00105 
00111     protected function _update()
00112     {
00113         if ( ( $this->_blWasSubscribed || $this->_blWasPreSubscribed ) && !$this->oxnewssubscribed__oxdboptin->value ) {
00114             // set unsubscription date
00115             $this->oxnewssubscribed__oxunsubscribed->setValue(date( 'Y-m-d H:i:s' ));
00116             // 0001974 Same object can be called many times without requiring to renew date.
00117             // If so happens, it would have _aSkipSaveFields set to skip date field. So need to check and
00118             // release if _aSkipSaveFields are set for field oxunsubscribed.
00119             $aSkipSaveFieldsKeys = array_keys( $this->_aSkipSaveFields, 'oxunsubscribed' );
00120             foreach ( $aSkipSaveFieldsKeys as $iSkipSaveFieldKey ) {
00121                 unset ( $this->_aSkipSaveFields[ $iSkipSaveFieldKey ] );
00122             }
00123         } else {
00124             // don't update date
00125             $this->_aSkipSaveFields[] = 'oxunsubscribed';
00126         }
00127 
00128         return parent::_update();
00129     }
00130 
00136     public function getOptInStatus()
00137     {
00138         return $this->oxnewssubscribed__oxdboptin->value;
00139     }
00140 
00148     public function setOptInStatus( $iStatus )
00149     {
00150         $this->oxnewssubscribed__oxdboptin = new oxField($iStatus, oxField::T_RAW);
00151         $this->save();
00152     }
00153 
00159     public function getOptInEmailStatus()
00160     {
00161         return $this->oxnewssubscribed__oxemailfailed->value;
00162     }
00163 
00171     public function setOptInEmailStatus( $iStatus )
00172     {
00173         $this->oxnewssubscribed__oxemailfailed = new oxField($iStatus, oxField::T_RAW);
00174         $this->save();
00175     }
00176 
00182     public function wasUnsubscribed()
00183     {
00184         if ( '0000-00-00 00:00:00' != $this->oxnewssubscribed__oxunsubscribed ) {
00185             return true;
00186         }
00187         return false;
00188     }
00189 
00198     public function updateSubscription( $oUser )
00199     {
00200         // user email changed ?
00201         if ( $oUser->oxuser__oxusername->value && $this->oxnewssubscribed__oxemail->value != $oUser->oxuser__oxusername->value ) {
00202             $this->oxnewssubscribed__oxemail = new oxField( $oUser->oxuser__oxusername->value, oxField::T_RAW );
00203         }
00204 
00205         // updating some other fields
00206         $this->oxnewssubscribed__oxsal   = new oxField( $oUser->oxuser__oxsal->value, oxField::T_RAW );
00207         $this->oxnewssubscribed__oxfname = new oxField( $oUser->oxuser__oxfname->value, oxField::T_RAW );
00208         $this->oxnewssubscribed__oxlname = new oxField( $oUser->oxuser__oxlname->value, oxField::T_RAW );
00209 
00210         return (bool) $this->save();
00211     }
00212 }