table_common_magiclog.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_magiclog.php 31034 2012-07-11 04:03:30Z zhangjie $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_magiclog extends discuz_table_archive
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_magiclog';
  15. $this->_pk = '';
  16. parent::__construct();
  17. }
  18. public function fetch_all_by_magicid_action($magicid, $action, $start = 0, $limit = 0) {
  19. $sql = array();
  20. if($magicid) {
  21. $magicid = dintval($magicid, true);
  22. $sql[] = DB::field('magicid', $magicid);
  23. }
  24. if($action) {
  25. $sql[] = DB::field('action', $action);
  26. }
  27. $wheresql = ($sql ? 'WHERE ' : '').implode(' AND ', $sql);
  28. return DB::fetch_all('SELECT * FROM %t %i ORDER BY dateline DESC '.DB::limit($start, $limit), array($this->_table, $wheresql));
  29. }
  30. public function fetch_all_by_magicid_action_uid($mid, $action, $uid, $start = 0, $limit = 0) {
  31. return DB::fetch_all('SELECT * FROM %t WHERE magicid=%d AND action=%d AND uid!=%d ORDER BY dateline DESC '.DB::limit($start, $limit), array($this->_table, $mid, $action, $uid));
  32. }
  33. public function fetch_all_by_uid_action($uid, $action, $start, $limit, $order = 'DESC') {
  34. return DB::fetch_all('SELECT * FROM %t WHERE uid=%d AND action=%d '.($order ? 'ORDER BY '.DB::order('dateline', $order) : '').' '.($limit ? DB::limit($start, $limit) : ''), array($this->_table, $uid, $action));
  35. }
  36. public function fetch_all_by_targetuid_action($uid, $action, $start, $limit, $order = 'DESC') {
  37. return DB::fetch_all('SELECT * FROM %t WHERE targetuid=%d AND action=%d '.($order ? 'ORDER BY '.DB::order('dateline', $order) : '').' '.($limit ? DB::limit($start, $limit) : ''), array($this->_table, $uid, $action));
  38. }
  39. public function count_by_targetuid_action($uid, $action) {
  40. return DB::result_first('SELECT COUNT(*) FROM %t WHERE targetuid=%d AND action=%d', array($this->_table, $uid, $action));
  41. }
  42. public function count_by_magicid_action($magicid, $action) {
  43. $sql = array();
  44. if($magicid) {
  45. $magicid = dintval($magicid, true);
  46. $sql[] = DB::field('magicid', $magicid);
  47. }
  48. if($action) {
  49. $sql[] = DB::field('action', $action);
  50. }
  51. $wheresql = ($sql ? 'WHERE ' : '').implode(' AND ', $sql);
  52. return DB::result_first('SELECT COUNT(*) FROM %t %i', array($this->_table, $wheresql));
  53. }
  54. public function count_by_action_uid_targetid_idtype_magicid($action, $uid, $targetid, $idtype, $magicid) {
  55. return DB::result_first('SELECT COUNT(*) FROM %t WHERE action=%d AND uid=%d AND targetid=%d AND idtype=%d AND magicid=%d', array($this->_table, $action, $uid, $targetid, $idtype, $magicid));
  56. }
  57. public function count_by_uid_magicid_action_dateline($uid, $magicid, $action, $dateline) {
  58. return DB::result_first('SELECT COUNT(*) FROM %t WHERE uid=%d AND magicid=%d AND action=%d AND dateline>%d', array($this->_table, $uid, $magicid, $action, $dateline));
  59. }
  60. public function count_by_uid_action($uid, $action) {
  61. return DB::result_first('SELECT COUNT(*) FROM %t WHERE uid=%d AND action=%d', array($this->_table, $uid, $action));
  62. }
  63. public function count_by_action_uid_dateline($action, $uid, $dateline, $maxdateline = 0) {
  64. $wherearr = array();
  65. $wherearr[] = 'action=%d';
  66. $wherearr[] = 'uid=%d';
  67. $wherearr[] = $maxdateline ? 'dateline BETWEEN %d AND %d' : 'dateline>%d';
  68. $parameter = array($this->_table, $action, $uid, $dateline);
  69. if($maxdateline) {
  70. $parameter[] = $maxdateline;
  71. }
  72. return DB::result_first('SELECT COUNT(*) FROM %t WHERE '.implode(' AND ', $wherearr), $parameter);
  73. }
  74. public function delete_by_magicid($ids) {
  75. $ids = dintval($ids, true);
  76. if($ids) {
  77. return DB::delete($this->_table, DB::field('magicid', $ids));
  78. }
  79. return 0;
  80. }
  81. }
  82. ?>