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

Circle::getMembers()   A

Complexity

Conditions 6
Paths 2

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 16
rs 9.2222
c 1
b 0
f 0
cc 6
nc 2
nop 0
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 OCA\Circles\Api\v1\Circles;
0 ignored issues
show
Bug introduced by
The type OCA\Circles\Api\v1\Circles 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...
28
29
use OCA\Polls\Exceptions\CirclesNotEnabled;
30
31
class Circle extends UserGroupClass {
32
	public const TYPE = 'circle';
33
	public const ICON = 'icon-circles';
34
35
	private $circle;
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
		if (\OC::$server->getAppManager()->isEnabledForUser('circles')) {
47
			$this->icon = self::ICON;
48
			$this->circle = Circles::detailsCircle($id);
49
			$this->displayName = $this->circle->getName();
50
			$this->description = $this->circle->gettypeLongString();
51
52
		} else {
53
			throw new CirclesNotEnabled();
54
		}
55
	}
56
57
	/**
58
	 * isEnabled
59
	 * @NoAdminRequired
60
	 * @return Boolean
61
	 */
62
	public static function isEnabled() {
63
		return \OC::$server->getAppManager()->isEnabledForUser('circles');
64
	}
65
66
	/**
67
	 * listRaw
68
	 * @NoAdminRequired
69
	 * @param string $query
70
	 * @return Array
71
	 */
72
	public static function listRaw($query = '') {
73
		$circles = [];
74
		if (\OC::$server->getAppManager()->isEnabledForUser('circles')) {
75
			$circles = Circles::listCircles(\OCA\Circles\Model\Circle::CIRCLES_ALL, $query);
0 ignored issues
show
Bug introduced by
The type OCA\Circles\Model\Circle 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...
76
		}
77
78
		return $circles;
79
	}
80
81
	/**
82
	 * search
83
	 * @NoAdminRequired
84
	 * @param string $query
85
	 * @param array $skip - group names to skip in return array
86
	 * @return Circle[]
87
	 */
88
	public static function search($query = '', $skip = []) {
89
		$circles = [];
90
		foreach (self::listRaw($query) as $circle) {
91
			if (!in_array($circle->getUniqueId(), $skip)) {
92
				$circles[] = new Self($circle->getUniqueId());
93
			}
94
		}
95
96
		return $circles;
97
	}
98
99
	/**
100
	 * Get a list of circle members
101
	 * @NoAdminRequired
102
	 * @param string $query
103
	 * @return User[]
104
	 */
105
	public function getMembers() {
106
		$members = [];
107
		if (\OC::$server->getAppManager()->isEnabledForUser('circles')) {
108
			foreach (Circles::detailsCircle($this->id)->getMembers() as $circleMember) {
109
				if ($circleMember->getType() === Circles::TYPE_USER) {
110
					$members[] = new User($circleMember->getUserId());
111
				} elseif ($circleMember->getType() === Circles::TYPE_MAIL) {
112
					$members[] = new Email($circleMember->getUserId());
113
				} elseif ($circleMember->getType() === Circles::TYPE_CONTACT) {
114
					$members[] = new Contact($circleMember->getUserId());
115
				} else {
116
					continue;
117
				}
118
			}
119
		}
120
		return $members;
121
	}
122
}
123