table_portal_category.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_portal_category.php 27876 2012-02-16 04:28:02Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_portal_category extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'portal_category';
  15. $this->_pk = 'catid';
  16. parent::__construct();
  17. }
  18. public function fetch_all_numkey($numkey) {
  19. $allow_numkey = array('portal', 'articles', 'num');
  20. if(!in_array($numkey, $allow_numkey)) {
  21. return null;
  22. }
  23. return DB::fetch_all("SELECT catid, $numkey FROM %t", array($this->_table), $this->_pk);
  24. }
  25. public function increase($catids, $data) {
  26. $catids = array_map('intval', (array)$catids);
  27. $sql = array();
  28. $allowkey = array('articles');
  29. foreach($data as $key => $value) {
  30. if(($value = intval($value)) && in_array($key, $allowkey)) {
  31. $sql[] = "`$key`=`$key`+'$value'";
  32. }
  33. }
  34. if(!empty($sql)){
  35. DB::query("UPDATE ".DB::table($this->_table)." SET ".implode(',', $sql)." WHERE catid IN (".dimplode($catids).")", 'UNBUFFERED');
  36. }
  37. }
  38. public function range($start = 0, $limit = 0) {
  39. $data = array();
  40. $query = DB::query('SELECT * FROM '.DB::table($this->_table).' ORDER BY displayorder,catid'.DB::limit($start, $limit));
  41. while($value = DB::fetch($query)) {
  42. $value['catname'] = dhtmlspecialchars($value['catname']);
  43. $data[$value['catid']] = $value;
  44. }
  45. return $data;
  46. }
  47. }
  48. ?>