table_common_word.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_word.php 27877 2012-02-16 04:33:37Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_word extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_word';
  15. $this->_pk = 'id';
  16. parent::__construct();
  17. }
  18. public function fetch_by_find($find) {
  19. return DB::fetch_first("SELECT * FROM %t WHERE find=%s", array($this->_table, $find));
  20. }
  21. public function fetch_all_order_type_find() {
  22. return DB::fetch_all('SELECT * FROM %t ORDER BY type ASC, find ASC', array($this->_table), $this->_pk);
  23. }
  24. public function fetch_all() {
  25. return DB::fetch_all('SELECT * FROM %t', array($this->_table), $this->_pk);
  26. }
  27. public function fetch_all_by_type_find($type = null, $find = null , $start = 0, $limit = 0) {
  28. $parameter = array($this->_table);
  29. $wherearr = array();
  30. if($type !== null) {
  31. $parameter[] = $type;
  32. $wherearr[] = "`type`=%d";
  33. }
  34. if($find !== null) {
  35. $parameter[] = '%'.addslashes(stripsearchkey($find)).'%';
  36. $wherearr[] = "`find` LIKE %s";
  37. }
  38. $wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
  39. return DB::fetch_all("SELECT * FROM %t $wheresql ORDER BY find ASC".DB::limit($start, $limit), $parameter);
  40. }
  41. public function update_by_type($types, $data) {
  42. if(!empty($types) && !empty($data) && is_array($data)) {
  43. $types = array_map('intval', (array)$types);
  44. return DB::update($this->_table, $data, "type IN (".dimplode($types).")");
  45. }
  46. return 0;
  47. }
  48. public function update_by_find($find, $data) {
  49. if(!empty($find) && !empty($data) && is_array($data)) {
  50. return DB::update($this->_table, $data, DB::field('find', $find));
  51. }
  52. return 0;
  53. }
  54. public function count_by_type_find($type = null, $find = null) {
  55. $parameter = array($this->_table);
  56. $wherearr = array();
  57. if($type !== null) {
  58. $parameter[] = $type;
  59. $wherearr[] = "`type`=%d";
  60. }
  61. if($find !== null) {
  62. $parameter[] = '%'.addslashes(stripsearchkey($find)).'%';
  63. $wherearr[] = "`find` LIKE %s";
  64. }
  65. $wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';
  66. return DB::result_first("SELECT COUNT(*) FROM %t $wheresql", $parameter);
  67. }
  68. }
  69. ?>