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