function.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. require_once "../config.php";
  3. require_once "../share/function.php";
  4. require_once "../db/table.php";
  5. class Channal extends Table
  6. {
  7. function __construct($redis=false) {
  8. parent::__construct(_FILE_DB_CHANNAL_, _TABLE_CHANNEL_, _DB_USERNAME_,_DB_PASSWORD_,$redis);
  9. }
  10. public function getChannal($id){
  11. $query = "SELECT * FROM ".$this->table." WHERE uid =? ";
  12. $stmt = $this->dbh->prepare($query);
  13. $stmt->execute(array($id));
  14. $channal = $stmt->fetch(PDO::FETCH_ASSOC);
  15. if($channal){
  16. return $channal;
  17. }
  18. else{
  19. return false;
  20. }
  21. }
  22. public function getTitle($id)
  23. {
  24. if (isset($id)) {
  25. $query = "SELECT name FROM ".$this->table." WHERE uid = ? ";
  26. $stmt = $this->dbh->prepare($query);
  27. $stmt->execute(array($id));
  28. $channal = $stmt->fetch(PDO::FETCH_ASSOC);
  29. if ($channel) {
  30. return $channel["name"];
  31. } else {
  32. return "";
  33. }
  34. } else {
  35. return "";
  36. }
  37. }
  38. public function insert($data){
  39. }
  40. public function update($data){
  41. }
  42. public function delete($data){
  43. }
  44. public function getPower($id){
  45. #查询用户对此channel是否有权限
  46. if(isset($_COOKIE["user_id"])){
  47. $userId = $_COOKIE["user_id"];
  48. }
  49. else{
  50. $userId='0';
  51. }
  52. if($this->redis!==false){
  53. $power = $this->redis->hGet("power://channel/".$id,$userId);
  54. if($power!==FALSE){
  55. return $power;
  56. }
  57. }
  58. $channelPower = 0;
  59. $query = "SELECT owner_uid,status FROM "._TABLE_CHANNEL_." WHERE uid=? and status>0 ";
  60. $stmt = $this->dbh->prepare($query);
  61. $stmt->execute(array($id));
  62. $channel = $stmt->fetch(PDO::FETCH_ASSOC);
  63. if($channel){
  64. if(!isset($_COOKIE["user_id"]) ){
  65. #未登录用户
  66. if($channel["status"]==30){
  67. #全网公开有建议权限
  68. return 10;
  69. }
  70. else{
  71. #其他状态没有任何权限
  72. return 0;
  73. }
  74. }
  75. if($channel["owner_uid"]==$_COOKIE["user_uid"]){
  76. return 30;
  77. }
  78. else if($channel["status"]>=30){
  79. #全网公开的 可以提交pr
  80. $channelPower = 10;
  81. }
  82. }
  83. #查询共享权限,如果共享权限更大,覆盖上面的的
  84. $sharePower = share_get_res_power($_COOKIE["user_uid"],$id);
  85. if($sharePower>$channelPower){
  86. $channelPower=$sharePower;
  87. }
  88. if($this->redis){
  89. $this->redis->hSet("power://channel/".$id,$_COOKIE["user_uid"],$channelPower);
  90. }
  91. return $channelPower;
  92. }
  93. }
  94. ?>