table_home_follow_feed.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_home_follow_feed.php 28364 2012-02-28 07:31:23Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_home_follow_feed extends discuz_table
  12. {
  13. private $_ids = array();
  14. private $_cids = array();
  15. private $_tids = array();
  16. private $_archiver_table = 'home_follow_feed_archiver';
  17. public function __construct() {
  18. $this->_table = 'home_follow_feed';
  19. $this->_pk = 'feedid';
  20. parent::__construct();
  21. }
  22. public function fetch_all_by_uid($uids = 0, $archiver = false, $start = 0, $limit = 0) {
  23. $data = array();
  24. $parameter = array($archiver ? $this->_archiver_table : $this->_table);
  25. $wherearr = array();
  26. if(!empty($uids)) {
  27. $uids = dintval($uids, true);
  28. $wherearr[] = is_array($uids) && $uids ? 'uid IN(%n)' : 'uid=%d';
  29. $parameter[] = $uids;
  30. }
  31. $wheresql = !empty($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
  32. $query = DB::query("SELECT * FROM %t $wheresql ORDER BY dateline DESC ".DB::limit($start, $limit), $parameter);
  33. while($row = DB::fetch($query)) {
  34. $data[$row['feedid']] = $row;
  35. $this->_tids[$row['tid']] = $row['tid'];
  36. }
  37. return $data;
  38. }
  39. public function fetch_all_by_dateline($dateline, $glue = '>=') {
  40. $glue = helper_util::check_glue($glue);
  41. return DB::fetch_all("SELECT * FROM %t WHERE dateline{$glue}%d ORDER BY dateline", array($this->_table, $dateline), $this->_pk);
  42. }
  43. public function fetch_by_feedid($feedid, $archiver = false) {
  44. return DB::fetch_first("SELECT * FROM %t WHERE feedid=%d", array($archiver ? $this->_archiver_table : $this->_table, $feedid));
  45. }
  46. public function count_by_uid_tid($uid, $tid, $archiver = false) {
  47. return DB::result_first('SELECT COUNT(*) FROM %t WHERE uid=%d AND tid=%d', array($archiver ? $this->_archiver_table : $this->_table, $uid, $tid));
  48. }
  49. public function count_by_uid_dateline($uids = array(), $dateline = 0, $archiver = 0) {
  50. $count = 0;
  51. $parameter = array($archiver ? $this->_archiver_table : $this->_table);
  52. $wherearr = array();
  53. if(!empty($uids)) {
  54. $uids = dintval($uids, true);
  55. $wherearr[] = is_array($uids) && $uids ? 'uid IN(%n)' : 'uid=%d';
  56. $parameter[] = $uids;
  57. }
  58. if($dateline) {
  59. $wherearr[] = "dateline>%d";
  60. $parameter[] = $dateline;
  61. }
  62. $wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
  63. $count = DB::result_first("SELECT COUNT(*) FROM %t $wheresql", $parameter);
  64. return $count;
  65. }
  66. public function insert_archiver($data) {
  67. if(!empty($data) && is_array($data)) {
  68. return DB::insert($this->_archiver_table, $data, false, true);
  69. }
  70. return 0;
  71. }
  72. public function delete_by_feedid($feedid, $archiver = false) {
  73. $feedid = dintval($feedid, true);
  74. if($feedid) {
  75. return DB::delete($archiver ? $this->_archiver_table : $this->_table, DB::field('feedid', $feedid));
  76. }
  77. return 0;
  78. }
  79. public function delete_by_uid($uids) {
  80. $uids = dintval($uids, true);
  81. $delnum = 0;
  82. if($uids) {
  83. $delnum = DB::delete($this->_table, DB::field('uid', $uids));
  84. $delnum += DB::delete($this->_archiver_table, DB::field('uid', $uids));
  85. }
  86. return $delnum;
  87. }
  88. public function get_ids() {
  89. return $this->_ids;
  90. }
  91. public function get_tids() {
  92. return $this->_tids;
  93. }
  94. public function get_cids() {
  95. return $this->_cids;
  96. }
  97. }
  98. ?>