oxnewssubscribed.php

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