BxStripeConnectDb.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup StripeConnect Stripe Connect
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. class BxStripeConnectDb extends BxBaseModConnectDb
  12. {
  13. public function __construct(&$oConfig)
  14. {
  15. parent::__construct($oConfig);
  16. }
  17. public function getAccount($aParams = [])
  18. {
  19. $CNF = &$this->_oConfig->CNF;
  20. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  21. $sJoinClause = $sWhereClause = "";
  22. switch($aParams['sample']) {
  23. case 'id':
  24. $aMethod['name'] = 'getRow';
  25. $aMethod['params'][1] = [
  26. 'id' => $aParams['id']
  27. ];
  28. $sWhereClause = " AND `te`.`id`=:id";
  29. break;
  30. case 'profile_id':
  31. $aMethod['name'] = 'getRow';
  32. $aMethod['params'][1] = [
  33. 'profile_id' => $aParams['profile_id']
  34. ];
  35. $sWhereClause = " AND `te`.`profile_id`=:profile_id";
  36. break;
  37. case 'account_id':
  38. $aMethod['name'] = 'getRow';
  39. if(!empty($aParams['live_account_id'])) {
  40. $aMethod['params'][1] = [
  41. 'live_account_id' => $aParams['live_account_id']
  42. ];
  43. $sWhereClause = " AND `te`.`live_account_id`=:live_account_id";
  44. }
  45. if(!empty($aParams['test_account_id'])) {
  46. $aMethod['params'][1] = [
  47. 'test_account_id' => $aParams['test_account_id']
  48. ];
  49. $sWhereClause = " AND `te`.`test_account_id`=:test_account_id";
  50. }
  51. break;
  52. }
  53. $aMethod['params'][0] = "SELECT `te`.*
  54. FROM `" . $CNF['TABLE_ENTRIES'] . "` AS `te`" . $sJoinClause . "
  55. WHERE 1" . $sWhereClause;
  56. return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
  57. }
  58. public function insertAccount($aSet)
  59. {
  60. $CNF = &$this->_oConfig->CNF;
  61. if(!isset($aSet[$CNF['FIELD_ADDED']]))
  62. $aSet[$CNF['FIELD_ADDED']] = time();
  63. if(!isset($aSet[$CNF['FIELD_CHANGED']]))
  64. $aSet[$CNF['FIELD_CHANGED']] = time();
  65. return (int)$this->query("INSERT INTO `" . $CNF['TABLE_ENTRIES'] . "` SET " . $this->arrayToSQL($aSet)) > 0;
  66. }
  67. public function updateAccount($aSet, $aWhere)
  68. {
  69. $CNF = &$this->_oConfig->CNF;
  70. if(!isset($aSet[$CNF['FIELD_CHANGED']]))
  71. $aSet[$CNF['FIELD_CHANGED']] = time();
  72. return (int)$this->query("UPDATE `" . $CNF['TABLE_ENTRIES'] . "` SET " . $this->arrayToSQL($aSet) . " WHERE " . (!empty($aWhere) ? $this->arrayToSQL($aWhere, ' AND ') : "1")) > 0;
  73. }
  74. public function deleteAccount($aWhere)
  75. {
  76. if(empty($aWhere))
  77. return false;
  78. return $this->query("DELETE FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` WHERE " . $this->arrayToSQL($aWhere, ' AND ')) !== false;
  79. }
  80. public function hasAccount($iProfileId, $sMode)
  81. {
  82. return (int)$this->getOne("SELECT `id` FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` WHERE `profile_id` = :profile_id AND `" . $sMode . "_account_id` <> '' LIMIT 1", [
  83. 'profile_id' => $iProfileId,
  84. ]) > 0;
  85. }
  86. /*
  87. * Commissions methods
  88. */
  89. public function getCommissions($aParams = [])
  90. {
  91. $CNF = &$this->_oConfig->CNF;
  92. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  93. $sSelectClause = "`tc`.*";
  94. $sWhereClause = $sOrderClause = "";
  95. if(!empty($aParams['type']))
  96. switch($aParams['type']) {
  97. case 'max_order':
  98. $aMethod['name'] = 'getOne';
  99. $aMethod['params'][1] = [];
  100. $sSelectClause = "IFNULL(MAX(`tc`.`order`), 0)";
  101. break;
  102. case 'id':
  103. $aMethod['name'] = 'getRow';
  104. $aMethod['params'][1] = [
  105. 'id' => $aParams['id']
  106. ];
  107. $sWhereClause = " AND `tc`.`id`=:id";
  108. break;
  109. case 'acl_id':
  110. $aMethod['name'] = 'getRow';
  111. $aMethod['params'][1] = [
  112. 'acl_id' => $aParams['acl_id']
  113. ];
  114. $sWhereClause = " AND `tc`.`acl_id`=:acl_id";
  115. break;
  116. case 'all':
  117. if(!empty($aParams['active']))
  118. $sWhereClause = " AND `tc`.`active`='1'";
  119. break;
  120. }
  121. if(!empty($sOrderClause))
  122. $sOrderClause = " ORDER BY " . $sOrderClause;
  123. $aMethod['params'][0] = "SELECT " . $sSelectClause . "
  124. FROM `" . $CNF['TABLE_COMMISSIONS'] . "` AS `tc`
  125. WHERE 1" . $sWhereClause . $sOrderClause;
  126. return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
  127. }
  128. }
  129. /** @} */