Completed
Pull Request — master (#1128)
by René
04:35
created

Group::listRaw()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
25
namespace OCA\Polls\Model;
26
27
use OCP\IGroup;
28
use OCA\Polls\Interfaces\IUserObj;
0 ignored issues
show
Bug introduced by
The type OCA\Polls\Interfaces\IUserObj was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
30
class Group extends UserGroupClass {
31
	public const TYPE = 'group';
32
	public const ICON = 'icon-group';
33
34
	/** @var IGroup */
35
	private $group;
36
37
	/**
38
	 * Group constructor.
39
	 * @param $id
40
	 * @param $displayName
41
	 */
42
	public function __construct(
43
		$id
44
	) {
45
		parent::__construct($id, self::TYPE);
46
		$this->icon = self::ICON;
47
48
		$this->group = \OC::$server->getGroupManager()->get($this->id);
49
		$this->description = \OC::$server->getL10N('polls')->t('Group');
50
		try {
51
			// since NC19
52
			$this->displayName = $this->group->getDisplayName();
53
		} catch (\Exception $e) {
54
			// until NC18
55
			$this->displayName = $this->id;
56
		}
57
	}
58
59
	/**
60
	 * listRaw
61
	 * @NoAdminRequired
62
	 * @param string $query
63
	 * @return Array
64
	 */
65
	public static function listRaw($query = '') {
66
		return \OC::$server->getGroupManager()->search($query);
67
	}
68
69
	/**
70
	 * search
71
	 * @NoAdminRequired
72
	 * @param string $query
73
	 * @param array $skip - group names to skip in return array
74
	 * @return Group[]
75
	 */
76
	public static function search($query = '', $skip = []) {
77
		$groups = [];
78
		foreach (self::listRaw($query) as $group) {
79
			if (!in_array($group->getGID(), $skip)) {
80
				$groups[] = new Self($group->getGID());
81
			}
82
		}
83
		return $groups;
84
	}
85
86
	/**
87
	 * getMembers
88
	 * @NoAdminRequired
89
	 * @param string $query
90
	 * @return User[]
91
	 */
92
	public function getMembers() {
93
		$members = [];
94
		foreach (array_keys(\OC::$server->getGroupManager()->displayNamesInGroup($this->id)) as $member) {
95
			$members[] = new User($member);
96
		}
97
		return $members;
98
	}
99
100
}
101