table_common_nav.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_nav.php 36278 2016-12-09 07:52:35Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_nav extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_nav';
  15. $this->_pk = 'id';
  16. parent::__construct();
  17. }
  18. public function fetch_by_id_navtype($id, $navtype) {
  19. return DB::fetch_first('SELECT * FROM %t WHERE id=%d AND navtype=%d', array($this->_table, $id, $navtype));
  20. }
  21. public function fetch_by_type_identifier($type, $identifier) {
  22. return DB::fetch_first('SELECT * FROM %t WHERE type=%d AND identifier=%s', array($this->_table, $type, $identifier));
  23. }
  24. public function fetch_all_by_navtype($navtype = null) {
  25. $parameter = array($this->_table);
  26. $wheresql = '';
  27. if($navtype !== null) {
  28. $parameter[] = $navtype;
  29. $wheresql = ' WHERE navtype=%d';
  30. }
  31. return DB::fetch_all('SELECT * FROM %t '.$wheresql.' ORDER BY available DESC, displayorder', $parameter, $this->_pk);
  32. }
  33. public function fetch_all_by_navtype_parentid($navtype, $parentid) {
  34. return DB::fetch_all('SELECT * FROM %t WHERE navtype=%d AND parentid=%d ORDER BY displayorder', array($this->_table, $navtype, $parentid), $this->_pk);
  35. }
  36. public function fetch_all_by_navtype_type($navtype, $type) {
  37. return DB::fetch_all('SELECT * FROM %t WHERE navtype=%d AND type=%d', array($this->_table, $navtype, $type), $this->_pk);
  38. }
  39. public function fetch_all_mainnav() {
  40. return DB::fetch_all('SELECT * FROM %t WHERE navtype=0 AND (available=1 OR type=0) AND parentid=0 ORDER BY displayorder', array($this->_table), $this->_pk);
  41. }
  42. public function fetch_all_subnav($parentid) {
  43. return DB::fetch_all('SELECT * FROM %t WHERE navtype=0 AND parentid=%d AND available=1 ORDER BY displayorder', array($this->_table, $parentid), $this->_pk);
  44. }
  45. public function fetch_all_by_navtype_type_identifier($navtype, $type, $identifier) {
  46. $navtype = dintval($navtype, true);
  47. $type = dintval($type, true);
  48. if($navtype && $type) {
  49. $wherearr[] = DB::field('navtype', $navtype);
  50. $wherearr[] = DB::field('type', $type);
  51. $wherearr[] = DB::field('identifier', $identifier);
  52. return DB::fetch_all('SELECT * FROM %t WHERE %i', array($this->_table, implode(' AND ', $wherearr)), 'identifier');
  53. }
  54. return array();
  55. }
  56. public function update_by_identifier($identifier, $data) {
  57. if(is_array($identifier) && empty($identifier)) {
  58. return 0;
  59. }
  60. if(!empty($data) && is_array($data)) {
  61. return DB::update($this->_table, $data, DB::field('identifier', $identifier));
  62. }
  63. return 0;
  64. }
  65. public function update_by_navtype_type_identifier($navtype, $type, $identifier, $data) {
  66. if(!empty($data) && is_array($data)) {
  67. $navtype = dintval($navtype, true);
  68. $type = dintval($type, true);
  69. if(is_array($navtype) && empty($navtype) || is_array($type) && empty($type) || is_array($identifier) && empty($identifier)) {
  70. return 0;
  71. }
  72. $wherearr[] = DB::field('navtype', $navtype);
  73. $wherearr[] = DB::field('type', $type);
  74. $wherearr[] = DB::field('identifier', $identifier);
  75. return DB::update($this->_table, $data, implode(' AND ', $wherearr));
  76. }
  77. return 0;
  78. }
  79. public function update_by_type_identifier($type, $identifier, $data) {
  80. $type = dintval($type, is_array($type) ? true : false);
  81. if(is_array($identifier) && empty($identifier)) {
  82. return 0;
  83. }
  84. if(!empty($data) && is_array($data)) {
  85. return DB::update($this->_table, $data, DB::field('type', $type).' AND '.DB::field('identifier', $identifier));
  86. }
  87. return 0;
  88. }
  89. public function delete_by_navtype_id($navtype, $ids) {
  90. $ids = dintval($ids, is_array($ids) ? true : false);
  91. $navtype = dintval($navtype, is_array($navtype) ? true : false);
  92. if($ids) {
  93. return DB::delete($this->_table, DB::field('id', $ids).' AND '.DB::field('navtype', $navtype));
  94. }
  95. return 0;
  96. }
  97. public function delete_by_navtype_parentid($navtype, $parentid) {
  98. $navtype = dintval($navtype, is_array($navtype) ? true : false);
  99. $parentid = dintval($parentid, is_array($parentid) ? true : false);
  100. return DB::delete($this->_table, DB::field('navtype', $navtype).' AND '.DB::field('parentid', $parentid));
  101. }
  102. public function delete_by_type_identifier($type, $identifier) {
  103. if(is_array($identifier) && empty($identifier)) {
  104. return 0;
  105. }
  106. $type = dintval($type, is_array($type) ? true : false);
  107. return DB::delete($this->_table, DB::field('type', $type).' AND '.DB::field('identifier', $identifier));
  108. }
  109. public function delete_by_parentid($id) {
  110. $id = dintval($id, is_array($id) ? true : false);
  111. if($id) {
  112. return DB::delete($this->_table, DB::field('parentid', $id));
  113. }
  114. return 0;
  115. }
  116. public function count_by_navtype_type_identifier($navtype, $type, $identifier) {
  117. return DB::result_first('SELECT COUNT(*) FROM %t WHERE navtype=%d AND type=%d AND identifier=%s', array($this->_table, $navtype, $type, $identifier));
  118. }
  119. }
  120. ?>