function.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. require_once "../path.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. require_once '../ucenter/function.php';
  6. require_once '../channal/function.php';
  7. require_once '../doc/function.php';
  8. /*
  9. 获取某用户的可见的协作资源
  10. $res_type 见readme.md#资源类型 -1全部类型资源
  11. */
  12. function share_res_list_get($userid,$res_type=-1){
  13. # 找我加入的群
  14. $dbhGroup = new PDO(_FILE_DB_GROUP_, "", "");
  15. $dbhGroup->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  16. $query = "SELECT group_id from group_member where user_id = ? limit 0,200";
  17. $stmtGroup = $dbhGroup->prepare($query);
  18. $stmtGroup->execute(array($userid));
  19. $my_group = $stmtGroup->fetchAll(PDO::FETCH_ASSOC);
  20. $userList = array();
  21. $userList[] = $userid;
  22. foreach ($my_group as $key => $value) {
  23. # code...
  24. $userList[]=$value["group_id"];
  25. }
  26. $place_holders = implode(',', array_fill(0, count($userList), '?'));
  27. $Fetch=array();
  28. $PDO = new PDO(_FILE_DB_USER_SHARE_, "", "");
  29. $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  30. if($res_type==-1){
  31. #所有类型资源
  32. $query = "SELECT res_id,res_type,power FROM share_cooperator WHERE is_deleted=0 AND cooperator_id IN ($place_holders) ";
  33. $stmt = $PDO->prepare($query);
  34. $stmt->execute($userList);
  35. $Fetch =$stmt->fetchAll(PDO::FETCH_ASSOC);
  36. }
  37. else{
  38. #指定类型资源
  39. $userList[]=$res_type;
  40. $query = "SELECT res_id,res_type,power FROM share_cooperator WHERE is_deleted=0 AND cooperator_id IN ($place_holders) AND res_type = ?";
  41. $stmt = $PDO->prepare($query);
  42. $stmt->execute($userList);
  43. $Fetch =$stmt->fetchAll(PDO::FETCH_ASSOC);
  44. }
  45. $resOutput = array();
  46. foreach ($Fetch as $key => $value) {
  47. # 查重
  48. if(isset($resOutput[$value["res_id"]])){
  49. if($value["power"]>$resOutput[$value["res_id"]]["power"]){
  50. $resOutput[$value["res_id"]]["power"] = $value["power"];
  51. }
  52. }
  53. else{
  54. $resOutput[$value["res_id"]]= array("power"=> $value["power"],"type" => $value["res_type"]);
  55. }
  56. }
  57. $resList=array();
  58. foreach ($resOutput as $key => $value) {
  59. # code...
  60. $resList[]=array("res_id"=>$key,"res_type"=>(int)$value["type"],"power"=>(int)$value["power"]);
  61. }
  62. $channel = new Channal();
  63. foreach ($resList as $key => $res) {
  64. # 获取资源标题 和所有者
  65. switch ($res["res_type"]) {
  66. case 1:
  67. # pcs 文档
  68. $resList[$key]["res_title"]=pcs_get_title($res["res_id"]);
  69. break;
  70. case 2:
  71. # channel
  72. $channelInfo = $channel->getChannal($res["res_id"]);
  73. if($channelInfo){
  74. $resList[$key]["res_title"]=$channelInfo["name"];
  75. $resList[$key]["res_owner_id"]=$channelInfo["owner"];
  76. }
  77. else{
  78. $resList[$key]["res_title"]="_unkown_";
  79. $resList[$key]["res_owner_id"]="_unkown_";
  80. }
  81. break;
  82. case 3:
  83. # 3 Article 文章
  84. break;
  85. case 4:
  86. # 4 Collection 文集
  87. break;
  88. case 5:
  89. # code...
  90. break;
  91. default:
  92. # code...
  93. break;
  94. }
  95. }
  96. return $resList;
  97. }
  98. //获取对某个共享资源的权限
  99. function share_get_res_power($userid,$res_id){
  100. # 找我加入的群
  101. $dbhGroup = new PDO(_FILE_DB_GROUP_, "", "");
  102. $dbhGroup->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  103. $query = "SELECT group_id from group_member where user_id = ? limit 0,100";
  104. $stmtGroup = $dbhGroup->prepare($query);
  105. $stmtGroup->execute(array($userid));
  106. $my_group = $stmtGroup->fetchAll(PDO::FETCH_ASSOC);
  107. $userList = array();
  108. $userList[] = $userid;
  109. foreach ($my_group as $key => $value) {
  110. # code...
  111. $userList[]=$value["group_id"];
  112. }
  113. $place_holders = implode(',', array_fill(0, count($userList), '?'));
  114. $Fetch=array();
  115. $PDO = new PDO(_FILE_DB_USER_SHARE_, "", "");
  116. $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  117. $userList[]=$res_id;
  118. $query = "SELECT power FROM share_cooperator WHERE is_deleted=0 AND cooperator_id IN ($place_holders) AND res_id = ? ";
  119. $stmt = $PDO->prepare($query);
  120. $stmt->execute($userList);
  121. $Fetch =$stmt->fetchAll(PDO::FETCH_ASSOC);
  122. $power=0;
  123. foreach ($Fetch as $key => $value) {
  124. # code...
  125. if((int)$value["power"]>$power){
  126. $power = $value["power"];
  127. }
  128. }
  129. return $power;
  130. }
  131. ?>