Esempio n. 1
0
 /**
  * Returns an instance of class.
  *
  * @return USERCREDITS_BOL_ActionDao
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Esempio n. 2
0
 /**
  * @param $userId
  * @param $page
  * @param $limit
  * @return array
  */
 public function findListForUser($userId, $page, $limit)
 {
     $actionDao = USERCREDITS_BOL_ActionDao::getInstance();
     $start = ($page - 1) * $limit;
     $sql = 'SELECT `l`.*, `a`.`pluginKey`, `a`.`actionKey` FROM `' . $this->getTableName() . '` AS `l`
         INNER JOIN `' . $actionDao->getTableName() . '` AS `a` ON (`a`.`id` = `l`.`actionId`)
         WHERE `l`.`userId` = :uid
         ORDER BY `l`.`logTimestamp` DESC
         LIMIT :start, :limit';
     return $this->dbo->queryForList($sql, array('uid' => $userId, 'start' => $start, 'limit' => $limit));
 }
Esempio 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());
 }
Esempio n. 4
0
 /**
  * Finds action by Id
  *
  * @param int $actionId
  * @return USERCREDITS_BOL_Action
  */
 public function findActionById($actionId)
 {
     return $this->actionDao->findById($actionId);
 }
Esempio n. 5
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);
 }