Backend.php 3.4 KB

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