table_baidusubmit_setting.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. if(!defined('IN_DISCUZ')) {
  3. exit('Access Denied');
  4. }
  5. class table_baidusubmit_setting extends discuz_table
  6. {
  7. public function __construct()
  8. {
  9. $this->_table = 'baidusubmit_setting';
  10. parent::__construct();
  11. }
  12. public function fetch_all()
  13. {
  14. $query = DB::query('SELECT * FROM %t', array($this->_table));
  15. $ret = array();
  16. while ($row = DB::fetch($query)) {
  17. $ret[$row['skey']] = array('svalue' => $row['svalue'], 'stime' => $row['stime']);
  18. }
  19. return $ret;
  20. }
  21. public function key_exists($skey)
  22. {
  23. return DB::fetch_first('SELECT skey FROM %t WHERE skey=%s LIMIT 1', array($this->_table, $skey)) ? true : false;
  24. }
  25. public function update($skey, $svalue, $update_time=true, $is_increase=false)
  26. {
  27. $time = time();
  28. if ($this->key_exists($skey)) {
  29. $subsql = !$is_increase ? 'svalue=%s' : 'svalue=svalue+%d';
  30. if ($update_time) {
  31. return DB::query("UPDATE %t SET $subsql, stime=%d WHERE skey=%s", array($this->_table, $svalue, $time, $skey));
  32. } else {
  33. return DB::query("UPDATE %t SET $subsql WHERE skey=%s", array($this->_table, $svalue, $skey));
  34. }
  35. } else {
  36. return DB::query('INSERT INTO %t(skey, svalue, stime) values(%s, %s, %d)', array($this->_table, $skey, $svalue, $time));
  37. }
  38. }
  39. public function remove_key($skey)
  40. {
  41. return DB::query('DELETE FROM %t WHERE skey=%s', array($this->_table, $skey));
  42. }
  43. }