table_common_usergroup_field.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_usergroup_field.php 28041 2012-02-21 07:33:55Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_usergroup_field extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_usergroup_field';
  15. $this->_pk = 'groupid';
  16. parent::__construct();
  17. }
  18. public function fetch_readaccess_by_readaccess($readaccess) {
  19. return DB::fetch_all('SELECT groupid,readaccess FROM %t WHERE readaccess>%d ORDER BY readaccess', array($this->_table, $readaccess), $this->_pk);
  20. }
  21. public function fetch_all_fields($gid, $fields) {
  22. if(!is_array($fields) || !$fields) {
  23. return null;
  24. }
  25. foreach($fields as &$field) {
  26. $field = DB::quote_field($field);
  27. }
  28. $fieldssql = implode(',', $fields);
  29. return DB::fetch_all('SELECT %i FROM %t %i', array($fieldssql, $this->_table, ($gid ? 'WHERE '.DB::field('groupid', $gid) : '')), $this->_pk);
  30. }
  31. public function count_by_field($field, $val, $glue = '=') {
  32. $allowedfield = array('allowposttrade');
  33. if(!in_array($field, $allowedfield)) {
  34. return null;
  35. }
  36. return DB::result_first('SELECT count(*) FROM %t WHERE %i', array($this->_table, DB::field($field, $val, $glue)));
  37. }
  38. public function fetch_table_struct($result = 'FIELD') {
  39. $datas = array();
  40. $query = DB::query('DESCRIBE %t', array($this->_table));
  41. while($data = DB::fetch($query)) {
  42. $datas[$data['Field']] = $result == 'FIELD' ? $data['Field'] : $data;
  43. }
  44. return $datas;
  45. }
  46. public function update_allowsearch() {
  47. return DB::query('UPDATE %t SET allowsearch = allowsearch | 2 WHERE groupid < 20 AND groupid NOT IN (5, 6)', array($this->_table));
  48. }
  49. }
  50. ?>