Exemplo n.º 1
0
 /**
  * Returns an instance of class.
  *
  * @return USERCREDITS_BOL_LogDao
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Exemplo n.º 2
0
 /**
  * @param $userId
  * @return int
  */
 public function countUserLogEntries($userId)
 {
     if (!$userId) {
         return 0;
     }
     return $this->logDao->countEntriesForUser($userId);
 }
Exemplo n.º 3
0
 public function purchase()
 {
     $creditValue = (double) $_POST['creditValue'];
     $buyingUser = (int) $_POST['buyingUser'];
     $itemName = $_POST['itemName'];
     $itemPrice = $_POST['itemPrice'];
     $itemCurrency = $_POST['itemCurrency'];
     $saleHash = $_POST['custom'];
     $transId = $_POST['transId'];
     $billingService = BOL_BillingService::getInstance();
     $adapter = new BILLINGCREDITS_CLASS_CreditsAdapter();
     $sale = $billingService->getSaleByHash($saleHash);
     if ($sale && $sale->status != BOL_BillingSaleDao::STATUS_DELIVERED) {
         $sale->transactionUid = $transId;
         if ($billingService->verifySale($adapter, $sale)) {
             $sale = $billingService->getSaleById($sale->id);
             $productAdapter = $billingService->getProductAdapter($sale->entityKey);
             if ($productAdapter) {
                 $billingService->deliverSale($productAdapter, $sale);
                 USERCREDITS_BOL_CreditsService::getInstance()->decreaseBalance($buyingUser, $creditValue);
                 $actionId = 0;
                 foreach (USERCREDITS_BOL_ActionDao::getInstance()->findActionsByPluginKey('billingcredits') as $action) {
                     if ($action->actionKey == 'creditsbuy') {
                         $actionId = $action->id;
                     }
                 }
                 if ($actionId) {
                     $log = new USERCREDITS_BOL_Log();
                     $log->actionId = $actionId;
                     $log->userId = $buyingUser;
                     $log->amount = (int) $creditValue;
                     $log->logTimestamp = time();
                     USERCREDITS_BOL_LogDao::getInstance()->save($log);
                 }
             }
         }
     }
     $this->redirect(BOL_BillingService::getInstance()->getOrderCompletedPageUrl());
 }
Exemplo n.º 4
0
 public function getCreditHistoryCountForAllUsers()
 {
     $logDao = USERCREDITS_BOL_LogDao::getInstance();
     $actionDao = USERCREDITS_BOL_ActionDao::getInstance();
     $query = "SELECT COUNT(*)\n                        FROM " . $logDao->getTableName() . " l," . $actionDao->getTableName() . " a\n                       WHERE l.actionId = a.id\n                         AND l.actionId = " . $this->getSentActionId() . "\n                         AND a.isHidden = 0\n                         AND a.active = 1";
     return (int) OW::getDbo()->queryForColumn($query);
 }
Exemplo n.º 5
0
 public function deleteUserCreditLogByUserId($userId)
 {
     return $this->logDao->deleteUserCreditLogByUserId($userId);
 }
Exemplo n.º 6
0
 /**
  * Finds action log record
  * 
  * @param int $userId
  * @param int $actionId
  * @return USERCREDITS_BOL_Log
  */
 public function findLog($userId, $actionId)
 {
     return $this->logDao->findLast($userId, $actionId);
 }