table_common_task.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_task.php 27777 2012-02-14 07:07:26Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_task extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_task';
  15. $this->_pk = 'taskid';
  16. parent::__construct();
  17. }
  18. public function fetch_all_by_available($available) {
  19. return DB::fetch_all("SELECT * FROM %t WHERE available=%d", array($this->_table, $available), $this->_pk);
  20. }
  21. public function fetch_all_data() {
  22. return DB::fetch_all("SELECT * FROM %t ORDER BY displayorder, taskid DESC", array($this->_table));
  23. }
  24. public function count_by_scriptname($scriptname) {
  25. return DB::result_first("SELECT COUNT(*) FROM %t WHERE scriptname=%s", array($this->_table, $scriptname));
  26. }
  27. public function fetch_all_by_scriptname($scriptname) {
  28. return DB::fetch_all("SELECT * FROM %t WHERE scriptname=%s", array($this->_table, $scriptname));
  29. }
  30. public function update_by_scriptname($scriptname, $data) {
  31. if(!$data || !is_array($data)) {
  32. return;
  33. }
  34. DB::update($this->_table, $data, DB::field('scriptname', $scriptname));
  35. }
  36. public function update_applicants($taskid, $v) {
  37. DB::query("UPDATE %t SET applicants=applicants+%s WHERE taskid=%d", array($this->_table, $v, $taskid));
  38. }
  39. public function update_achievers($taskid, $v) {
  40. DB::query("UPDATE %t SET achievers=achievers+%s WHERE taskid=%d", array($this->_table, $v, $taskid));
  41. }
  42. public function update_available() {
  43. DB::query("UPDATE %t SET available='2' WHERE available='1' AND starttime>'0' AND starttime<=%d AND (endtime IS NULL OR endtime>%d)", array($this->_table, TIMESTAMP, TIMESTAMP), false, true);
  44. }
  45. public function fetch_all_by_status($uid, $status) {
  46. switch($status) {
  47. case 'doing':
  48. $status = "mt.status='0'";
  49. break;
  50. case 'done':
  51. $status = "mt.status='1'";
  52. break;
  53. case 'failed':
  54. $status = "mt.status='-1'";
  55. break;
  56. case 'canapply':
  57. case 'new':
  58. default:
  59. $status = "'".TIMESTAMP."' > starttime AND (mt.taskid IS NULL OR (ABS(mt.status)='1' AND t.period>0))";
  60. break;
  61. }
  62. return DB::fetch_all("SELECT t.*, mt.csc, mt.dateline FROM %t t
  63. LEFT JOIN %t mt ON mt.taskid=t.taskid AND mt.uid=%d
  64. WHERE %i AND t.available='2' ORDER BY t.displayorder, t.taskid DESC", array($this->_table, 'common_mytask', $uid, $status));
  65. }
  66. public function fetch_by_uid($uid, $taskid) {
  67. return DB::fetch_first("SELECT t.*, mt.dateline, mt.dateline AS applytime, mt.status, mt.csc FROM %t t LEFT JOIN %t mt ON mt.uid=%d AND mt.taskid=t.taskid
  68. WHERE t.taskid=%d AND t.available='2'", array($this->_table, 'common_mytask', $uid, $taskid));
  69. }
  70. }
  71. ?>