oxorderfile.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxOrderFile extends oxBase
00008 {
00009 
00015     protected $_sCoreTable = 'oxorderfiles';
00016 
00022     protected $_sClassName = 'oxorderfile';
00023 
00024 
00030     public function __construct()
00031     {
00032         parent::__construct();
00033         $this->init('oxorderfiles');
00034     }
00035 
00039     public function reset()
00040     {
00041         $oArticleFile = oxNew('oxFile');
00042         $oArticleFile->load($this->oxorderfiles__oxfileid->value);
00043         if (file_exists($oArticleFile->getStoreLocation())) {
00044             $this->oxorderfiles__oxdownloadcount = new oxField(0);
00045             $this->oxorderfiles__oxfirstdownload = new oxField('0000-00-00 00:00:00');
00046             $this->oxorderfiles__oxlastdownload = new oxField('0000-00-00 00:00:00');
00047             $iExpirationTime = $this->oxorderfiles__oxlinkexpirationtime->value * 3600;
00048             $sNow = oxRegistry::get("oxUtilsDate")->getTime();
00049             $sDate = date('Y-m-d H:i:s', $sNow + $iExpirationTime);
00050             $this->oxorderfiles__oxvaliduntil = new oxField($sDate);
00051             $this->oxorderfiles__oxresetcount = new oxField($this->oxorderfiles__oxresetcount->value + 1);
00052         }
00053     }
00054 
00060     public function setOrderId($sOrderId)
00061     {
00062         $this->oxorderfiles__oxorderid = new oxField($sOrderId);
00063     }
00064 
00070     public function setOrderArticleId($sOrderArticleId)
00071     {
00072         $this->oxorderfiles__oxorderarticleid = new oxField($sOrderArticleId);
00073     }
00074 
00080     public function setShopId($sShopId)
00081     {
00082         $this->oxorderfiles__oxshopid = new oxField($sShopId);
00083     }
00084 
00094     public function setFile($sFileName, $sFileId, $iMaxDownloadCounts, $iExpirationTime, $iExpirationDownloadTime)
00095     {
00096         $sNow = oxRegistry::get("oxUtilsDate")->getTime();
00097         $sDate = date('Y-m-d G:i', $sNow + $iExpirationTime * 3600);
00098 
00099         $this->oxorderfiles__oxfileid = new oxField($sFileId);
00100         $this->oxorderfiles__oxfilename = new oxField($sFileName);
00101         $this->oxorderfiles__oxmaxdownloadcount = new oxField($iMaxDownloadCounts);
00102         $this->oxorderfiles__oxlinkexpirationtime = new oxField($iExpirationTime);
00103         $this->oxorderfiles__oxdownloadexpirationtime = new oxField($iExpirationDownloadTime);
00104         $this->oxorderfiles__oxvaliduntil = new oxField($sDate);
00105     }
00106 
00112     public function getFileSize()
00113     {
00114         $oFile = oxNew("oxfile");
00115         $oFile->load($this->oxorderfiles__oxfileid->value);
00116 
00117         return $oFile->getSize();
00118     }
00119 
00127     protected function _getFieldLongName($sFieldName)
00128     {
00129         $aFieldNames = array(
00130             'oxorderfiles__oxarticletitle',
00131             'oxorderfiles__oxarticleartnum',
00132             'oxorderfiles__oxordernr',
00133             'oxorderfiles__oxorderdate',
00134             'oxorderfiles__oxispaid',
00135             'oxorderfiles__oxpurchasedonly'
00136         );
00137 
00138         if (in_array($sFieldName, $aFieldNames)) {
00139             return $sFieldName;
00140         }
00141 
00142         return parent::_getFieldLongName($sFieldName);
00143     }
00144 
00150     public function isValid()
00151     {
00152         if (!$this->oxorderfiles__oxmaxdownloadcount->value || ($this->oxorderfiles__oxdownloadcount->value < $this->oxorderfiles__oxmaxdownloadcount->value)) {
00153 
00154             if (!$this->oxorderfiles__oxlinkexpirationtime->value && !$this->oxorderfiles__oxdownloadxpirationtime->value) {
00155                 return true;
00156             } else {
00157                 $sNow = oxRegistry::get("oxUtilsDate")->getTime();
00158                 $iTimestamp = strtotime($this->oxorderfiles__oxvaliduntil->value);
00159                 if (!$iTimestamp || ($iTimestamp > $sNow)) {
00160                     return true;
00161                 }
00162             }
00163         }
00164 
00165         return false;
00166     }
00167 
00173     public function isPaid()
00174     {
00175         return $this->oxorderfiles__oxispaid->value;
00176     }
00177 
00183     public function getValidUntil()
00184     {
00185         return substr($this->oxorderfiles__oxvaliduntil->value, 0, 16);
00186     }
00187 
00193     public function getLeftDownloadCount()
00194     {
00195         $iLeft = $this->oxorderfiles__oxmaxdownloadcount->value - $this->oxorderfiles__oxdownloadcount->value;
00196         if ($iLeft < 0) {
00197             $iLeft = 0;
00198         }
00199 
00200         return $iLeft;
00201     }
00202 
00208     public function processOrderFile()
00209     {
00210         if ($this->isValid()) {
00211             //first download
00212             if (!$this->oxorderfiles__oxdownloadcount->value) {
00213                 $this->oxorderfiles__oxdownloadcount = new oxField(1);
00214 
00215                 $iExpirationTime = $this->oxorderfiles__oxdownloadexpirationtime->value * 3600;
00216                 $iTime = oxRegistry::get("oxUtilsDate")->getTime();
00217                 $this->oxorderfiles__oxvaliduntil = new oxField(date('Y-m-d H:i:s', $iTime + $iExpirationTime));
00218 
00219                 $this->oxorderfiles__oxfirstdownload = new oxField(date('Y-m-d H:i:s', $iTime));
00220                 $this->oxorderfiles__oxlastdownload = new oxField(date('Y-m-d H:i:s', $iTime));
00221             } else {
00222                 $this->oxorderfiles__oxdownloadcount = new oxField($this->oxorderfiles__oxdownloadcount->value + 1);
00223 
00224                 $iTime = oxRegistry::get("oxUtilsDate")->getTime();
00225                 $this->oxorderfiles__oxlastdownload = new oxField(date('Y-m-d H:i:s', $iTime));
00226             }
00227             $this->save();
00228 
00229             return $this->oxorderfiles__oxfileid->value;
00230         }
00231 
00232         return false;
00233     }
00234 
00240     public function getFileId()
00241     {
00242         return $this->oxorderfiles__oxfileid->value;
00243     }
00244 }