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