table_common_mytask.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_mytask.php 27777 2012-02-14 07:07:26Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_mytask extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_mytask';
  15. $this->_pk = '';
  16. parent::__construct();
  17. }
  18. public function delete($uid, $taskid) {
  19. $condition = array();
  20. if($uid) {
  21. $condition[] = DB::field('uid', $uid);
  22. }
  23. if($taskid) {
  24. $condition[] = DB::field('taskid', $taskid);
  25. }
  26. DB::delete($this->_table, implode(' AND ', $condition));
  27. }
  28. public function update($uid, $taskid, $data) {
  29. if(!$data || !is_array($data)) {
  30. return;
  31. }
  32. $condition = array();
  33. if($uid) {
  34. $condition[] = DB::field('uid', $uid);
  35. }
  36. if($taskid) {
  37. $condition[] = DB::field('taskid', $taskid);
  38. }
  39. DB::update($this->_table, $data, implode(' AND ', $condition));
  40. }
  41. public function count($uid, $taskid = false, $status = false) {
  42. $taskid = $taskid !== false ? 'AND taskid='.intval($taskid) : '';
  43. $status = $status !== false ? 'AND status='.intval($status) : '';
  44. return DB::result_first("SELECT COUNT(*) FROM %t WHERE uid=%d %i %i", array($this->_table, $uid, $taskid, $status));
  45. }
  46. public function delete_exceed($exceedtime) {
  47. DB::query("DELETE FROM %t WHERE status='-1' AND dateline<%d", array($this->_table, TIMESTAMP - intval($exceedtime)), false, true);
  48. }
  49. public function fetch_all_by_taskid($taskid, $limit) {
  50. return DB::fetch_all("SELECT * FROM %t WHERE taskid=%d ORDER BY dateline DESC LIMIT 0, %d", array($this->_table, $taskid, $limit));
  51. }
  52. public function fetch($uid, $taskid) {
  53. return DB::fetch_first("SELECT * FROM %t WHERE uid=%d AND taskid=%d", array($this->_table, $uid, $taskid));
  54. }
  55. }
  56. ?>