public function afterInsert(array &$values, CouponBatch $record) { switch ($values['_source']) { case self::SOURCE_GENERATE: $record->generateCoupons((int) $values['_count'], (int) $values['_code_len'], (int) $values['_code_len']); break; case self::SOURCE_FILE: $upload = new Am_Upload($this->getDi()); $upload->setTemp(3600); if (!$upload->processSubmit('file')) { throw new Am_Exception_InputError('File was not uploaded'); } /* @var $file Upload */ list($file) = $upload->getUploads(); $f = fopen($file->getFullPath(), 'r'); while ($row = fgetcsv($f)) { $coupon = $this->getDi()->couponRecord; $coupon->code = $row[0]; $coupon->batch_id = $record->pk(); try { $coupon->insert(); } catch (Exception $e) { } } fclose($f); break; default: throw new Am_Exception_InternalError(sprintf('Unknown Coupon Code Source [%s]', $values['_source'])); } }
public function afterInsert(array &$values, CouponBatch $record) { $couponsCount = intval(); $code_len = intval($vars['_code_len']); $record->generateCoupons((int) $values['_count'], (int) $values['_code_len'], (int) $values['_code_len']); }