OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
oxorderfile.php
Go to the documentation of this file.
1 <?php
2 
7 class oxOrderFile extends oxBase
8 {
9 
15  protected $_sCoreTable = 'oxorderfiles';
16 
22  protected $_sClassName = 'oxorderfile';
23 
24 
30  public function __construct()
31  {
33  $this->init('oxorderfiles');
34  }
35 
39  public function reset()
40  {
41  $oArticleFile = oxNew('oxFile');
42  $oArticleFile->load($this->oxorderfiles__oxfileid->value);
43  if (file_exists($oArticleFile->getStoreLocation())) {
44  $this->oxorderfiles__oxdownloadcount = new oxField(0);
45  $this->oxorderfiles__oxfirstdownload = new oxField('0000-00-00 00:00:00');
46  $this->oxorderfiles__oxlastdownload = new oxField('0000-00-00 00:00:00');
47  $iExpirationTime = $this->oxorderfiles__oxlinkexpirationtime->value * 3600;
48  $sNow = oxRegistry::get("oxUtilsDate")->getTime();
49  $sDate = date('Y-m-d H:i:s', $sNow + $iExpirationTime);
50  $this->oxorderfiles__oxvaliduntil = new oxField($sDate);
51  $this->oxorderfiles__oxresetcount = new oxField($this->oxorderfiles__oxresetcount->value + 1);
52  }
53  }
54 
60  public function setOrderId($sOrderId)
61  {
62  $this->oxorderfiles__oxorderid = new oxField($sOrderId);
63  }
64 
70  public function setOrderArticleId($sOrderArticleId)
71  {
72  $this->oxorderfiles__oxorderarticleid = new oxField($sOrderArticleId);
73  }
74 
80  public function setShopId($sShopId)
81  {
82  $this->oxorderfiles__oxshopid = new oxField($sShopId);
83  }
84 
94  public function setFile($sFileName, $sFileId, $iMaxDownloadCounts, $iExpirationTime, $iExpirationDownloadTime)
95  {
96  $sNow = oxRegistry::get("oxUtilsDate")->getTime();
97  $sDate = date('Y-m-d G:i', $sNow + $iExpirationTime * 3600);
98 
99  $this->oxorderfiles__oxfileid = new oxField($sFileId);
100  $this->oxorderfiles__oxfilename = new oxField($sFileName);
101  $this->oxorderfiles__oxmaxdownloadcount = new oxField($iMaxDownloadCounts);
102  $this->oxorderfiles__oxlinkexpirationtime = new oxField($iExpirationTime);
103  $this->oxorderfiles__oxdownloadexpirationtime = new oxField($iExpirationDownloadTime);
104  $this->oxorderfiles__oxvaliduntil = new oxField($sDate);
105  }
106 
112  public function getFileSize()
113  {
114  $oFile = oxNew("oxfile");
115  $oFile->load($this->oxorderfiles__oxfileid->value);
116 
117  return $oFile->getSize();
118  }
119 
127  protected function _getFieldLongName($sFieldName)
128  {
129  $aFieldNames = array(
130  'oxorderfiles__oxarticletitle',
131  'oxorderfiles__oxarticleartnum',
132  'oxorderfiles__oxordernr',
133  'oxorderfiles__oxorderdate',
134  'oxorderfiles__oxispaid',
135  'oxorderfiles__oxpurchasedonly'
136  );
137 
138  if (in_array($sFieldName, $aFieldNames)) {
139  return $sFieldName;
140  }
141 
142  return parent::_getFieldLongName($sFieldName);
143  }
144 
150  public function isValid()
151  {
152  if (!$this->oxorderfiles__oxmaxdownloadcount->value || ($this->oxorderfiles__oxdownloadcount->value < $this->oxorderfiles__oxmaxdownloadcount->value)) {
153 
154  if (!$this->oxorderfiles__oxlinkexpirationtime->value && !$this->oxorderfiles__oxdownloadxpirationtime->value) {
155  return true;
156  } else {
157  $sNow = oxRegistry::get("oxUtilsDate")->getTime();
158  $iTimestamp = strtotime($this->oxorderfiles__oxvaliduntil->value);
159  if (!$iTimestamp || ($iTimestamp > $sNow)) {
160  return true;
161  }
162  }
163  }
164 
165  return false;
166  }
167 
173  public function isPaid()
174  {
175  return $this->oxorderfiles__oxispaid->value;
176  }
177 
183  public function getValidUntil()
184  {
185  return substr($this->oxorderfiles__oxvaliduntil->value, 0, 16);
186  }
187 
193  public function getLeftDownloadCount()
194  {
195  $iLeft = $this->oxorderfiles__oxmaxdownloadcount->value - $this->oxorderfiles__oxdownloadcount->value;
196  if ($iLeft < 0) {
197  $iLeft = 0;
198  }
199 
200  return $iLeft;
201  }
202 
208  public function processOrderFile()
209  {
210  if ($this->isValid()) {
211  //first download
212  if (!$this->oxorderfiles__oxdownloadcount->value) {
213  $this->oxorderfiles__oxdownloadcount = new oxField(1);
214 
215  $iExpirationTime = $this->oxorderfiles__oxdownloadexpirationtime->value * 3600;
216  $iTime = oxRegistry::get("oxUtilsDate")->getTime();
217  $this->oxorderfiles__oxvaliduntil = new oxField(date('Y-m-d H:i:s', $iTime + $iExpirationTime));
218 
219  $this->oxorderfiles__oxfirstdownload = new oxField(date('Y-m-d H:i:s', $iTime));
220  $this->oxorderfiles__oxlastdownload = new oxField(date('Y-m-d H:i:s', $iTime));
221  } else {
222  $this->oxorderfiles__oxdownloadcount = new oxField($this->oxorderfiles__oxdownloadcount->value + 1);
223 
224  $iTime = oxRegistry::get("oxUtilsDate")->getTime();
225  $this->oxorderfiles__oxlastdownload = new oxField(date('Y-m-d H:i:s', $iTime));
226  }
227  $this->save();
228 
229  return $this->oxorderfiles__oxfileid->value;
230  }
231 
232  return false;
233  }
234 
240  public function getFileId()
241  {
242  return $this->oxorderfiles__oxfileid->value;
243  }
244 }