Advertisement
Guest User

[ROServices]Vote4CredtisHerc

a guest
Sep 5th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. <?php
  2. class Cashpoints {
  3. public $server;
  4. public $cashRecords = array();
  5. public $pointsType = '#CASHPOINTS';
  6.  
  7. public function __construct(Flux_Athena $athenaServer, $kafraPoints=false)
  8. {
  9. $this->server = $athenaServer;
  10. if ($kafraPoints) {
  11. $this->pointsType = '#KAFRAPOINTS';
  12. }
  13. }
  14.  
  15. public function getCash($accountID)
  16. {
  17. $this->initCash($accountID);
  18.  
  19. $sql = "SELECT value FROM {$this->server->charMapDatabase}.acc_reg_num_db ";
  20. $sql .= "WHERE `key` = ? AND account_id = ? LIMIT 1";
  21. $sth = $this->server->connection->getStatement($sql);
  22. $sth->execute(array($this->pointsType, $accountID));
  23. return (int)$sth->fetch()->value;
  24. }
  25.  
  26. public function setCash($accountID, $amount)
  27. {
  28. $this->initCash($accountID);
  29.  
  30. $sql = "UPDATE {$this->server->charMapDatabase}.acc_reg_num_db ";
  31. $sql .= "SET value = ? WHERE `key` = ? AND account_id = ?";
  32. $sth = $this->server->connection->getStatement($sql);
  33.  
  34. return $sth->execute(array((int)$amount, $this->pointsType, $accountID));
  35. }
  36.  
  37. protected function initCash($accountID)
  38. {
  39. if (!array_key_exists($accountID, $this->cashRecords)) {
  40. $sql = "SELECT account_id FROM {$this->server->charMapDatabase}.acc_reg_num_db ";
  41. $sql .= "WHERE `key` = ? AND account_id = ? LIMIT 1";
  42. $sth = $this->server->connection->getStatement($sql);
  43. $sth->execute(array($this->pointsType, $accountID));
  44.  
  45. if ($sth->fetch()) {
  46. // Has prior cashpoints record.
  47. $this->cashRecords[$accountID] = true;
  48. }
  49. else {
  50. // Does not have prior cash points record.
  51. $this->cashRecords[$accountID] = false;
  52. }
  53. }
  54.  
  55. // Initialize cash points record if it doesn't already exist.
  56. if (!$this->cashRecords[$accountID]) {
  57. $sql = "INSERT INTO {$this->server->charMapDatabase}.acc_reg_num_db ";
  58. $sql .= "(`key`, value, type, account_id, char_id) ";
  59. $sql .= "VALUES (?, 0, 2, ?, 0)";
  60. $sth = $this->server->connection->getStatement($sql);
  61. $sth->execute(array($this->pointsType, $accountID));
  62. }
  63. }
  64. }
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement