table_common_block_style.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_block_style.php 31736 2012-09-26 02:23:48Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_block_style extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_block_style';
  15. $this->_pk = 'styleid';
  16. parent::__construct();
  17. }
  18. public function fetch_all_by_blockclass($blockclass) {
  19. return $blockclass ? DB::fetch_all('SELECT * FROM %t WHERE blockclass=%s', array($this->_table, $blockclass), $this->_pk) : array();
  20. }
  21. public function fetch_all_by_hash($hash) {
  22. return $hash ? DB::fetch_all('SELECT * FROM %t WHERE `hash` IN (%n)', array($this->_table, $hash), $this->_pk) : array();
  23. }
  24. public function count_by_where($wheresql) {
  25. $wheresql = $wheresql ? ' WHERE '.(string)$wheresql : '';
  26. return DB::result_first('SELECT COUNT(*) FROM '.DB::table($this->_table).$wheresql);
  27. }
  28. public function fetch_all_by_where($wheresql, $ordersql, $start, $limit) {
  29. $wheresql = $wheresql ? ' WHERE '.(string)$wheresql : '';
  30. return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).$wheresql.' '.(string)$ordersql.DB::limit($start, $limit), null, $this->_pk ? $this->_pk : '');
  31. }
  32. public function insert_batch($styles) {
  33. $inserts = array();
  34. foreach($styles as $value) {
  35. if(!empty($value['blockclass'])) {
  36. $value = daddslashes($value);
  37. $inserts[] = "('$value[blockclass]', '$value[name]', '$value[template]', '$value[hash]', '$value[getpic]', '$value[getsummary]', '$value[settarget]', '$value[fields]', '$value[moreurl]')";
  38. }
  39. }
  40. if(!empty($inserts)) {
  41. DB::query('INSERT INTO '.DB::table($this->_table)."(`blockclass`, `name`, `template`, `hash`, `getpic`, `getsummary`, `settarget`, `fields`, `moreurl`) VALUES ".implode(',',$inserts));
  42. }
  43. }
  44. public function update($val, $data, $unbuffered = false, $low_priority = false) {
  45. if(($val = dintval($val, true)) && $data && is_array($data)) {
  46. $this->_pre_cache_key = 'blockstylecache_';
  47. $this->_cache_ttl = getglobal('setting/memory/diyblock');
  48. $this->_allowmem = getglobal('setting/memory/diyblock') && memory('check');
  49. $this->clear_cache($val);
  50. return parent::update($val, $data, $unbuffered, $low_priority);
  51. }
  52. return false;
  53. }
  54. public function delete($val, $unbuffered = false) {
  55. if(($val = dintval($val, true))) {
  56. $this->_pre_cache_key = 'blockstylecache_';
  57. $this->_cache_ttl = getglobal('setting/memory/diyblock');
  58. $this->_allowmem = getglobal('setting/memory/diyblock') && memory('check');
  59. return parent::delete($val, $unbuffered);
  60. }
  61. return false;
  62. }
  63. }
  64. ?>