You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dummy.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * dummy group backend, does not keep state, only for testing use
  24. */
  25. class OC_Group_Dummy extends OC_Group_Backend {
  26. private $groups=array();
  27. /**
  28. * @brief Try to create a new group
  29. * @param $gid The name of the group to create
  30. * @returns true/false
  31. *
  32. * Trys to create a new group. If the group name already exists, false will
  33. * be returned.
  34. */
  35. public function createGroup($gid) {
  36. if(!isset($this->groups[$gid])) {
  37. $this->groups[$gid]=array();
  38. return true;
  39. }else{
  40. return false;
  41. }
  42. }
  43. /**
  44. * @brief delete a group
  45. * @param $gid gid of the group to delete
  46. * @returns true/false
  47. *
  48. * Deletes a group and removes it from the group_user-table
  49. */
  50. public function deleteGroup($gid) {
  51. if(isset($this->groups[$gid])) {
  52. unset($this->groups[$gid]);
  53. return true;
  54. }else{
  55. return false;
  56. }
  57. }
  58. /**
  59. * @brief is user in group?
  60. * @param $uid uid of the user
  61. * @param $gid gid of the group
  62. * @returns true/false
  63. *
  64. * Checks whether the user is member of a group or not.
  65. */
  66. public function inGroup($uid, $gid) {
  67. if(isset($this->groups[$gid])) {
  68. return (array_search($uid, $this->groups[$gid])!==false);
  69. }else{
  70. return false;
  71. }
  72. }
  73. /**
  74. * @brief Add a user to a group
  75. * @param $uid Name of the user to add to group
  76. * @param $gid Name of the group in which add the user
  77. * @returns true/false
  78. *
  79. * Adds a user to a group.
  80. */
  81. public function addToGroup($uid, $gid) {
  82. if(isset($this->groups[$gid])) {
  83. if(array_search($uid, $this->groups[$gid])===false) {
  84. $this->groups[$gid][]=$uid;
  85. return true;
  86. }else{
  87. return false;
  88. }
  89. }else{
  90. return false;
  91. }
  92. }
  93. /**
  94. * @brief Removes a user from a group
  95. * @param $uid NameUSER of the user to remove from group
  96. * @param $gid Name of the group from which remove the user
  97. * @returns true/false
  98. *
  99. * removes the user from a group.
  100. */
  101. public function removeFromGroup($uid, $gid) {
  102. if(isset($this->groups[$gid])) {
  103. if(($index=array_search($uid, $this->groups[$gid]))!==false) {
  104. unset($this->groups[$gid][$index]);
  105. }else{
  106. return false;
  107. }
  108. }else{
  109. return false;
  110. }
  111. }
  112. /**
  113. * @brief Get all groups a user belongs to
  114. * @param $uid Name of the user
  115. * @returns array with group names
  116. *
  117. * This function fetches all groups a user belongs to. It does not check
  118. * if the user exists at all.
  119. */
  120. public function getUserGroups($uid) {
  121. $groups=array();
  122. $allGroups=array_keys($this->groups);
  123. foreach($allGroups as $group) {
  124. if($this->inGroup($uid, $group)) {
  125. $groups[]=$group;
  126. }
  127. }
  128. return $groups;
  129. }
  130. /**
  131. * @brief get a list of all groups
  132. * @returns array with group names
  133. *
  134. * Returns a list with all groups
  135. */
  136. public function getGroups($search = '', $limit = -1, $offset = 0) {
  137. return array_keys($this->groups);
  138. }
  139. /**
  140. * @brief get a list of all users in a group
  141. * @returns array with user ids
  142. */
  143. public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
  144. if(isset($this->groups[$gid])) {
  145. return $this->groups[$gid];
  146. }else{
  147. return array();
  148. }
  149. }
  150. }