Ejemplo n.º 1
0
 public function setCredits()
 {
     if (!OW::getRequest()->isAjax()) {
         throw new Redirect404Exception();
     }
     if (!OW::getUser()->isAuthorized('usercredits')) {
         throw new AuthenticateException();
     }
     $form = new USERCREDITS_CLASS_SetCreditsForm();
     if ($form->isValid($_POST)) {
         $lang = OW::getLanguage();
         $creditService = USERCREDITS_BOL_CreditsService::getInstance();
         $values = $form->getValues();
         $userId = (int) $values['userId'];
         $balance = abs((int) $values['balance']);
         $balanceValues = $creditService->getBalanceForUserList(array($userId));
         $oldBalance = 0;
         if (!empty($balanceValues[$userId])) {
             $oldBalance = (int) $balanceValues[$userId];
         }
         $amount = $balance - $oldBalance;
         $creditService->setBalance($userId, $balance);
         $data = array('amount' => $amount, 'balance' => $balance, 'userId' => $userId);
         $event = new OW_Event('usercredits.set_by_moderator', $data);
         OW::getEventManager()->trigger($event);
         $balance = $creditService->getCreditsBalance($userId);
         exit(json_encode(array("message" => $lang->text('usercredits', 'credit_balance_updated'), "credits" => $balance, "text" => OW::getLanguage()->text('usercredits', 'profile_toolbar_item_credits', array('credits' => $balance)))));
     }
 }
Ejemplo n.º 2
0
 public function setCredits()
 {
     if (!OW::getRequest()->isAjax()) {
         throw new Redirect404Exception();
     }
     if (!OW::getUser()->isAuthorized('usercredits')) {
         throw new AuthenticateException();
     }
     $form = new USERCREDITS_CLASS_SetCreditsForm();
     if ($form->isValid($_POST)) {
         $lang = OW::getLanguage();
         $creditService = USERCREDITS_BOL_CreditsService::getInstance();
         $values = $form->getValues();
         $userId = (int) $values['userId'];
         $balance = abs((int) $values['balance']);
         $creditService->setBalance($userId, $balance);
         exit(json_encode(array("message" => $lang->text('usercredits', 'credit_balance_updated'), "credits" => $balance, "text" => OW::getLanguage()->text('usercredits', 'profile_toolbar_item_credits', array('credits' => $balance)))));
     }
 }