table_forum_announcement.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_announcement.php 27829 2012-02-15 07:34:43Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_forum_announcement extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'forum_announcement';
  15. $this->_pk = 'id';
  16. parent::__construct();
  17. }
  18. public function fetch_all_by_date($timestamp, $type = 2) {
  19. return DB::fetch_all('SELECT * FROM %t WHERE type!=%d AND starttime<=%d AND (endtime=0 OR endtime>%d) ORDER BY displayorder, starttime DESC, id DESC', array($this->_table, $type, $timestamp, $timestamp), $this->_pk);
  20. }
  21. public function fetch_all_by_displayorder() {
  22. return DB::fetch_all('SELECT * FROM %t ORDER BY displayorder, starttime DESC, id DESC', array($this->_table), $this->_pk);
  23. }
  24. public function fetch_by_displayorder($timestamp) {
  25. return DB::fetch_first('SELECT * FROM %t WHERE type!=2 AND groups = \'\' AND starttime<=%d AND (endtime>=%d OR endtime=0) ORDER BY displayorder, starttime DESC, id DESC LIMIT 1', array($this->_table, $timestamp, $timestamp));
  26. }
  27. public function fetch_all_by_time($time, $type, $bannedids, $startrow, $items) {
  28. $type = dintval($type, true);
  29. $sql = ' AND '.DB::field('type', $type);
  30. if($bannedids) {
  31. $bannedids = dintval($bannedids, true);
  32. $sql .= ' AND '.DB::field('id', $bannedids, 'notin');
  33. }
  34. return DB::fetch_all('SELECT * FROM %t WHERE starttime <= %d AND (endtime = \'\' || endtime >= %d) %i ORDER BY displayorder DESC LIMIT %d, %d', array($this->_table, $time, $time, $sql, $startrow, $items), $this->_pk);
  35. }
  36. public function fetch_by_id_username($id, $username, $adminid = 1) {
  37. return DB::fetch_first('SELECT * FROM %t WHERE id=%d AND (%d=1 AND author=%s)', array($this->_table, $id, $adminid, $username));
  38. }
  39. public function delete_by_id_username($ids, $username, $adminid = 1) {
  40. if(($ids = dintval((array)$ids, true))) {
  41. DB::query('DELETE FROM %t WHERE id IN(%n) AND (%d=1 OR author=%s)', array($this->_table, $ids, $adminid, $username), false, true);
  42. }
  43. }
  44. public function update_displayorder_by_id_username($id, $displayorder, $username, $adminid = 1) {
  45. if(($id = dintval((array)$id, true))) {
  46. DB::query('UPDATE %t SET displayorder=%d WHERE id IN(%n) AND (%d=1 OR author=%s)', array($this->_table, $displayorder, $id, $adminid, $username), false, true);
  47. }
  48. }
  49. public function update_by_id_username($id, $data, $username, $adminid = 1) {
  50. if(($id = dintval($id, true)) && $data && is_array($data)) {
  51. $adminid = dintval($adminid);
  52. DB::update($this->_table, $data, DB::field($this->_pk, $id)." AND ('{$adminid}'=1 OR ".DB::field('author', $username).')', true);
  53. }
  54. }
  55. public function delete_all_by_endtime($timestamp) {
  56. DB::query("DELETE FROM %t WHERE endtime<%d AND endtime<>'0'", array($this->_table, $timestamp));
  57. }
  58. }
  59. ?>