* post_removeFromGroup(uid, gid)
*/
class OC_Group {
- /**
- * @var \OC\Group\Manager $manager
- */
- private static $manager;
/**
- * @var \OC\User\Manager
+ * @return \OC\Group\Manager
*/
- private static $userManager;
+ public static function getManager() {
+ return \OC::$server->getGroupManager();
+ }
/**
- * @return \OC\Group\Manager
+ * @return \OC\User\Manager
*/
- public static function getManager() {
- if (self::$manager) {
- return self::$manager;
- }
- self::$userManager = \OC_User::getManager();
- self::$manager = new \OC\Group\Manager(self::$userManager);
- return self::$manager;
+ private static function getUserManager() {
+ return \OC::$server->getUserManager();
}
/**
*/
public static function inGroup($uid, $gid) {
$group = self::getManager()->get($gid);
- $user = self::$userManager->get($uid);
+ $user = self::getUserManager()->get($uid);
if ($group and $user) {
return $group->inGroup($user);
}
*/
public static function addToGroup($uid, $gid) {
$group = self::getManager()->get($gid);
- $user = self::$userManager->get($uid);
+ $user = self::getUserManager()->get($uid);
if ($group and $user) {
OC_Hook::emit("OC_Group", "pre_addToGroup", array("run" => true, "uid" => $uid, "gid" => $gid));
$group->addUser($user);
*/
public static function removeFromGroup($uid, $gid) {
$group = self::getManager()->get($gid);
- $user = self::$userManager->get($uid);
+ $user = self::getUserManager()->get($uid);
if ($group and $user) {
OC_Hook::emit("OC_Group", "pre_removeFromGroup", array("run" => true, "uid" => $uid, "gid" => $gid));
$group->removeUser($user);
* if the user exists at all.
*/
public static function getUserGroups($uid) {
- $user = self::$userManager->get($uid);
+ $user = self::getUserManager()->get($uid);
if ($user) {
return self::getManager()->getUserGroupIds($user);
} else {
/**
* Class Server
+ *
* @package OC
*
* TODO: hookup all manager classes
class Server extends SimpleContainer implements IServerContainer {
function __construct() {
- $this->registerService('ContactsManager', function($c) {
+ $this->registerService('ContactsManager', function ($c) {
return new ContactsManager();
});
- $this->registerService('Request', function($c) {
+ $this->registerService('Request', function ($c) {
if (isset($c['urlParams'])) {
$urlParams = $c['urlParams'];
} else {
}
if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
- && in_array('fakeinput', stream_get_wrappers())) {
+ && in_array('fakeinput', stream_get_wrappers())
+ ) {
$stream = 'fakeinput://data';
} else {
$stream = 'php://input';
'env' => $_ENV,
'cookies' => $_COOKIE,
'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
- ? $_SERVER['REQUEST_METHOD']
- : null,
+ ? $_SERVER['REQUEST_METHOD']
+ : null,
'urlParams' => $urlParams,
'requesttoken' => $requestToken,
), $stream
);
});
- $this->registerService('PreviewManager', function($c) {
+ $this->registerService('PreviewManager', function ($c) {
return new PreviewManager();
});
- $this->registerService('TagManager', function($c) {
+ $this->registerService('TagManager', function ($c) {
$user = \OC_User::getUser();
return new TagManager($user);
});
- $this->registerService('RootFolder', function($c) {
+ $this->registerService('RootFolder', function ($c) {
// TODO: get user and user manager from container as well
$user = \OC_User::getUser();
/** @var $c SimpleContainer */
$view = new View();
return new Root($manager, $view, $user);
});
- $this->registerService('UserManager', function($c) {
+ $this->registerService('UserManager', function ($c) {
/**
* @var SimpleContainer $c
* @var \OC\AllConfig $config
$config = $c->query('AllConfig');
return new \OC\User\Manager($config);
});
- $this->registerService('UserSession', function($c) {
+ $this->registerService('GroupManager', function ($c) {
+ /**
+ * @var SimpleContainer $c
+ * @var \OC\User\Manager $userManager
+ */
+ $userManager = $c->query('UserManager');
+ return new \OC\Group\Manager($userManager);
+ });
+ $this->registerService('UserSession', function ($c) {
/**
* @var SimpleContainer $c
* @var \OC\User\Manager $manager
});
return $userSession;
});
- $this->registerService('NavigationManager', function($c) {
+ $this->registerService('NavigationManager', function ($c) {
return new \OC\NavigationManager();
});
- $this->registerService('AllConfig', function($c) {
+ $this->registerService('AllConfig', function ($c) {
return new \OC\AllConfig();
});
$this->registerService('AppConfig', function ($c) {
return new \OC\AppConfig(\OC_DB::getConnection());
});
- $this->registerService('L10NFactory', function($c) {
+ $this->registerService('L10NFactory', function ($c) {
return new \OC\L10N\Factory();
});
- $this->registerService('URLGenerator', function($c) {
+ $this->registerService('URLGenerator', function ($c) {
/** @var $c SimpleContainer */
$config = $c->query('AllConfig');
return new \OC\URLGenerator($config);
});
- $this->registerService('AppHelper', function($c) {
+ $this->registerService('AppHelper', function ($c) {
return new \OC\AppHelper();
});
- $this->registerService('UserCache', function($c) {
+ $this->registerService('UserCache', function ($c) {
return new UserCache();
});
$this->registerService('MemCacheFactory', function ($c) {
$instanceId = \OC_Util::getInstanceId();
return new \OC\Memcache\Factory($instanceId);
});
- $this->registerService('ActivityManager', function($c) {
+ $this->registerService('ActivityManager', function ($c) {
return new ActivityManager();
});
- $this->registerService('AvatarManager', function($c) {
+ $this->registerService('AvatarManager', function ($c) {
return new AvatarManager();
});
- $this->registerService('Logger', function($c) {
+ $this->registerService('Logger', function ($c) {
/** @var $c SimpleContainer */
$logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
$logger = 'OC_Log_' . ucfirst($logClass);
$config = $c->getConfig();
return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
});
- $this->registerService('Router', function ($c){
+ $this->registerService('Router', function ($c) {
/**
* @var Server $c
*/
}
return $router;
});
- $this->registerService('Search', function($c){
+ $this->registerService('Search', function ($c) {
return new Search();
});
- $this->registerService('Db', function($c){
+ $this->registerService('Db', function ($c) {
return new Db();
});
}
$root = $this->getRootFolder();
$folder = null;
- if(!$root->nodeExists($dir)) {
+ if (!$root->nodeExists($dir)) {
$folder = $root->newFolder($dir);
} else {
$folder = $root->get($dir);
}
$dir = '/files';
- if(!$folder->nodeExists($dir)) {
+ if (!$folder->nodeExists($dir)) {
$folder = $folder->newFolder($dir);
} else {
$folder = $folder->get($dir);
$dir = '/' . \OC_App::getCurrentApp();
$root = $this->getRootFolder();
$folder = null;
- if(!$root->nodeExists($dir)) {
+ if (!$root->nodeExists($dir)) {
$folder = $root->newFolder($dir);
} else {
$folder = $root->get($dir);
return $this->query('UserManager');
}
+ /**
+ * @return \OC\Group\Manager
+ */
+ function getGroupManager() {
+ return $this->query('GroupManager');
+ }
+
/**
* @return \OC\User\Session
*/
*
* @return \OCP\IAppConfig
*/
- function getAppConfig(){
+ function getAppConfig() {
return $this->query('AppConfig');
}
/**
* get an L10N instance
+ *
* @param string $app appid
* @return \OC_L10N
*/
*
* @return \OCP\BackgroundJob\IJobList
*/
- function getJobList(){
+ function getJobList() {
return $this->query('JobList');
}
*
* @return \OCP\Route\IRouter
*/
- function getRouter(){
+ function getRouter() {
return $this->query('Router');
}
/**
* Returns a search instance
+ *
* @return \OCP\ISearch
*/
function getSearch() {
/**
* Returns an instance of the db facade
+ *
* @return \OCP\IDb
*/
function getDb() {
--- /dev/null
+<?php
+
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP;
+
+/**
+ * Class Manager
+ *
+ * Hooks available in scope \OC\Group:
+ * - preAddUser(\OC\Group\Group $group, \OC\User\User $user)
+ * - postAddUser(\OC\Group\Group $group, \OC\User\User $user)
+ * - preRemoveUser(\OC\Group\Group $group, \OC\User\User $user)
+ * - postRemoveUser(\OC\Group\Group $group, \OC\User\User $user)
+ * - preDelete(\OC\Group\Group $group)
+ * - postDelete(\OC\Group\Group $group)
+ * - preCreate(string $groupId)
+ * - postCreate(\OC\Group\Group $group)
+ *
+ * @package OC\Group
+ */
+interface IGroupManager {
+ /**
+ * @param \OCP\UserInterface $backend
+ */
+ public function addBackend($backend);
+
+ public function clearBackends();
+
+ /**
+ * @param string $gid
+ * @return \OCP\IGroup
+ */
+ public function get($gid);
+
+ /**
+ * @param string $gid
+ * @return bool
+ */
+ public function groupExists($gid);
+
+ /**
+ * @param string $gid
+ * @return \OCP\IGroup
+ */
+ public function createGroup($gid);
+
+ /**
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return \OCP\IGroup[]
+ */
+ public function search($search, $limit = null, $offset = null);
+
+ /**
+ * @param \OCP\IUser $user
+ * @return \OCP\IGroup[]
+ */
+ public function getUserGroups($user);
+
+ /**
+ * @param \OCP\IUser $user
+ * @return array with group names
+ */
+ public function getUserGroupIds($user);
+
+ /**
+ * get a list of all display names in a group
+ *
+ * @param string $gid
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array an array of display names (value) and user ids (key)
+ */
+ public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0);
+}