BxForumDb.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 Forum Forum
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Module database queries
  13. */
  14. class BxForumDb extends BxBaseModTextDb
  15. {
  16. public function __construct(&$oConfig)
  17. {
  18. parent::__construct($oConfig);
  19. }
  20. public function updateEntries($aSet, $aWhere)
  21. {
  22. $sQuery = "UPDATE `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` SET " . $this->arrayToSQL($aSet) . " WHERE " . (!empty($aWhere) ? $this->arrayToSQL($aWhere, ' AND ') : "1");
  23. return (int)$this->query($sQuery) > 0;
  24. }
  25. public function updateLastCommentTimeProfile($iConversationId, $iProfileId, $iCommentId, $iTimestamp)
  26. {
  27. $sQuery = $this->prepare("UPDATE `" . $this->getPrefix() . "discussions` SET `lr_profile_id` = ?, `lr_timestamp` = ?, `lr_comment_id` = ? WHERE `id` = ?", $iProfileId, $iTimestamp, $iCommentId, $iConversationId);
  28. return $this->query($sQuery);
  29. }
  30. public function getComments($aParams)
  31. {
  32. $CNF = &$this->_oConfig->CNF;
  33. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  34. $sFieldsClause = "`te`.*";
  35. $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = "";
  36. switch($aParams['type']) {
  37. case 'entries_author_search':
  38. $aMethod['name'] = 'getColumn';
  39. $sFieldsClause = "`te`.`cmt_object_id`";
  40. $sWhereClause = " AND `te`.`cmt_author_id` IN (" . $this->implode_escape($aParams['author']) . ")";
  41. $sGroupClause = "`te`.`cmt_object_id`";
  42. break;
  43. case 'entries_keyword_search':
  44. $aMethod['name'] = 'getColumn';
  45. $sFieldsClause = "`te`.`cmt_object_id`";
  46. $sWhereClause = " AND `te`.`cmt_text` LIKE " . $this->escape("%" . $aParams['keyword'] . "%");
  47. $sGroupClause = "`te`.`cmt_object_id`";
  48. break;
  49. case 'author_comments':
  50. $aMethod['name'] = 'getPairs';
  51. $sFieldsClause = "`te`.`cmt_author_id`, COUNT(`te`.`cmt_id`) AS `cmt_count`";
  52. $sWhereClause = $this->prepareAsString(" AND `te`.`cmt_object_id`=? ", $aParams['object_id']);
  53. $sGroupClause = "`te`.`cmt_author_id`";
  54. $aMethod['params'][1] = "cmt_author_id";
  55. $aMethod['params'][2] = "cmt_count";
  56. break;
  57. }
  58. $sGroupClause = $sGroupClause ? "GROUP BY " . $sGroupClause : "";
  59. $sOrderClause = $sOrderClause ? "ORDER BY " . $sOrderClause : "";
  60. $aMethod['params'][0] = "SELECT
  61. " . $sFieldsClause . "
  62. FROM `" . $this->getPrefix() . "cmts` AS `te`" . $sJoinClause . "
  63. WHERE 1" . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause;
  64. return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  65. }
  66. public function getUnrepliedDiscussionsNum ($iProfileId)
  67. {
  68. $CNF = &$this->_oConfig->CNF;
  69. $sQuery = $this->prepare("SELECT COUNT(`te`.`id`)
  70. FROM `" . $CNF['TABLE_ENTRIES'] . "` AS `te`
  71. WHERE `te`.`author`=? AND `te`.`lr_profile_id`<>?", $iProfileId, $iProfileId);
  72. return $this->getOne($sQuery);
  73. }
  74. public function updateStatus($sAction, $aContentInfo)
  75. {
  76. $CNF = &$this->_oConfig->CNF;
  77. $aActions = array(
  78. 'stick' => array($CNF['FIELD_STICK'] => 1),
  79. 'unstick' => array($CNF['FIELD_STICK'] => 0),
  80. 'lock' => array($CNF['FIELD_LOCK'] => 1),
  81. 'unlock' => array($CNF['FIELD_LOCK'] => 0),
  82. 'hide' => array($CNF['FIELD_STATUS_ADMIN'] => 'hidden'),
  83. 'unhide' => array($CNF['FIELD_STATUS_ADMIN'] => 'active')
  84. );
  85. return $this->updateEntries($aActions[$sAction], array($CNF['FIELD_ID'] => $aContentInfo[$CNF['FIELD_ID']]));
  86. }
  87. public function insertCategory($aSet)
  88. {
  89. $sQuery = "INSERT INTO `" . $this->getPrefix() . "categories` SET " . $this->arrayToSQL($aSet);
  90. return (int)$this->query($sQuery) > 0;
  91. }
  92. public function getCategories($aParams)
  93. {
  94. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  95. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  96. if(!isset($aParams['order']) || empty($aParams['order']))
  97. $sOrderClause = "ORDER BY `tc`.`category` ASC";
  98. switch($aParams['type']) {
  99. case 'by_category':
  100. $aMethod['name'] = 'getRow';
  101. $aMethod['params'][1] = array(
  102. 'category' => $aParams['category']
  103. );
  104. $sWhereClause = " AND `tc`.`category`=:category ";
  105. break;
  106. case 'all_pairs':
  107. $aMethod['name'] = 'getPairs';
  108. $aMethod['params'][1] = 'category';
  109. $aMethod['params'][2] = 'visible_for_levels';
  110. break;
  111. }
  112. $aMethod['params'][0] = "SELECT
  113. `tc`.*" . $sSelectClause . "
  114. FROM `" . $this->getPrefix() . "categories` AS `tc` " . $sJoinClause . "
  115. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  116. return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  117. }
  118. }
  119. /** @} */