table_forum_ratelog.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: table_forum_ratelog.php 32456 2013-01-21 05:18:56Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_forum_ratelog extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'forum_ratelog';
  15. $this->_pk = '';
  16. parent::__construct();
  17. }
  18. public function fetch_by_uid_pid($uid, $pid) {
  19. return DB::fetch_first('SELECT * FROM %t WHERE uid=%d AND pid=%d LIMIT 1', array($this->_table, $uid, $pid));
  20. }
  21. public function fetch_all_by_pid($pid, $sort = 'DESC') {
  22. if(is_array($pid)) {
  23. $pid = array_map('intval', (array)$pid);
  24. }
  25. $wheresql = is_array($pid) ? 'pid IN(%n)' : 'pid=%d';
  26. return DB::fetch_all("SELECT * FROM %t WHERE $wheresql ORDER BY dateline $sort", array($this->_table, $pid));
  27. }
  28. public function fetch_all_sum_score($uid, $dateline) {
  29. return DB::fetch_all('SELECT extcredits, SUM(ABS(score)) AS todayrate FROM %t WHERE uid=%d AND dateline>=%d GROUP BY extcredits', array($this->_table, $uid, $dateline));
  30. }
  31. public function count_by_uid_pid($uid, $pid) {
  32. return DB::result_first('SELECT COUNT(*) FROM %t WHERE uid=%d AND pid=%d LIMIT 1', array($this->_table, $uid, $pid));
  33. }
  34. public function delete_by_pid_uid_extcredits_dateline($pid = null, $uid = null, $extcredits = null, $dateline = null) {
  35. $parameter = array($this->_table);
  36. $wherearr = array();
  37. if($pid !== null) {
  38. $parameter[] = $pid;
  39. $wherearr[] = "pid=%d";
  40. }
  41. if($uid !== null) {
  42. $parameter[] = $uid;
  43. $wherearr[] = "uid=%d";
  44. }
  45. if($extcredits !== null) {
  46. $parameter[] = $extcredits;
  47. $wherearr[] = "extcredits=%d";
  48. }
  49. if($dateline !== null) {
  50. $parameter[] = $dateline;
  51. $wherearr[] = "dateline=%d";
  52. }
  53. if(!empty($wherearr)) {
  54. $wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
  55. return DB::query("DELETE FROM %t $wheresql", $parameter, true, true);
  56. }
  57. return false;
  58. }
  59. public function fetch_postrate_by_pid($pids, $postlist, $postcache, $ratelogrecord) {
  60. $pids = array_map('intval', (array)$pids);
  61. $query = DB::query("SELECT * FROM ".DB::table('forum_ratelog')." WHERE pid IN (".dimplode($pids).") ORDER BY dateline DESC");
  62. $ratelogs = array();
  63. while($ratelog = DB::fetch($query)) {
  64. if(count($postlist[$ratelog['pid']]['ratelog']) < $ratelogrecord) {
  65. $ratelogs[$ratelog['pid']][$ratelog['uid']]['username'] = $ratelog['username'];
  66. $ratelogs[$ratelog['pid']][$ratelog['uid']]['score'][$ratelog['extcredits']] += $ratelog['score'];
  67. empty($ratelogs[$ratelog['pid']][$ratelog['uid']]['reason']) && $ratelogs[$ratelog['pid']][$ratelog['uid']]['reason'] = dhtmlspecialchars($ratelog['reason']);
  68. $postlist[$ratelog['pid']]['ratelog'][$ratelog['uid']] = $ratelogs[$ratelog['pid']][$ratelog['uid']];
  69. }
  70. $postcache[$ratelog['pid']]['rate']['ratelogs'] = $postlist[$ratelog['pid']]['ratelog'];
  71. $postcache[$ratelog['pid']]['rate']['extcredits'][$ratelog['extcredits']] = $postlist[$ratelog['pid']]['ratelogextcredits'][$ratelog['extcredits']] += $ratelog['score'];
  72. if(!$postlist[$ratelog['pid']]['totalrate'] || !in_array($ratelog['uid'], $postlist[$ratelog['pid']]['totalrate'])) {
  73. $postlist[$ratelog['pid']]['totalrate'][] = $ratelog['uid'];
  74. }
  75. $postcache[$ratelog['pid']]['rate']['totalrate'] = $postlist[$ratelog['pid']]['totalrate'];
  76. }
  77. return array($ratelogs, $postlist, $postcache);
  78. }
  79. }
  80. ?>