Backend.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program 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 License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Group;
  23. /**
  24. * Abstract base class for user management
  25. */
  26. abstract class Backend implements \OCP\GroupInterface {
  27. /**
  28. * error code for functions not provided by the group backend
  29. */
  30. const NOT_IMPLEMENTED = -501;
  31. protected $possibleActions = [
  32. self::CREATE_GROUP => 'createGroup',
  33. self::DELETE_GROUP => 'deleteGroup',
  34. self::ADD_TO_GROUP => 'addToGroup',
  35. self::REMOVE_FROM_GOUP => 'removeFromGroup',
  36. self::COUNT_USERS => 'countUsersInGroup',
  37. self::GROUP_DETAILS => 'getGroupDetails',
  38. ];
  39. /**
  40. * Get all supported actions
  41. * @return int bitwise-or'ed actions
  42. *
  43. * Returns the supported actions as int to be
  44. * compared with \OC\Group\Backend::CREATE_GROUP etc.
  45. */
  46. public function getSupportedActions() {
  47. $actions = 0;
  48. foreach($this->possibleActions AS $action => $methodName) {
  49. if(method_exists($this, $methodName)) {
  50. $actions |= $action;
  51. }
  52. }
  53. return $actions;
  54. }
  55. /**
  56. * Check if backend implements actions
  57. * @param int $actions bitwise-or'ed actions
  58. * @return bool
  59. *
  60. * Returns the supported actions as int to be
  61. * compared with \OC\Group\Backend::CREATE_GROUP etc.
  62. */
  63. public function implementsActions($actions) {
  64. return (bool)($this->getSupportedActions() & $actions);
  65. }
  66. /**
  67. * is user in group?
  68. * @param string $uid uid of the user
  69. * @param string $gid gid of the group
  70. * @return bool
  71. *
  72. * Checks whether the user is member of a group or not.
  73. */
  74. public function inGroup($uid, $gid) {
  75. return in_array($gid, $this->getUserGroups($uid));
  76. }
  77. /**
  78. * Get all groups a user belongs to
  79. * @param string $uid Name of the user
  80. * @return array an array of group names
  81. *
  82. * This function fetches all groups a user belongs to. It does not check
  83. * if the user exists at all.
  84. */
  85. public function getUserGroups($uid) {
  86. return array();
  87. }
  88. /**
  89. * get a list of all groups
  90. * @param string $search
  91. * @param int $limit
  92. * @param int $offset
  93. * @return array an array of group names
  94. *
  95. * Returns a list with all groups
  96. */
  97. public function getGroups($search = '', $limit = -1, $offset = 0) {
  98. return array();
  99. }
  100. /**
  101. * check if a group exists
  102. * @param string $gid
  103. * @return bool
  104. */
  105. public function groupExists($gid) {
  106. return in_array($gid, $this->getGroups($gid, 1));
  107. }
  108. /**
  109. * get a list of all users in a group
  110. * @param string $gid
  111. * @param string $search
  112. * @param int $limit
  113. * @param int $offset
  114. * @return array an array of user ids
  115. */
  116. public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
  117. return array();
  118. }
  119. }