/** * Class constructor */ public function __construct(BASE_CLASS_WidgetParameter $paramObj) { parent::__construct(); $this->creditsService = USERCREDITS_BOL_CreditsService::getInstance(); $userId = OW::getUser()->getId(); $lang = OW::getLanguage(); if (!$userId) { $this->setVisible(false); return; } $balance = $this->creditsService->getCreditsBalance($userId); $this->assign('balance', $balance); $this->setSettingValue(self::SETTING_TOOLBAR, array(array('label' => $lang->text('usercredits', 'buy_more'), 'href' => OW::getRouter()->urlForRoute('usercredits.buy_credits')))); $accountTypeId = $this->creditsService->getUserAccountTypeId($userId); $earning = (bool) $this->creditsService->findCreditsActions('earn', $accountTypeId); $losing = (bool) $this->creditsService->findCreditsActions('lose', $accountTypeId); $showCostOfActions = $earning || $losing; $this->assign('showCostOfActions', $showCostOfActions); $script = ''; if ($showCostOfActions) { $script .= '$("#credits-link-cost-of-actions").click(function(){ document.creditsEarnFloatbox = OW.ajaxFloatBox( "USERCREDITS_CMP_CostOfActions", {}, { width : 432, title: ' . json_encode($lang->text('usercredits', 'cost_of_actions')) . '} ); }); '; } $history = (bool) $this->creditsService->countUserLogEntries($userId); $this->assign('showHistory', $history); if ($history) { $script .= '$("#credits-link-history").click(function(){ document.creditsHistoryFloatbox = OW.ajaxFloatBox( "USERCREDITS_CMP_History", {}, { width : 500, title: ' . json_encode($lang->text('usercredits', 'history')) . '} ); }); '; } if (mb_strlen($script)) { OW::getDocument()->addOnloadScript($script); } }