table_forum_polloption.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_polloption.php 31445 2012-08-28 08:56:51Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_forum_polloption extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'forum_polloption';
  15. $this->_pk = 'polloptionid';
  16. parent::__construct();
  17. }
  18. public function update_vote($polloptionids, $voterids, $num = 1) {
  19. DB::query('UPDATE %t SET votes=votes+\'%d\', voterids=CONCAT(voterids,%s) WHERE polloptionid IN (%n)', array($this->_table, $num, $voterids, $polloptionids), false, true);
  20. }
  21. public function fetch_all_by_tid($tids, $displayorder = 0, $limit = 0) {
  22. $sqladd = '';
  23. if($displayorder) {
  24. $sqladd = ' ORDER BY displayorder';
  25. }
  26. if($limit) {
  27. $sqladd .= ' LIMIT '.intval($limit);
  28. }
  29. return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('tid', $tids).$sqladd, array($this->_table));
  30. }
  31. public function delete_safe_tid($tid, $polloptionid = 0) {
  32. $sqladd = '';
  33. if($polloptionid) {
  34. $sqladd = DB::field('polloptionid', intval($polloptionid)).' AND ';
  35. }
  36. DB::query("DELETE FROM %t WHERE $sqladd tid=%d", array($this->_table, $tid));
  37. }
  38. public function delete_by_tid($tids) {
  39. return DB::delete($this->_table, DB::field('tid', $tids));
  40. }
  41. public function update_safe_tid($polloptionid, $tid, $displayorder, $polloption = '') {
  42. $param = array($this->_table, $displayorder);
  43. if($polloption) {
  44. $sqladd = ', polloption=%s';
  45. $param[] = $polloption;
  46. }
  47. $param[] = $polloptionid;
  48. $param[] = $tid;
  49. DB::query('UPDATE %t SET displayorder=%d'.$sqladd.' WHERE polloptionid=%d AND tid=%d', $param);
  50. }
  51. public function fetch_count_by_tid($tid) {
  52. return DB::fetch_first('SELECT MAX(votes) AS max, SUM(votes) AS total FROM %t WHERE tid=%d', array($this->_table, $tid));
  53. }
  54. }
  55. ?>