OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
oxnewssubscribed.php
Go to the documentation of this file.
1 <?php
2 
9 class oxNewsSubscribed extends oxBase
10 {
16  protected $_blWasSubscribed = false;
17 
23  protected $_blWasPreSubscribed = false;
24 
30  protected $_sClassName = 'oxnewssubscribed';
31 
32 
36  public function __construct()
37  {
38 
40 
41  $this->init( 'oxnewssubscribed' );
42  }
43 
44 
52  public function load( $oxId )
53  {
54  $blRet = parent::load( $oxId );
55 
56  if ( $this->oxnewssubscribed__oxdboptin->value == 1 ) {
57  $this->_blWasSubscribed = true;
58  } elseif ( $this->oxnewssubscribed__oxdboptin->value == 2 ) {
59  $this->_blWasPreSubscribed = true;
60  }
61 
62  return $blRet;
63  }
64 
72  public function loadFromEmail( $sEmailAddress )
73  {
74  $oDb = oxDb::getDb();
75  $sEmailAddressQuoted = $oDb->quote( $sEmailAddress );
76  $sOxId = $oDb->getOne( "select oxid from oxnewssubscribed where oxemail = {$sEmailAddressQuoted} " );
77 
78  return $this->load( $sOxId );
79  }
80 
88  public function loadFromUserId( $sOxUserId )
89  {
90  $oDb = oxDb::getDb();
91  $sOxId = $oDb->getOne( "select oxid from oxnewssubscribed where oxuserid = {$oDb->quote( $sOxUserId )} and oxshopid = {$oDb->quote( $this->getConfig()->getShopId() )}" );
92  return $this->load( $sOxId );
93  }
94 
100  protected function _insert()
101  {
102  // set subscription date
103  $this->oxnewssubscribed__oxsubscribed = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
104  return parent::_insert();
105  }
106 
112  protected function _update()
113  {
114  if ( ( $this->_blWasSubscribed || $this->_blWasPreSubscribed ) && !$this->oxnewssubscribed__oxdboptin->value ) {
115  // set unsubscription date
116  $this->oxnewssubscribed__oxunsubscribed->setValue(date( 'Y-m-d H:i:s' ));
117  // 0001974 Same object can be called many times without requiring to renew date.
118  // If so happens, it would have _aSkipSaveFields set to skip date field. So need to check and
119  // release if _aSkipSaveFields are set for field oxunsubscribed.
120  $aSkipSaveFieldsKeys = array_keys( $this->_aSkipSaveFields, 'oxunsubscribed' );
121  foreach ( $aSkipSaveFieldsKeys as $iSkipSaveFieldKey ) {
122  unset ( $this->_aSkipSaveFields[ $iSkipSaveFieldKey ] );
123  }
124  } else {
125  // don't update date
126  $this->_aSkipSaveFields[] = 'oxunsubscribed';
127  }
128 
129  return parent::_update();
130  }
131 
137  public function getOptInStatus()
138  {
139  return $this->oxnewssubscribed__oxdboptin->value;
140  }
141 
149  public function setOptInStatus( $iStatus )
150  {
151  $this->oxnewssubscribed__oxdboptin = new oxField($iStatus, oxField::T_RAW);
152  $this->save();
153  }
154 
160  public function getOptInEmailStatus()
161  {
162  return $this->oxnewssubscribed__oxemailfailed->value;
163  }
164 
172  public function setOptInEmailStatus( $iStatus )
173  {
174  $this->oxnewssubscribed__oxemailfailed = new oxField($iStatus, oxField::T_RAW);
175  $this->save();
176  }
177 
183  public function wasUnsubscribed()
184  {
185  if ('0000-00-00 00:00:00' != $this->oxnewssubscribed__oxunsubscribed->value) {
186  return true;
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 }