voucherserie_generate.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class VoucherSerie_Generate extends VoucherSerie_Main
00008 {
00009 
00015     public $sClassDo = "voucherserie_generate";
00016 
00022     public $iGeneratePerTick = 100;
00023 
00029     protected $_sThisTemplate = "voucherserie_generate.tpl";
00030 
00036     protected $_oVoucherSerie = null;
00037 
00043     protected $_iGenerated = false;
00044 
00052     public function nextTick($iCnt)
00053     {
00054         if ($iGeneratedItems = $this->generateVoucher($iCnt)) {
00055             return $iGeneratedItems;
00056         }
00057 
00058         return false;
00059     }
00060 
00068     public function generateVoucher($iCnt)
00069     {
00070         $iAmount = abs((int) oxRegistry::getSession()->getVariable("voucherAmount"));
00071 
00072         // creating new vouchers
00073         if ($iCnt < $iAmount && ($oVoucherSerie = $this->_getVoucherSerie())) {
00074 
00075             if (!$this->_iGenerated) {
00076                 $this->_iGenerated = $iCnt;
00077             }
00078 
00079             $blRandomNr = ( bool ) oxRegistry::getSession()->getVariable("randomVoucherNr");
00080             $sVoucherNr = $blRandomNr ? oxUtilsObject::getInstance()->generateUID() : oxRegistry::getSession()->getVariable("voucherNr");
00081 
00082             $oNewVoucher = oxNew("oxvoucher");
00083             $oNewVoucher->oxvouchers__oxvoucherserieid = new oxField($oVoucherSerie->getId());
00084             $oNewVoucher->oxvouchers__oxvouchernr = new oxField($sVoucherNr);
00085             $oNewVoucher->save();
00086 
00087             $this->_iGenerated++;
00088         }
00089 
00090         return $this->_iGenerated;
00091     }
00092 
00096     public function run()
00097     {
00098         $blContinue = true;
00099         $iExportedItems = 0;
00100 
00101         // file is open
00102         $iStart = oxRegistry::getConfig()->getRequestParameter("iStart");
00103 
00104         for ($i = $iStart; $i < $iStart + $this->iGeneratePerTick; $i++) {
00105             if (($iExportedItems = $this->nextTick($i)) === false) {
00106                 // end reached
00107                 $this->stop(ERR_SUCCESS);
00108                 $blContinue = false;
00109                 break;
00110             }
00111         }
00112 
00113         if ($blContinue) {
00114             // make ticker continue
00115             $this->_aViewData['refresh'] = 0;
00116             $this->_aViewData['iStart'] = $i;
00117             $this->_aViewData['iExpItems'] = $iExportedItems;
00118         }
00119     }
00120 }