table_common_template_block.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_template_block.php 29445 2012-04-12 07:14:40Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_template_block extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_template_block';
  15. $this->_pk = '';
  16. parent::__construct();
  17. }
  18. public function delete_by_targettplname($tpl, $tpldirectory = NULL) {
  19. $add = $tpldirectory !== NULL ? ' AND '.DB::field('tpldirectory', $tpldirectory) : '';
  20. return $tpl ? DB::delete($this->_table, DB::field('targettplname', $tpl).$add) : false;
  21. }
  22. public function fetch_targettplname_by_bid($bid) {
  23. return ($bid = dintval($bid)) ? DB::result_first('SELECT targettplname FROM %t WHERE bid=%d', array($this->_table, $bid)) : '';
  24. }
  25. public function fetch_all_bid_by_targettplname_notinherited($tpl, $notinherited) {
  26. $bids = array();
  27. if($tpl) {
  28. $query = DB::query('SELECT tb.bid FROM %t tb LEFT JOIN %t b ON b.bid=tb.bid WHERE '.DB::field('targettplname', $tpl).' AND b.notinherited=%d', array($this->_table, 'common_block', $notinherited));
  29. while($value = DB::fetch($query)) {
  30. $bids[$value['bid']] = $value['bid'];
  31. }
  32. }
  33. return $bids;
  34. }
  35. public function fetch_by_bid($bid) {
  36. return ($bid = dintval($bid)) ? DB::fetch_first('SELECT * FROM '.DB::table($this->_table).' WHERE '.DB::field('bid', $bid)) : array();
  37. }
  38. public function fetch_all_by_bid($bids) {
  39. return ($bids = dintval($bids, true)) ? DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' WHERE '.DB::field('bid', $bids), null, 'bid') : array();
  40. }
  41. public function fetch_all_by_targettplname($targettplname, $tpldirectory = NULL) {
  42. $add = ($tpldirectory !== NULL) ? ' AND '.DB::field('tpldirectory', $tpldirectory) : '';
  43. return DB::fetch_all('SELECT * FROM %t WHERE targettplname=%s'.$add, array($this->_table, $targettplname), 'bid');
  44. }
  45. public function insert_batch($targettplname, $tpldirectory, $bids) {
  46. if($targettplname && ($bids = dintval($bids, true))) {
  47. $values = array();
  48. foreach ($bids as $bid) {
  49. if($bid) {
  50. $values[] = "('$targettplname','$tpldirectory', '$bid')";
  51. }
  52. }
  53. DB::query("INSERT INTO ".DB::table($this->_table)." (targettplname, tpldirectory, bid) VALUES ".implode(',', $values));
  54. }
  55. }
  56. }
  57. ?>