table_mobile_wechat_resource.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_mobile_wechat_resource.php 34748 2014-07-28 08:09:07Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_mobile_wechat_resource extends discuz_table {
  12. public function __construct() {
  13. $this->_table = 'mobile_wechat_resource';
  14. $this->_pk = 'id';
  15. parent::__construct();
  16. }
  17. public function insert($data, $return_insert_id = false, $replace = false, $silent = false) {
  18. if(!is_array($data['data'])) {
  19. return;
  20. }
  21. if(!$data['dateline']) {
  22. $data['dateline'] = TIMESTAMP;
  23. }
  24. $data['data'] = serialize($data['data']);
  25. return parent::insert($data, $return_insert_id, $replace, $silent);
  26. }
  27. public function update($val, $data, $unbuffered = false, $low_priority = false) {
  28. if(isset($data['data']) && is_array($data['data'])) {
  29. $data['data'] = serialize($data['data']);
  30. }
  31. return parent::update($val, $data, $unbuffered , $low_priority);
  32. }
  33. public function fetch($id, $force_from_db = false){
  34. $data = parent::fetch($id, $force_from_db);
  35. if($data) {
  36. $data['data'] = unserialize($data['data']);
  37. return $data;
  38. } else {
  39. return array();
  40. }
  41. }
  42. public function count_by_type($type = null) {
  43. $typesql = $type !== null ? "`type`=".intval($type) : 'TRUE';
  44. return DB::result_first("SELECT COUNT(*) FROM %t WHERE %i", array($this->_table, $typesql));
  45. }
  46. public function fetch_by_type($type = null, $start = 0, $limit = 20) {
  47. $typesql = $type !== null ? "`type`=".intval($type) : 'TRUE';
  48. $datas = DB::fetch_all("SELECT * FROM %t WHERE %i ORDER BY id DESC LIMIT %d,%d", array($this->_table, $typesql, $start, $limit));
  49. if($datas) {
  50. foreach($datas as &$data) {
  51. $data['data'] = unserialize($data['data']);
  52. }
  53. return $datas;
  54. } else {
  55. return array();
  56. }
  57. }
  58. public function fetch_all($ids, $force_from_db = false) {
  59. $datas = parent::fetch_all($ids, $force_from_db);
  60. if($datas) {
  61. foreach($datas as &$data) {
  62. $data['data'] = unserialize($data['data']);
  63. }
  64. return $datas;
  65. } else {
  66. return array();
  67. }
  68. }
  69. }