table_forum_access.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_access.php 27777 2012-02-14 07:07:26Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_forum_access extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'forum_access';
  15. $this->_pk = '';
  16. parent::__construct();
  17. }
  18. public function fetch_all_by_fid_uid($fid = 0, $uid = 0, $count = 0, $start = 0, $limit = 0) {
  19. $uid = intval($uid);
  20. $sql = $uid ? ' uid='.$uid : '';
  21. $sql .= $fid ? ($sql ? ' AND ' : '').DB::field('fid', $fid) : '';
  22. if(empty($sql)) {
  23. return false;
  24. }
  25. if($count) {
  26. return DB::result_first('SELECT count(*) FROM %t WHERE '.$sql, array($this->_table));
  27. }
  28. if($limit) {
  29. $sql .= " LIMIT $start, $limit";
  30. }
  31. return DB::fetch_all('SELECT * FROM %t WHERE '.$sql, array($this->_table));
  32. }
  33. public function fetch_all_by_uid($uid) {
  34. $data = array();
  35. if($uid) {
  36. $data = DB::fetch_all('SELECT * FROM %t WHERE uid=%d', array($this->_table, $uid), 'fid');
  37. }
  38. return $data;
  39. }
  40. public function count_by_uid($uid) {
  41. return $uid ? DB::result_first('SELECT count(*) FROM %t WHERE uid=%d', array($this->_table, $uid)) : 0;
  42. }
  43. public function delete_by_fid($fid, $uid = 0) {
  44. $uid = intval($uid);
  45. $uidsql = $uid ? ' uid='.$uid.' AND ' : '';
  46. DB::query("DELETE FROM %t WHERE $uidsql fid=%d", array($this->_table, $fid));
  47. }
  48. public function update_for_uid($uid, $fid, $data) {
  49. if(empty($uid) || empty($fid) || empty($data) || !is_array($data)) {
  50. return false;
  51. }
  52. DB::update($this->_table, $data, DB::field('uid', $uid).' AND '.DB::field('fid', $fid));
  53. }
  54. public function delete_by_uid($uid) {
  55. return $uid ? DB::delete($this->_table, DB::field('uid', $uid)) : false;
  56. }
  57. }
  58. ?>