OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
voucherserie_generate.php
Go to the documentation of this file.
1 <?php
2 
8 {
14  public $sClassDo = "voucherserie_generate";
15 
21  public $iGeneratePerTick = 100;
22 
28  protected $_sThisTemplate = "voucherserie_generate.tpl";
29 
35  protected $_oVoucherSerie = null;
36 
42  protected $_iGenerated = false;
43 
51  public function nextTick( $iCnt )
52  {
53  if ( $iGeneratedItems = $this->generateVoucher( $iCnt ) ) {
54  return $iGeneratedItems;
55  }
56 
57  return false;
58  }
59 
67  public function generateVoucher( $iCnt )
68  {
69  $iAmount = abs( (int) oxSession::getVar( "voucherAmount" ) );
70 
71  // creating new vouchers
72  if ( $iCnt < $iAmount && ( $oVoucherSerie = $this->_getVoucherSerie() ) ) {
73 
74  if ( !$this->_iGenerated ) {
75  $this->_iGenerated = $iCnt;
76  }
77 
78  $blRandomNr = ( bool ) oxSession::getVar( "randomVoucherNr" );
79  $sVoucherNr = $blRandomNr ? oxUtilsObject::getInstance()->generateUID() : oxSession::getVar( "voucherNr" );
80 
81  $oNewVoucher = oxNew( "oxvoucher" );
82  $oNewVoucher->oxvouchers__oxvoucherserieid = new oxField( $oVoucherSerie->getId() );
83  $oNewVoucher->oxvouchers__oxvouchernr = new oxField( $sVoucherNr );
84  $oNewVoucher->save();
85 
86  $this->_iGenerated++;
87  }
88 
89  return $this->_iGenerated;
90  }
91 
97  public function run()
98  {
99  $blContinue = true;
100  $iExportedItems = 0;
101 
102  // file is open
103  $iStart = oxConfig::getParameter("iStart");
104 
105  for ( $i = $iStart; $i < $iStart + $this->iGeneratePerTick; $i++) {
106  if ( ( $iExportedItems = $this->nextTick( $i ) ) === false ) {
107  // end reached
108  $this->stop( ERR_SUCCESS );
109  $blContinue = false;
110  break;
111  }
112  }
113 
114  if ( $blContinue) {
115  // make ticker continue
116  $this->_aViewData['refresh'] = 0;
117  $this->_aViewData['iStart'] = $i;
118  $this->_aViewData['iExpItems'] = $iExportedItems;
119  }
120  }
121 }