BxInvDb.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Invites Invites
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. class BxInvDb extends BxDolModuleDb
  12. {
  13. protected $_oConfig;
  14. protected $_sTableInvites;
  15. protected $_sTableRequests;
  16. /*
  17. * Constructor.
  18. */
  19. function __construct(&$oConfig)
  20. {
  21. parent::__construct($oConfig);
  22. $this->_oConfig = $oConfig;
  23. $this->_sTableInvites = $this->_sPrefix . 'invites';
  24. $this->_sTableRequests = $this->_sPrefix . 'requests';
  25. }
  26. public function getInvites($aParams, $bReturnCount = false)
  27. {
  28. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  29. $sSelectClause = $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = "";
  30. $sSelectClause = "`{$this->_sTableInvites}`.*";
  31. switch($aParams['type']) {
  32. case 'count_by_account':
  33. $aMethod['name'] = 'getOne';
  34. $aMethod['params'][1] = array(
  35. 'account_id' => $aParams['value']
  36. );
  37. $sSelectClause = "COUNT(`{$this->_sTableInvites}`.`id`) AS `count`";
  38. $sWhereClause = "AND `{$this->_sTableInvites}`.`account_id`=:account_id ";
  39. $sLimitClause = "LIMIT 1";
  40. break;
  41. }
  42. $sSql = "SELECT {select} FROM `{$this->_sTableInvites}` " . $sJoinClause . " WHERE 1 " . $sWhereClause . " {order} {limit}";
  43. $aMethod['params'][0] = str_replace(array('{select}', '{order}', '{limit}'), array($sSelectClause, $sOrderClause, $sLimitClause), $sSql);
  44. $aEntries = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  45. if(!$bReturnCount)
  46. return $aEntries;
  47. $aMethod['name'] = 'getOne';
  48. $aMethod['params'][0] = str_replace(array('{select}', '{order}', '{limit}'), array("COUNT(*)", "", ""), $sSql);
  49. return array($aEntries, (int)call_user_func_array(array($this, $aMethod['name']), $aMethod['params']));
  50. }
  51. public function deleteInvites($aParams)
  52. {
  53. $sSql = "DELETE FROM `{$this->_sTableInvites}` WHERE " . $this->arrayToSQL($aParams, " AND ");
  54. return $this->query($sSql);
  55. }
  56. public function getRequests($aParams, $bReturnCount = false)
  57. {
  58. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  59. $sSelectClause = $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = "";
  60. $sSelectClause = "`{$this->_sTableRequests}`.*";
  61. switch($aParams['type']) {
  62. case 'by_id':
  63. $aMethod['name'] = 'getRow';
  64. $aMethod['params'][1] = array(
  65. 'id' => $aParams['value']
  66. );
  67. $sWhereClause = "AND `{$this->_sTableRequests}`.`id`=:id ";
  68. $sLimitClause = "LIMIT 1";
  69. break;
  70. case 'count_all':
  71. $aMethod['name'] = 'getOne';
  72. $sSelectClause = "COUNT(`{$this->_sTableRequests}`.`id`) AS `count`";
  73. $sLimitClause = "LIMIT 1";
  74. break;
  75. }
  76. $sSql = "SELECT {select} FROM `{$this->_sTableRequests}` " . $sJoinClause . " WHERE 1 " . $sWhereClause . " {order} {limit}";
  77. $aMethod['params'][0] = str_replace(array('{select}', '{order}', '{limit}'), array($sSelectClause, $sOrderClause, $sLimitClause), $sSql);
  78. $aEntries = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  79. if(!$bReturnCount)
  80. return $aEntries;
  81. $aMethod['name'] = 'getOne';
  82. $aMethod['params'][0] = str_replace(array('{select}', '{order}', '{limit}'), array("COUNT(*)", "", ""), $sSql);
  83. return array($aEntries, (int)call_user_func_array(array($this, $aMethod['name']), $aMethod['params']));
  84. }
  85. }
  86. /** @} */