OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxorderfile.php
Go to the documentation of this file.
1 <?php
2 
7 class oxOrderFile extends oxBase
8 {
14  protected $_sCoreTable = 'oxorderfiles';
15 
21  protected $_sClassName = 'oxorderfile';
22 
23 
29  public function __construct()
30  {
32  $this->init('oxorderfiles');
33  }
34 
40  public function reset()
41  {
42  $oArticleFile = oxNew('oxFile');
43  $oArticleFile->load($this->oxorderfiles__oxfileid->value);
44  if ( file_exists($oArticleFile->getStoreLocation()) ) {
45  $this->oxorderfiles__oxdownloadcount = new oxField( 0 );
46  $this->oxorderfiles__oxfirstdownload = new oxField( '0000-00-00 00:00:00' );
47  $this->oxorderfiles__oxlastdownload = new oxField( '0000-00-00 00:00:00' );
48  $iExpirationTime = $this->oxorderfiles__oxlinkexpirationtime->value * 3600;
49  $sNow = oxRegistry::get("oxUtilsDate")->getTime();
50  $sDate = date( 'Y-m-d H:i:s', $sNow + $iExpirationTime );
51  $this->oxorderfiles__oxvaliduntil = new oxField( $sDate );
52  $this->oxorderfiles__oxresetcount = new oxField( $this->oxorderfiles__oxresetcount->value + 1 );
53  }
54  }
55 
63  public function setOrderId( $sOrderId )
64  {
65  $this->oxorderfiles__oxorderid = new oxField( $sOrderId );
66  }
67 
75  public function setOrderArticleId( $sOrderArticleId )
76  {
77  $this->oxorderfiles__oxorderarticleid = new oxField( $sOrderArticleId );
78  }
79 
87  public function setShopId( $sShopId )
88  {
89  $this->oxorderfiles__oxshopid = new oxField( $sShopId );
90  }
91 
103  public function setFile( $sFileName, $sFileId, $iMaxDownloadCounts, $iExpirationTime, $iExpirationDownloadTime )
104  {
105  $sNow = oxRegistry::get("oxUtilsDate")->getTime();
106  $sDate = date( 'Y-m-d G:i', $sNow + $iExpirationTime*3600 );
107 
108  $this->oxorderfiles__oxfileid = new oxField( $sFileId );
109  $this->oxorderfiles__oxfilename = new oxField( $sFileName );
110  $this->oxorderfiles__oxmaxdownloadcount = new oxField( $iMaxDownloadCounts );
111  $this->oxorderfiles__oxlinkexpirationtime = new oxField( $iExpirationTime );
112  $this->oxorderfiles__oxdownloadexpirationtime = new oxField( $iExpirationDownloadTime );
113  $this->oxorderfiles__oxvaliduntil = new oxField( $sDate );
114  }
115 
121  public function getFileSize()
122  {
123  $oFile = oxNew("oxfile");
124  $oFile->load($this->oxorderfiles__oxfileid->value);
125  return $oFile->getSize();
126  }
127 
135  protected function _getFieldLongName( $sFieldName )
136  {
137  $aFieldNames = array(
138  'oxorderfiles__oxarticletitle',
139  'oxorderfiles__oxarticleartnum',
140  'oxorderfiles__oxordernr',
141  'oxorderfiles__oxorderdate',
142  'oxorderfiles__oxispaid',
143  'oxorderfiles__oxpurchasedonly'
144  );
145 
146  if ( in_array( $sFieldName, $aFieldNames ) ) {
147  return $sFieldName;
148  }
149 
150  return parent::_getFieldLongName( $sFieldName );
151  }
152 
158  public function isValid()
159  {
160  if ( !$this->oxorderfiles__oxmaxdownloadcount->value || ($this->oxorderfiles__oxdownloadcount->value < $this->oxorderfiles__oxmaxdownloadcount->value) ) {
161 
162  if ( !$this->oxorderfiles__oxlinkexpirationtime->value && !$this->oxorderfiles__oxdownloadxpirationtime->value ) {
163  return true;
164  } else {
165  $sNow = oxRegistry::get("oxUtilsDate")->getTime();
166  $iTimestamp = strtotime($this->oxorderfiles__oxvaliduntil->value);
167  if ( !$iTimestamp || ( $iTimestamp > $sNow ) ) {
168  return true;
169  }
170  }
171  }
172  return false;
173  }
174 
180  public function isPaid()
181  {
182  return $this->oxorderfiles__oxispaid->value;
183  }
184 
190  public function getValidUntil()
191  {
192  return substr( $this->oxorderfiles__oxvaliduntil->value, 0, 16 );
193  }
194 
200  public function getLeftDownloadCount()
201  {
202  $iLeft = $this->oxorderfiles__oxmaxdownloadcount->value - $this->oxorderfiles__oxdownloadcount->value;
203  if ($iLeft < 0) {
204  $iLeft = 0;
205  }
206  return $iLeft;
207  }
208 
214  public function processOrderFile()
215  {
216  if ( $this->isValid() ) {
217  //first download
218  if (!$this->oxorderfiles__oxdownloadcount->value) {
219  $this->oxorderfiles__oxdownloadcount = new oxField( 1 );
220 
221  $iExpirationTime = $this->oxorderfiles__oxdownloadexpirationtime->value * 3600;
222  $iTime = oxRegistry::get("oxUtilsDate")->getTime();
223  $this->oxorderfiles__oxvaliduntil = new oxField( date( 'Y-m-d H:i:s', $iTime + $iExpirationTime ) );
224 
225  $this->oxorderfiles__oxfirstdownload = new oxField( date( 'Y-m-d H:i:s', $iTime ) );
226  $this->oxorderfiles__oxlastdownload = new oxField( date( 'Y-m-d H:i:s', $iTime ) );
227  } else {
228  $this->oxorderfiles__oxdownloadcount = new oxField( $this->oxorderfiles__oxdownloadcount->value + 1 );
229 
230  $iTime = oxRegistry::get("oxUtilsDate")->getTime();
231  $this->oxorderfiles__oxlastdownload = new oxField( date( 'Y-m-d H:i:s', $iTime ) );
232  }
233  $this->save();
234  return $this->oxorderfiles__oxfileid->value;
235  }
236  return false;
237  }
238 
239  public function getFileId()
240  {
241  return $this->oxorderfiles__oxfileid->value;
242  }
243 
244 }