oxorderfile.php

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 = oxRegistry::get("oxUtilsDate")->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 = oxRegistry::get("oxUtilsDate")->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         return $oFile->getSize();
00126     }
00127 
00135     protected function _getFieldLongName( $sFieldName )
00136     {
00137         $aFieldNames = array(
00138             'oxorderfiles__oxarticletitle',
00139             'oxorderfiles__oxarticleartnum',
00140             'oxorderfiles__oxordernr',
00141             'oxorderfiles__oxorderdate',
00142             'oxorderfiles__oxispaid',
00143             'oxorderfiles__oxpurchasedonly'
00144         );
00145 
00146         if ( in_array( $sFieldName, $aFieldNames ) ) {
00147             return $sFieldName;
00148         }
00149 
00150         return parent::_getFieldLongName( $sFieldName );
00151     }
00152 
00158     public function isValid()
00159     {
00160         if ( !$this->oxorderfiles__oxmaxdownloadcount->value || ($this->oxorderfiles__oxdownloadcount->value < $this->oxorderfiles__oxmaxdownloadcount->value) ) {
00161 
00162             if ( !$this->oxorderfiles__oxlinkexpirationtime->value && !$this->oxorderfiles__oxdownloadxpirationtime->value ) {
00163                 return true;
00164             } else {
00165                 $sNow = oxRegistry::get("oxUtilsDate")->getTime();
00166                 $iTimestamp = strtotime($this->oxorderfiles__oxvaliduntil->value);
00167                 if ( !$iTimestamp || ( $iTimestamp > $sNow ) ) {
00168                     return true;
00169                 }
00170             }
00171         }
00172         return false;
00173     }
00174 
00180     public function isPaid()
00181     {
00182         return $this->oxorderfiles__oxispaid->value;
00183     }
00184 
00190     public function getValidUntil()
00191     {
00192         return substr( $this->oxorderfiles__oxvaliduntil->value, 0, 16 );
00193     }
00194 
00200     public function getLeftDownloadCount()
00201     {
00202         $iLeft = $this->oxorderfiles__oxmaxdownloadcount->value - $this->oxorderfiles__oxdownloadcount->value;
00203         if ($iLeft < 0) {
00204             $iLeft = 0;
00205         }
00206         return $iLeft;
00207     }
00208 
00214     public function processOrderFile()
00215     {
00216         if ( $this->isValid() ) {
00217             //first download
00218             if (!$this->oxorderfiles__oxdownloadcount->value) {
00219                 $this->oxorderfiles__oxdownloadcount = new oxField( 1 );
00220 
00221                 $iExpirationTime = $this->oxorderfiles__oxdownloadexpirationtime->value * 3600;
00222                 $iTime = oxRegistry::get("oxUtilsDate")->getTime();
00223                 $this->oxorderfiles__oxvaliduntil = new oxField( date( 'Y-m-d H:i:s', $iTime + $iExpirationTime ) );
00224 
00225                 $this->oxorderfiles__oxfirstdownload = new oxField( date( 'Y-m-d H:i:s', $iTime ) );
00226                 $this->oxorderfiles__oxlastdownload = new oxField( date( 'Y-m-d H:i:s', $iTime ) );
00227             } else {
00228                 $this->oxorderfiles__oxdownloadcount = new oxField( $this->oxorderfiles__oxdownloadcount->value + 1 );
00229 
00230                 $iTime = oxRegistry::get("oxUtilsDate")->getTime();
00231                 $this->oxorderfiles__oxlastdownload = new oxField( date( 'Y-m-d H:i:s', $iTime ) );
00232             }
00233             $this->save();
00234             return $this->oxorderfiles__oxfileid->value;
00235         }
00236         return false;
00237     }
00238 
00239     public function getFileId()
00240     {
00241         return $this->oxorderfiles__oxfileid->value;
00242     }
00243 
00244 }