Go to the documentation of this file.00001 <?php
00002
00007 class oxOrderFile extends oxBase
00008 {
00014 protected $_sCoreTable = 'oxorderfiles';
00015
00021 protected $_sClassName = 'oxorderfile';
00022
00023
00029 public function __construct()
00030 {
00031 parent::__construct();
00032 $this->init('oxorderfiles');
00033 }
00034
00040 public function reset()
00041 {
00042 $oArticleFile = oxNew('oxFile');
00043 $oArticleFile->load($this->oxorderfiles__oxfileid->value);
00044 if ( file_exists($oArticleFile->getStoreLocation()) ) {
00045 $this->oxorderfiles__oxdownloadcount = new oxField( 0 );
00046 $this->oxorderfiles__oxfirstdownload = new oxField( '0000-00-00 00:00:00' );
00047 $this->oxorderfiles__oxlastdownload = new oxField( '0000-00-00 00:00:00' );
00048 $iExpirationTime = $this->oxorderfiles__oxlinkexpirationtime->value * 3600;
00049 $sNow = oxUtilsDate::getInstance()->getTime();
00050 $sDate = date( 'Y-m-d H:i:s', $sNow + $iExpirationTime );
00051 $this->oxorderfiles__oxvaliduntil = new oxField( $sDate );
00052 $this->oxorderfiles__oxresetcount = new oxField( $this->oxorderfiles__oxresetcount->value + 1 );
00053 }
00054 }
00055
00063 public function setOrderId( $sOrderId )
00064 {
00065 $this->oxorderfiles__oxorderid = new oxField( $sOrderId );
00066 }
00067
00075 public function setOrderArticleId( $sOrderArticleId )
00076 {
00077 $this->oxorderfiles__oxorderarticleid = new oxField( $sOrderArticleId );
00078 }
00079
00087 public function setShopId( $sShopId )
00088 {
00089 $this->oxorderfiles__oxshopid = new oxField( $sShopId );
00090 }
00091
00103 public function setFile( $sFileName, $sFileId, $iMaxDownloadCounts, $iExpirationTime, $iExpirationDownloadTime )
00104 {
00105 $sNow = oxUtilsDate::getInstance()->getTime();
00106 $sDate = date( 'Y-m-d G:i', $sNow + $iExpirationTime*3600 );
00107
00108 $this->oxorderfiles__oxfileid = new oxField( $sFileId );
00109 $this->oxorderfiles__oxfilename = new oxField( $sFileName );
00110 $this->oxorderfiles__oxmaxdownloadcount = new oxField( $iMaxDownloadCounts );
00111 $this->oxorderfiles__oxlinkexpirationtime = new oxField( $iExpirationTime );
00112 $this->oxorderfiles__oxdownloadexpirationtime = new oxField( $iExpirationDownloadTime );
00113 $this->oxorderfiles__oxvaliduntil = new oxField( $sDate );
00114 }
00115
00121 public function getFileSize()
00122 {
00123 $oFile = oxNew("oxfile");
00124 $oFile->load($this->oxorderfiles__oxfileid->value);
00125
00126 return $oFile->getSize();
00127 }
00128
00136 protected function _getFieldLongName( $sFieldName )
00137 {
00138 $aFieldNames = array(
00139 'oxorderfiles__oxarticletitle',
00140 'oxorderfiles__oxarticleartnum',
00141 'oxorderfiles__oxordernr',
00142 'oxorderfiles__oxorderdate',
00143 'oxorderfiles__oxispaid',
00144 'oxorderfiles__oxpurchasedonly'
00145 );
00146
00147 if ( in_array( $sFieldName, $aFieldNames ) ) {
00148 return $sFieldName;
00149 }
00150
00151 return parent::_getFieldLongName( $sFieldName );
00152 }
00153
00159 public function isValid()
00160 {
00161 if ( !$this->oxorderfiles__oxmaxdownloadcount->value || ($this->oxorderfiles__oxdownloadcount->value < $this->oxorderfiles__oxmaxdownloadcount->value) ) {
00162
00163 if ( !$this->oxorderfiles__oxlinkexpirationtime->value && !$this->oxorderfiles__oxdownloadxpirationtime->value ) {
00164 return true;
00165 } else {
00166 $sNow = oxUtilsDate::getInstance()->getTime();
00167 $iTimestamp = strtotime($this->oxorderfiles__oxvaliduntil->value);
00168 if ( !$iTimestamp || ( $iTimestamp > $sNow ) ) {
00169 return true;
00170 }
00171 }
00172 }
00173 return false;
00174 }
00175
00181 public function isPaid()
00182 {
00183 return $this->oxorderfiles__oxispaid->value;
00184 }
00185
00191 public function getValidUntil()
00192 {
00193 return substr( $this->oxorderfiles__oxvaliduntil->value, 0, 16 );
00194 }
00195
00201 public function getLeftDownloadCount()
00202 {
00203 $iLeft = $this->oxorderfiles__oxmaxdownloadcount->value - $this->oxorderfiles__oxdownloadcount->value;
00204 if ($iLeft < 0) {
00205 $iLeft = 0;
00206 }
00207 return $iLeft;
00208 }
00209
00215 public function processOrderFile()
00216 {
00217 if ( $this->isValid() ) {
00218
00219 if (!$this->oxorderfiles__oxdownloadcount->value) {
00220 $this->oxorderfiles__oxdownloadcount = new oxField( 1 );
00221
00222 $iExpirationTime = $this->oxorderfiles__oxdownloadexpirationtime->value * 3600;
00223 $iTime = oxUtilsDate::getInstance()->getTime();
00224 $this->oxorderfiles__oxvaliduntil = new oxField( date( 'Y-m-d H:i:s', $iTime + $iExpirationTime ) );
00225
00226 $this->oxorderfiles__oxfirstdownload = new oxField( date( 'Y-m-d H:i:s', $iTime ) );
00227 $this->oxorderfiles__oxlastdownload = new oxField( date( 'Y-m-d H:i:s', $iTime ) );
00228 } else {
00229 $this->oxorderfiles__oxdownloadcount = new oxField( $this->oxorderfiles__oxdownloadcount->value + 1 );
00230
00231 $iTime = oxUtilsDate::getInstance()->getTime();
00232 $this->oxorderfiles__oxlastdownload = new oxField( date( 'Y-m-d H:i:s', $iTime ) );
00233 }
00234 $this->save();
00235 return $this->oxorderfiles__oxfileid->value;
00236 }
00237 return false;
00238 }
00239
00240 }