diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-07-09 12:19:50 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-07-14 21:26:37 +0200 |
commit | ab2c7e06a4ea3c751058b6b72dc9b8832836669a (patch) | |
tree | 709a7a31a74be44d08dc038b3169f1cb4144a4d5 /lib/private/group | |
parent | 9ee1c7ff7143c9d75a5f5a9f9477cc73f5d97717 (diff) | |
download | nextcloud-server-ab2c7e06a4ea3c751058b6b72dc9b8832836669a.tar.gz nextcloud-server-ab2c7e06a4ea3c751058b6b72dc9b8832836669a.zip |
remove dead code
do not filter groups. but update the user count according to the filter
improve phpdoc
improve metadata runtime cache
add metadata tests
Diffstat (limited to 'lib/private/group')
-rw-r--r-- | lib/private/group/metadata.php | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/lib/private/group/metadata.php b/lib/private/group/metadata.php index 1883ba727e0..303543d48c6 100644 --- a/lib/private/group/metadata.php +++ b/lib/private/group/metadata.php @@ -24,9 +24,9 @@ class MetaData { protected $isAdmin; /** - * @var string[] $groups + * @var array $metaData */ - protected $groups = array(); + protected $metaData = array(); /** * @var \OC\Group\Manager $groupManager @@ -39,11 +39,6 @@ class MetaData { protected $sorting = false; /** - * @var string $lastSearch - */ - protected $lastSearch; - - /** * @param string the uid of the current user * @param bool whether the current users is an admin * @param \OC\Group\Manager @@ -63,14 +58,15 @@ class MetaData { * the array is structured as follows: * [0] array containing meta data about admin groups * [1] array containing meta data about unprivileged groups - * @param string only effective when instance was created with isAdmin being - * true + * @param string $groupSearch only effective when instance was created with + * isAdmin being true + * @param string $userSearch the pattern users are search for * @return array */ - public function get($search = '') { - if($this->lastSearch !== $search) { - $this->lastSearch = $search; - $this->groups = array(); + public function get($groupSearch = '', $userSearch = '') { + $key = $groupSearch . '::' . $userSearch; + if(isset($this->metaData[$key])) { + return $this->metaData[$key]; } $adminGroups = array(); @@ -80,8 +76,8 @@ class MetaData { $sortAdminGroupsIndex = 0; $sortAdminGroupsKeys = array(); - foreach($this->getGroups($search) as $group) { - $groupMetaData = $this->generateGroupMetaData($group); + foreach($this->getGroups($groupSearch) as $group) { + $groupMetaData = $this->generateGroupMetaData($group, $userSearch); if (strtolower($group->getGID()) !== 'admin') { $this->addEntry( $groups, @@ -104,7 +100,8 @@ class MetaData { $this->sort($groups, $sortGroupsKeys); $this->sort($adminGroups, $sortAdminGroupsKeys); - return array($adminGroups, $groups); + $this->metaData[$key] = array($adminGroups, $groups); + return $this->metaData[$key]; } /** @@ -138,14 +135,15 @@ class MetaData { /** * @brief creates an array containing the group meta data - * @param \OC\Group\Group + * @param \OC\Group\Group $group + * @param string $userSearch * @return array with the keys 'id', 'name' and 'usercount' */ - private function generateGroupMetaData(\OC\Group\Group $group) { + private function generateGroupMetaData(\OC\Group\Group $group, $userSearch) { return array( - 'id' => str_replace(' ','', $group->getGID()), + 'id' => $group->getGID(), 'name' => $group->getGID(), - 'usercount' => $group->count() + 'usercount' => $group->count($userSearch) ); } @@ -167,22 +165,10 @@ class MetaData { * @return \OC\Group\Group[] */ private function getGroups($search = '') { - if(count($this->groups) === 0) { - $this->fetchGroups($search); - } - return $this->groups; - } - - /** - * @brief fetches the group using the group manager or the subAdmin API - * @param string a search string - * @return null - */ - private function fetchGroups($search = '') { if($this->isAdmin) { - $this->groups = $this->groupManager->search($search); + return $this->groupManager->search($search); } else { - $this->groups = \OC_SubAdmin::getSubAdminsGroups($this->user); + return \OC_SubAdmin::getSubAdminsGroups($this->user); } } } |