/** * @return array */ public function getStatistics($usagePeriod = null) { $overallCount = $this->configuration->getUsages(); $usageCount = OnlineShop_Framework_VoucherService_Token::getByCode($this->configuration->getToken())->getUsages(); $reservedTokenCount = OnlineShop_Framework_VoucherService_Token_List::getCountByReservation($this->seriesId); $usage = OnlineShop_Framework_VoucherService_Statistic::getBySeriesId($this->seriesId, $usagePeriod); $this->prepareUsageStatisticData($usage, $usagePeriod); return ['overallCount' => $overallCount, 'usageCount' => $usageCount, 'freeCount' => $overallCount - $usageCount - $reservedTokenCount, 'reservedCount' => $reservedTokenCount, 'usage' => $usage]; }
/** * @param \Pimcore\Model\Object\OnlineShopVoucherSeries $series * @return bool */ public function cleanUpVoucherSeries(\Pimcore\Model\Object\OnlineShopVoucherSeries $series) { return OnlineShop_Framework_VoucherService_Token_List::cleanUpAllTokens($series->getId()); }
/** * Prepares the view and returns the according template for rendering. * * @param $view * @param array $params * @return string * @throws Zend_Paginator_Exception */ public function prepareConfigurationView($view, $params) { $view->msg = []; $tokens = new OnlineShop_Framework_VoucherService_Token_List(); try { $tokens->setFilterConditions($params['id'], $params); } catch (Exception $e) { $this->template = "voucher/voucher-code-tab-error.php"; $view->errors[] = $e->getMessage() . " | Error-Code: " . $e->getCode(); } if ($tokens) { $paginator = Zend_Paginator::factory($tokens); if ($params['tokensPerPage']) { $paginator->setItemCountPerPage((int) $params['tokensPerPage']); } else { $paginator->setItemCountPerPage(25); } $paginator->setCurrentPageNumber($params['page']); $view->paginator = $paginator; $view->count = sizeof($tokens); } else { $view->msg['result'] = $view->ts('plugin_onlineshop_voucherservice_msg-error-token-noresult'); } $view->msg['error'] = $params['error']; $view->msg['success'] = $params['success']; // Settings parsed via foreach in view -> key is translation $view->settings = [$view->ts('plugin_onlineshop_voucherservice_settings-count') => $this->getConfiguration()->getCount(), $view->ts('plugin_onlineshop_voucherservice_settings-prefix') => $this->getConfiguration()->getPrefix(), $view->ts('plugin_onlineshop_voucherservice_settings-length') => $this->getConfiguration()->getLength(), $view->ts('plugin_onlineshop_voucherservice_settings-exampletoken') => $this->getExampleToken()]; $statisticUsagePeriod = 30; if (isset($params['statisticUsagePeriod'])) { $statisticUsagePeriod = $params['statisticUsagePeriod']; } $view->tokenLengths = $this->series->getExistingLengths(); $view->statistics = $this->getStatistics($statisticUsagePeriod); return $this->template; }