table_forum_activity.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_activity.php 30378 2012-05-24 09:52:46Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_forum_activity extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'forum_activity';
  15. $this->_pk = 'tid';
  16. parent::__construct();
  17. }
  18. public function fetch_all_for_search($view, $order, $searchkey, $type, $frienduid, $spaceuid, $minhot, $count = 0, $start = 0, $limit = 0) {
  19. $today = strtotime(dgmdate(TIMESTAMP, 'Y-m-d'));
  20. $wheresql = '1';
  21. $threadsql = $ordersql = $apply_sql = '';
  22. if($view == 'all') {
  23. if($order == 'hot') {
  24. $threadsql .= " t.special='4' AND t.replies>='$minhot'";
  25. $apply_sql = "INNER JOIN ".DB::table('forum_thread')." t ON t.special='4' AND t.tid = a.tid AND t.replies>='$minhot' AND t.displayorder>'-1'";
  26. }
  27. } elseif($view == 'me') {
  28. $type = in_array($type, array('orig', 'apply')) ? $type : 'orig';
  29. if($type == 'apply') {
  30. $wheresql = "1";
  31. $apply_sql = "INNER JOIN ".DB::table('forum_activityapply')." apply ON apply.uid = '$spaceuid' AND apply.tid = a.tid";
  32. } else {
  33. $wheresql = "a.uid = '$spaceuid'";
  34. }
  35. $ordersql = 'DESC';
  36. } else {
  37. if($frienduid) {
  38. $wheresql = "a.".DB::field('uid', $frienduid);
  39. }
  40. $ordersql = 'DESC';
  41. }
  42. if($view != 'all') {
  43. } elseif(empty($order)) {
  44. $ordersql = 'DESC';
  45. }
  46. if($searchkey) {
  47. $threadsql .= " AND t.subject LIKE ".DB::quote('%'.addslashes($searchkey).'%');
  48. }
  49. if($count) {
  50. return DB::result(DB::query("SELECT COUNT(*) FROM ".DB::table('forum_activity')." a $apply_sql WHERE $wheresql"),0);
  51. }
  52. if($view == 'all' && $order == 'hot') {
  53. $apply_sql = '';
  54. }
  55. $threadsql = empty($threadsql) ? '' : $threadsql.' AND ';
  56. return DB::fetch_all("SELECT a.*, t.* FROM ".DB::table('forum_activity')." a $apply_sql
  57. INNER JOIN ".DB::table('forum_thread')." t ON $threadsql t.tid=a.tid
  58. WHERE t.displayorder>'-1' AND $wheresql
  59. ORDER BY a.starttimefrom $ordersql ".DB::limit($start, $limit));
  60. }
  61. public function delete_by_tid($tids) {
  62. return DB::delete($this->_table, DB::field('tid', $tids));
  63. }
  64. }
  65. ?>