table_common_member_count.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_common_member_count.php 31022 2012-07-10 03:16:07Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_member_count extends discuz_table_archive
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_member_count';
  15. $this->_pk = 'uid';
  16. $this->_pre_cache_key = 'common_member_count_';
  17. parent::__construct();
  18. }
  19. public function increase($uids, $creditarr) {
  20. $uids = dintval((array)$uids, true);
  21. $sql = array();
  22. $allowkey = array('extcredits1', 'extcredits2', 'extcredits3', 'extcredits4', 'extcredits5', 'extcredits6', 'extcredits7', 'extcredits8',
  23. 'friends', 'posts', 'threads', 'oltime', 'digestposts', 'doings', 'blogs', 'albums', 'sharings', 'attachsize', 'views',
  24. 'todayattachs', 'todayattachsize', 'follower', 'following', 'newfollower', 'feeds', 'blacklist');
  25. foreach($creditarr as $key => $value) {
  26. if(($value = intval($value)) && $value && in_array($key, $allowkey)) {
  27. $sql[] = "`$key`=`$key`+'$value'";
  28. }
  29. }
  30. if(!empty($sql)){
  31. DB::query("UPDATE ".DB::table($this->_table)." SET ".implode(',', $sql)." WHERE uid IN (".dimplode($uids).")", 'UNBUFFERED');
  32. $this->increase_cache($uids, $creditarr);
  33. }
  34. }
  35. public function clear_extcredits($uids, $extcredits) {
  36. $uids = dintval((array)$uids, true);
  37. $sql = $data = array();
  38. $allowkey = array('extcredits1', 'extcredits2', 'extcredits3', 'extcredits4', 'extcredits5', 'extcredits6', 'extcredits7', 'extcredits8');
  39. foreach($extcredits as $value) {
  40. if(in_array($value, $allowkey, true)) {
  41. $sql[] = "`$value`='0'";
  42. $data[$value] = 0;
  43. }
  44. }
  45. if(!empty($sql)) {
  46. DB::query("UPDATE ".DB::table($this->_table)." SET ".implode(',', $sql)." WHERE uid IN (".dimplode($uids).")", 'UNBUFFERED');
  47. $this->update_batch_cache($uids, $data);
  48. }
  49. }
  50. public function count_by_posts($num) {
  51. return DB::result_first('SELECT COUNT(*) FROM %t WHERE posts=%d', array($this->_table, $num));
  52. }
  53. public function range_by_field($start = 0, $limit = 0, $orderby = '', $sort = '') {
  54. $orderby = in_array($orderby, array(
  55. 'extcredits1', 'extcredits2', 'extcredits3', 'extcredits4', 'extcredits5', 'extcredits6', 'extcredits7', 'extcredits8',
  56. 'friends', 'posts', 'threads', 'oltime', 'digestposts', 'doings', 'blogs', 'albums', 'sharings', 'attachsize', 'views',
  57. 'todayattachs', 'todayattachsize', 'follower', 'following', 'newfollower', 'feeds', 'blacklist'), true) ? $orderby : '';
  58. return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).($orderby ? ' ORDER BY '.DB::order($orderby, $sort) : '').DB::limit($start, $limit), null, $this->_pk);
  59. }
  60. public function clear_digestposts() {
  61. $uids = array();
  62. if($this->_allowmem) {
  63. $uids = DB::fetch_all('SELECT uid FROM '.DB::table($this->_table).' WHERE digestposts<>0', null, $this->_pk);
  64. }
  65. $data = DB::query("UPDATE ".DB::table($this->_table)." SET digestposts=0", 'UNBUFFERED');
  66. if(!empty($uids)) {
  67. $this->update_batch_cache(array_keys($uids), array('digestposts' => 0));
  68. }
  69. return $data;
  70. }
  71. public function clear_today_data() {
  72. $uids = array();
  73. if($this->_allowmem) {
  74. $uids = DB::fetch_all('SELECT uid FROM '.DB::table($this->_table).' WHERE todayattachs<>0 OR todayattachsize<>0', null, $this->_pk);
  75. }
  76. $data = DB::query("UPDATE ".DB::table($this->_table)." SET todayattachs='0',todayattachsize='0'", 'UNBUFFERED');
  77. if(!empty($uids)) {
  78. $this->update_batch_cache(array_keys($uids), array('todayattachs' => 0, 'todayattachsize' => 0));
  79. }
  80. return $data;
  81. }
  82. public function count_by_extcredits($extcredits, $credits) {
  83. $count = 0;
  84. if(in_array($extcredits, array(1,2,3,4,5,6,7,8))) {
  85. $count = DB::result_first('SELECT COUNT(*) FROM %t WHERE extcredits'.$extcredits.'>%d', array($this->_table, $credits));
  86. }
  87. return $count;
  88. }
  89. public function count_by_friends($friends) {
  90. return DB::result_first('SELECT COUNT(*) FROM %t WHERE friends>%d', array($this->_table, $friends));
  91. }
  92. }
  93. ?>