table_common_template_permission.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_permission.php 27830 2012-02-15 07:39:23Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_template_permission extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_template_permission';
  15. $this->_pk = '';
  16. parent::__construct();
  17. }
  18. public function fetch_all_by_targettplname($targettplname) {
  19. return DB::fetch_all('SELECT * FROM %t WHERE targettplname=%s ORDER BY inheritedtplname', array($this->_table, $targettplname), 'uid');
  20. }
  21. public function fetch_all_by_uid($uids, $flag = true, $sort = 'ASC', $start = 0, $limit = 0) {
  22. $wherearr = array();
  23. $sort = $sort === 'ASC' ? 'ASC' : 'DESC';
  24. if(($uids = dintval($uids, true))) {
  25. $wherearr[] = DB::field('uid', $uids);
  26. }
  27. if(!$flag) {
  28. $wherearr[] = 'inheritedtplname = \'\'';
  29. }
  30. $where = $wherearr ? ' WHERE '.implode(' AND ', $wherearr) : '';
  31. return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).$where.' ORDER BY uid '.$sort.', inheritedtplname'.DB::limit($start, $limit), NULL, 'targettplname');
  32. }
  33. public function count_by_uids($uids, $flag) {
  34. $wherearr = array();
  35. if(($uids = dintval($uids, true))) {
  36. $wherearr[] = DB::field('uid', $uids);
  37. }
  38. if(!$flag) {
  39. $wherearr[] = 'inheritedtplname = \'\'';
  40. }
  41. $where = $wherearr ? ' WHERE '.implode(' AND ', $wherearr) : '';
  42. return DB::result_first('SELECT COUNT(*) FROM '.DB::table($this->_table).$where);
  43. }
  44. public function delete_by_targettplname_uid_inheritedtplname($targettplname = false, $uids = false, $inheritedtplname = false) {
  45. $wherearr = array();
  46. if($targettplname) {
  47. $wherearr[] = DB::field('targettplname', $targettplname);
  48. }
  49. if(($uids = dintval($uids, true))) {
  50. $wherearr[] = DB::field('uid', $uids);
  51. }
  52. if($inheritedtplname === true) {
  53. $wherearr[] = "inheritedtplname!=''";
  54. } elseif($inheritedtplname !== false && is_string($inheritedtplname)) {
  55. $wherearr[] = DB::field('inheritedtplname', $inheritedtplname);
  56. }
  57. return $wherearr ? DB::delete($this->_table, implode(' AND ', $wherearr)) : false;
  58. }
  59. public function insert_batch($users, $templates, $uptplname = '') {
  60. $blockperms = array();
  61. if(!empty($users) && !empty($templates)){
  62. if(!is_array($templates)) {
  63. $templates = array($templates);
  64. }
  65. foreach($users as $user) {
  66. $inheritedtplname = $uptplname ? $uptplname : '';
  67. foreach ($templates as $tpl) {
  68. if($tpl) {
  69. $blockperms[] = "('$tpl','$user[uid]','$user[allowmanage]','$user[allowrecommend]','$user[needverify]','$inheritedtplname')";
  70. $inheritedtplname = empty($inheritedtplname) ? $tpl : $inheritedtplname;
  71. }
  72. }
  73. }
  74. if($blockperms) {
  75. DB::query('REPLACE INTO '.DB::table($this->_table).' (targettplname,uid,allowmanage,allowrecommend,needverify,inheritedtplname) VALUES '.implode(',', $blockperms));
  76. }
  77. }
  78. }
  79. }
  80. ?>