table_forum_threadmod.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_threadmod.php 27913 2012-02-16 09:07:00Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_forum_threadmod extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'forum_threadmod';
  15. $this->_pk = '';
  16. parent::__construct();
  17. }
  18. public function fetch_by_tid($tid) {
  19. return DB::fetch_first('SELECT * FROM %t WHERE tid=%d ORDER BY dateline DESC LIMIT 1', array($this->_table, $tid));
  20. }
  21. public function fetch_by_tid_action_status($tid, $action, $status = 1) {
  22. return DB::fetch_first('SELECT * FROM %t WHERE tid=%d AND action=%s AND status=%d ORDER BY dateline DESC LIMIT 1', array($this->_table, $tid, $action, $status));
  23. }
  24. public function fetch_by_tid_magicid($tid, $magicid = 0) {
  25. return DB::fetch_first('SELECT * FROM %t WHERE tid=%d AND magicid=%d', array($this->_table, $tid, $magicid));
  26. }
  27. public function fetch_all_by_tid_magicid($tid, $magicid = 0) {
  28. return DB::fetch_all('SELECT * FROM %t WHERE tid=%d AND magicid=%d', array($this->_table, $tid, $magicid));
  29. }
  30. public function fetch_all_by_tid($tid, $action = '', $start = 0, $limit = 0) {
  31. $tid = dintval($tid, true);
  32. $parameter = array($this->_table, $tid);
  33. $wherearr = array();
  34. $wherearr[] = is_array($tid) && $tid ? 'tid IN(%n)' : 'tid=%d';
  35. if($action) {
  36. $parameter[] = $action;
  37. $wherearr[] = is_array($action) && $action ? 'action IN(%n)' : 'action=%s';
  38. }
  39. $wheresql = ' WHERE '.implode(' AND ', $wherearr);
  40. return DB::fetch_all("SELECT * FROM %t $wheresql ORDER BY dateline DESC ".DB::limit($start, $limit), $parameter);
  41. }
  42. public function fetch_all_by_expiration_status($expiration, $status=1) {
  43. return DB::fetch_all('SELECT * FROM %t WHERE expiration>0 AND expiration<%d AND status=%d', array($this->_table, $expiration, $status));
  44. }
  45. public function fetch_all_recyclebin_by_dateline($dateline, $start = 0, $limit = 0) {
  46. return DB::fetch_all("SELECT tm.tid FROM %t tm, %t t WHERE tm.action='DEL' AND tm.dateline<%d AND t.tid=tm.tid AND t.displayorder=-1".DB::limit($start, $limit), array($this->_table, 'forum_thread', $dateline));
  47. }
  48. public function count_by_tid_magicid($tid, $magicid) {
  49. return DB::result_first('SELECT COUNT(*) FROM %t WHERE tid=%d AND magicid=%d', array($this->_table, $tid, $magicid));
  50. }
  51. public function delete_by_dateline($dateline) {
  52. $dateline = dintval($dateline);
  53. return DB::delete($this->_table, DB::field('tid', 0, '>').' AND '.DB::field('dateline', $dateline, '<'));
  54. }
  55. public function update_by_tid_action($tids, $action, $data) {
  56. $tids = dintval($tids, true);
  57. if(!empty($data) && is_array($data) && $tids) {
  58. return DB::update($this->_table, $data, DB::field('tid', $tids).' AND '.DB::field('action', $action));
  59. }
  60. return 0;
  61. }
  62. public function delete_by_tid($tids) {
  63. $tids = dintval($tids, true);
  64. if($tids) {
  65. return DB::delete($this->_table, DB::field('tid', $tids));
  66. }
  67. return 0;
  68. }
  69. }
  70. ?>