oxnewssubscribed.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class oxNewsSubscribed extends oxBase
00010 {
00011 
00017     protected $_blWasSubscribed = false;
00018 
00024     protected $_blWasPreSubscribed = false;
00025 
00031     protected $_sClassName = 'oxnewssubscribed';
00032 
00033 
00037     public function __construct()
00038     {
00039 
00040         parent::__construct();
00041 
00042         $this->init('oxnewssubscribed');
00043     }
00044 
00045 
00053     public function load($oxId)
00054     {
00055         $blRet = parent::load($oxId);
00056 
00057         if ($this->oxnewssubscribed__oxdboptin->value == 1) {
00058             $this->_blWasSubscribed = true;
00059         } elseif ($this->oxnewssubscribed__oxdboptin->value == 2) {
00060             $this->_blWasPreSubscribed = true;
00061         }
00062 
00063         return $blRet;
00064     }
00065 
00073     public function loadFromEmail($sEmailAddress)
00074     {
00075         $oDb = oxDb::getDb();
00076         $sEmailAddressQuoted = $oDb->quote($sEmailAddress);
00077         $sOxId = $oDb->getOne("select oxid from oxnewssubscribed where oxemail = {$sEmailAddressQuoted} ");
00078 
00079         return $this->load($sOxId);
00080     }
00081 
00089     public function loadFromUserId($sOxUserId)
00090     {
00091         $oDb = oxDb::getDb();
00092         $sOxId = $oDb->getOne("select oxid from oxnewssubscribed where oxuserid = {$oDb->quote($sOxUserId)} and oxshopid = {$oDb->quote($this->getConfig()->getShopId())}");
00093 
00094         return $this->load($sOxId);
00095     }
00096 
00102     protected function _insert()
00103     {
00104         // set subscription date
00105         $this->oxnewssubscribed__oxsubscribed = new oxField(date('Y-m-d H:i:s'), oxField::T_RAW);
00106 
00107         return parent::_insert();
00108     }
00109 
00115     protected function _update()
00116     {
00117         if (($this->_blWasSubscribed || $this->_blWasPreSubscribed) && !$this->oxnewssubscribed__oxdboptin->value) {
00118             // set unsubscription date
00119             $this->oxnewssubscribed__oxunsubscribed->setValue(date('Y-m-d H:i:s'));
00120             // 0001974 Same object can be called many times without requiring to renew date.
00121             // If so happens, it would have _aSkipSaveFields set to skip date field. So need to check and
00122             // release if _aSkipSaveFields are set for field oxunsubscribed.
00123             $aSkipSaveFieldsKeys = array_keys($this->_aSkipSaveFields, 'oxunsubscribed');
00124             foreach ($aSkipSaveFieldsKeys as $iSkipSaveFieldKey) {
00125                 unset ($this->_aSkipSaveFields[$iSkipSaveFieldKey]);
00126             }
00127         } else {
00128             // don't update date
00129             $this->_aSkipSaveFields[] = 'oxunsubscribed';
00130         }
00131 
00132         return parent::_update();
00133     }
00134 
00140     public function getOptInStatus()
00141     {
00142         return $this->oxnewssubscribed__oxdboptin->value;
00143     }
00144 
00150     public function setOptInStatus($iStatus)
00151     {
00152         $this->oxnewssubscribed__oxdboptin = new oxField($iStatus, oxField::T_RAW);
00153         $this->save();
00154     }
00155 
00161     public function getOptInEmailStatus()
00162     {
00163         return $this->oxnewssubscribed__oxemailfailed->value;
00164     }
00165 
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->value) {
00185             return true;
00186         }
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 }