OXID eShop CE  4.10.4
 All Classes Namespaces Files Functions Variables Pages
oxnewssubscribed.php
Go to the documentation of this file.
1 <?php
2 
9 class oxNewsSubscribed extends oxBase
10 {
11 
17  protected $_blWasSubscribed = false;
18 
24  protected $_blWasPreSubscribed = false;
25 
31  protected $_sClassName = 'oxnewssubscribed';
32 
33 
37  public function __construct()
38  {
39 
41 
42  $this->init('oxnewssubscribed');
43  }
44 
45 
53  public function load($oxId)
54  {
55  $blRet = parent::load($oxId);
56 
57  if ($this->oxnewssubscribed__oxdboptin->value == 1) {
58  $this->_blWasSubscribed = true;
59  } elseif ($this->oxnewssubscribed__oxdboptin->value == 2) {
60  $this->_blWasPreSubscribed = true;
61  }
62 
63  return $blRet;
64  }
65 
73  public function loadFromEmail($sEmailAddress)
74  {
75  $oDb = oxDb::getDb();
76  $sEmailAddressQuoted = $oDb->quote($sEmailAddress);
77  $sOxId = $oDb->getOne("select oxid from oxnewssubscribed where oxemail = {$sEmailAddressQuoted} ");
78 
79  return $this->load($sOxId);
80  }
81 
89  public function loadFromUserId($sOxUserId)
90  {
91  $oDb = oxDb::getDb();
92  $sOxId = $oDb->getOne("select oxid from oxnewssubscribed where oxuserid = {$oDb->quote($sOxUserId)} and oxshopid = {$oDb->quote($this->getConfig()->getShopId())}");
93 
94  return $this->load($sOxId);
95  }
96 
102  protected function _insert()
103  {
104  // set subscription date
105  $this->oxnewssubscribed__oxsubscribed = new oxField(date('Y-m-d H:i:s'), oxField::T_RAW);
106 
107  return parent::_insert();
108  }
109 
115  protected function _update()
116  {
117  if (($this->_blWasSubscribed || $this->_blWasPreSubscribed) && !$this->oxnewssubscribed__oxdboptin->value) {
118  // set unsubscription date
119  $this->oxnewssubscribed__oxunsubscribed->setValue(date('Y-m-d H:i:s'));
120  // 0001974 Same object can be called many times without requiring to renew date.
121  // If so happens, it would have _aSkipSaveFields set to skip date field. So need to check and
122  // release if _aSkipSaveFields are set for field oxunsubscribed.
123  $aSkipSaveFieldsKeys = array_keys($this->_aSkipSaveFields, 'oxunsubscribed');
124  foreach ($aSkipSaveFieldsKeys as $iSkipSaveFieldKey) {
125  unset ($this->_aSkipSaveFields[$iSkipSaveFieldKey]);
126  }
127  } else {
128  // don't update date
129  $this->_aSkipSaveFields[] = 'oxunsubscribed';
130  }
131 
132  return parent::_update();
133  }
134 
140  public function getOptInStatus()
141  {
142  return $this->oxnewssubscribed__oxdboptin->value;
143  }
144 
150  public function setOptInStatus($iStatus)
151  {
152  $this->oxnewssubscribed__oxdboptin = new oxField($iStatus, oxField::T_RAW);
153  $this->save();
154  }
155 
161  public function getOptInEmailStatus()
162  {
163  return $this->oxnewssubscribed__oxemailfailed->value;
164  }
165 
171  public function setOptInEmailStatus($iStatus)
172  {
173  $this->oxnewssubscribed__oxemailfailed = new oxField($iStatus, oxField::T_RAW);
174  $this->save();
175  }
176 
182  public function wasUnsubscribed()
183  {
184  if ('0000-00-00 00:00:00' != $this->oxnewssubscribed__oxunsubscribed->value) {
185  return true;
186  }
187 
188  return false;
189  }
190 
199  public function updateSubscription($oUser)
200  {
201  // user email changed ?
202  if ($oUser->oxuser__oxusername->value && $this->oxnewssubscribed__oxemail->value != $oUser->oxuser__oxusername->value) {
203  $this->oxnewssubscribed__oxemail = new oxField($oUser->oxuser__oxusername->value, oxField::T_RAW);
204  }
205 
206  // updating some other fields
207  $this->oxnewssubscribed__oxsal = new oxField($oUser->oxuser__oxsal->value, oxField::T_RAW);
208  $this->oxnewssubscribed__oxfname = new oxField($oUser->oxuser__oxfname->value, oxField::T_RAW);
209  $this->oxnewssubscribed__oxlname = new oxField($oUser->oxuser__oxlname->value, oxField::T_RAW);
210 
211  return (bool) $this->save();
212  }
213 }