table_forum_medallog.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_medallog.php 27751 2012-02-14 02:26:11Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_forum_medallog extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'forum_medallog';
  15. $this->_pk = 'id';
  16. parent::__construct();
  17. }
  18. public function count_by_type($type) {
  19. return DB::result_first("SELECT COUNT(*) FROM %t WHERE type=%d", array($this->_table, $type));
  20. }
  21. public function count_by_uid($uid) {
  22. return DB::result_first("SELECT COUNT(*) FROM %t WHERE uid=%d", array($this->_table, $uid));
  23. }
  24. public function fetch_all_by_type($type) {
  25. return DB::fetch_all("SELECT * FROM %t WHERE type=%d ORDER BY dateline", array($this->_table, $type), $this->_pk);
  26. }
  27. public function fetch_all_lastmedal($limit) {
  28. return DB::fetch_all("SELECT * FROM %t WHERE type<'2' ORDER BY dateline DESC LIMIT %d", array($this->_table, $limit), $this->_pk);
  29. }
  30. public function fetch_all_by_expiration($expiration) {
  31. return DB::fetch_all("SELECT * FROM %t WHERE status=1 AND expiration>0 AND expiration<%d", array($this->_table, $expiration));
  32. }
  33. public function fetch_all_by_uid($uid, $start, $limit) {
  34. return DB::fetch_all("SELECT * FROM %t WHERE uid=%d ORDER BY dateline DESC LIMIT %d,%d", array($this->_table, $uid, $start, $limit));
  35. }
  36. public function update_type_by_uid_medalid($type, $uid, $medalid) {
  37. $type = intval($type);
  38. if(!$uid || !$medalid) {
  39. return;
  40. }
  41. DB::update($this->_table, array('type' => $type), DB::field('uid', $uid).' AND '.DB::field('medalid', $medalid));
  42. }
  43. public function fetch_all_by_type_medalid($type, $medalid, $start_limit, $lpp) {
  44. $where = array();
  45. if($type !== '') {
  46. $where[] = DB::field('type', $type);
  47. }
  48. if($medalid !== '') {
  49. $where[] = DB::field('medalid', $medalid);
  50. }
  51. $where = $where ? 'WHERE '.implode(' AND ', $where) : '';
  52. $start_limit = intval($start_limit);
  53. $lpp = intval($lpp);
  54. return DB::fetch_all("SELECT * FROM ".DB::table('forum_medallog')." $where ORDER BY dateline DESC LIMIT $start_limit, $lpp");
  55. }
  56. public function count_by_type_medalid($type, $medalid) {
  57. $where = array();
  58. if($type !== '') {
  59. $where[] = DB::field('type', $type);
  60. }
  61. if($medalid !== '') {
  62. $where[] = DB::field('medalid', $medalid);
  63. }
  64. $where = $where ? 'WHERE '.implode(' AND ', $where) : '';
  65. return DB::result_first("SELECT COUNT(*) FROM ".DB::table('forum_medallog')." $where");
  66. }
  67. public function count_by_verify_medalid($uid, $medalid) {
  68. return DB::result_first("SELECT COUNT(*) FROM %t WHERE uid=%d AND medalid=%d AND type=2", array($this->_table, $uid, $medalid));
  69. }
  70. }
  71. ?>