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 $_sClassName = 'oxnewssubscribed';
00023 
00024 
00028     public function __construct()
00029     {
00030 
00031         parent::__construct();
00032 
00033         $this->init( 'oxnewssubscribed' );
00034     }
00035 
00036 
00044     public function load( $oxId )
00045     {
00046         $blRet = parent::load( $oxId );
00047 
00048         if ( $this->oxnewssubscribed__oxdboptin->value == 1) {
00049             $this->_blWasSubscribed = true;
00050         }
00051 
00052         return $blRet;
00053     }
00054 
00062     public function loadFromEmail( $sEmailAddress )
00063     {
00064         $oDb = oxDb::getDb();
00065         $sEmailAddressQuoted = $oDb->quote( $sEmailAddress );
00066             $sOxId = $oDb->getOne( "select oxid from oxnewssubscribed where oxemail = {$sEmailAddressQuoted} " );
00067 
00068         return $this->load( $sOxId );
00069     }
00070 
00078     public function loadFromUserId( $sOxUserId )
00079     {
00080         $oDb = oxDb::getDb( true );
00081         $sOxId = $oDb->getOne( "select oxid from oxnewssubscribed where oxuserid = " . $oDb->quote( $sOxUserId ) );
00082         return $this->load( $sOxId );
00083     }
00084 
00090     protected function _insert()
00091     {
00092         // set subscription date
00093         $this->oxnewssubscribed__oxsubscribed = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
00094         return parent::_insert();
00095     }
00096 
00102     protected function _update()
00103     {
00104         if ( $this->_blWasSubscribed && !$this->oxnewssubscribed__oxdboptin->value ) {
00105             // set unsubscription date
00106             $this->oxnewssubscribed__oxunsubscribed->setValue(date( 'Y-m-d H:i:s' ));
00107         } else {
00108             // don't update date
00109             $this->_aSkipSaveFields[] = 'oxunsubscribed';
00110         }
00111 
00112         return parent::_update();
00113     }
00114 
00120     public function getOptInStatus()
00121     {
00122         return $this->oxnewssubscribed__oxdboptin->value;
00123     }
00124 
00132     public function setOptInStatus( $iStatus )
00133     {
00134         $this->oxnewssubscribed__oxdboptin = new oxField($iStatus, oxField::T_RAW);
00135         $this->save();
00136     }
00137 
00143     public function getOptInEmailStatus()
00144     {
00145         return $this->oxnewssubscribed__oxemailfailed->value;
00146     }
00147 
00155     public function setOptInEmailStatus( $iStatus )
00156     {
00157         $this->oxnewssubscribed__oxemailfailed = new oxField($iStatus, oxField::T_RAW);
00158         $this->save();
00159     }
00160 
00169     public function updateSubscription( $oUser )
00170     {
00171         // user email changed ?
00172         if ( $oUser->oxuser__oxusername->value && $this->oxnewssubscribed__oxemail->value != $oUser->oxuser__oxusername->value ) {
00173             $this->oxnewssubscribed__oxemail = new oxField( $oUser->oxuser__oxusername->value, oxField::T_RAW );
00174         }
00175 
00176         // updating some other fields
00177         $this->oxnewssubscribed__oxsal   = new oxField( $oUser->oxuser__oxsal->value, oxField::T_RAW );
00178         $this->oxnewssubscribed__oxfname = new oxField( $oUser->oxuser__oxfname->value, oxField::T_RAW );
00179         $this->oxnewssubscribed__oxlname = new oxField( $oUser->oxuser__oxlname->value, oxField::T_RAW );
00180 
00181         return (bool) $this->save();
00182     }
00183 }