table_common_member_magic.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_common_member_magic.php 27757 2012-02-14 03:08:15Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_member_magic extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_member_magic';
  15. $this->_pk = '';
  16. parent::__construct();
  17. }
  18. public function delete($uid = null, $magicid = null) {
  19. $para = array();
  20. if($uid) {
  21. $para[] = DB::field('uid', $uid);
  22. }
  23. if($magicid) {
  24. $para[] = DB::field('magicid', $magicid);
  25. }
  26. if(!($where = $para ? implode(' AND ', $para) : '')) {
  27. return null;
  28. }
  29. return DB::delete($this->_table, $where);
  30. }
  31. public function fetch_all($uid, $magicid = '', $start = 0, $limit = 0) {
  32. $para = array();
  33. if($uid) {
  34. $para[] = DB::field('uid', $uid);
  35. }
  36. if($magicid) {
  37. $para[] = DB::field('magicid', $magicid);
  38. }
  39. if($limit) {
  40. $sql = DB::limit($start, $limit);
  41. }
  42. if(!count($para)) {
  43. return null;
  44. }
  45. $para = implode(' AND ', $para);
  46. return DB::fetch_all('SELECT * FROM %t WHERE %i', array($this->_table, $para.$sql));
  47. }
  48. public function fetch($uid, $magicid) {
  49. $para = array();
  50. if($uid) {
  51. $para[] = DB::field('uid', $uid);
  52. }
  53. if($magicid) {
  54. $para[] = DB::field('magicid', $magicid);
  55. }
  56. if(!count($para)) {
  57. return null;
  58. }
  59. $sql = implode(' AND ', $para);
  60. return DB::fetch_first('SELECT * FROM %t WHERE %i', array($this->_table, $sql));
  61. }
  62. public function count($uid, $magicid) {
  63. $para = array();
  64. if($uid) {
  65. $para[] = DB::field('uid', $uid);
  66. }
  67. if($magicid) {
  68. $para[] = DB::field('magicid', $magicid);
  69. }
  70. if(!count($para)) {
  71. return null;
  72. }
  73. $sql = implode(' AND ', $para);
  74. return (int) DB::result_first('SELECT count(*) FROM %t WHERE %i', array($this->_table, $sql));
  75. }
  76. public function increase($uid, $magicid, $setarr, $slient = false, $unbuffered = false) {
  77. $para = array();
  78. $setsql = array();
  79. $allowkey = array('num');
  80. foreach($setarr as $key => $value) {
  81. if(($value = intval($value)) && in_array($key, $allowkey)) {
  82. $setsql[] = "`$key`=`$key`+'$value'";
  83. }
  84. }
  85. if($uid) {
  86. $para[] = DB::field('uid', $uid);
  87. }
  88. if($magicid) {
  89. $para[] = DB::field('magicid', $magicid);
  90. }
  91. if(!count($para) || !count($setsql)) {
  92. return null;
  93. }
  94. $sql = implode(' AND ', $para);
  95. return DB::query('UPDATE %t SET %i WHERE %i', array($this->_table, implode(',', $setsql), $sql), $slient, $unbuffered);
  96. }
  97. public function count_by_uid($uid) {
  98. return DB::result_first('SELECT COUNT(*) FROM %t mm, %t m WHERE mm.uid=%d AND mm.magicid=m.magicid', array($this->_table, 'common_magic', $uid));
  99. }
  100. public function fetch_magicid_by_identifier($uid, $identifier) {
  101. return DB::result_first('SELECT m.magicid FROM %t mm,%t m WHERE mm.uid=%d AND m.identifier=%s AND mm.magicid=m.magicid', array($this->_table, 'common_magic', $uid, $identifier));
  102. }
  103. }
  104. ?>