Issues (27)

lib/Model/Circle.php (2 issues)

Labels
Severity
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\App\IAppManager;
28
use OCA\Circles\Api\v1\Circles;
0 ignored issues
show
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...
29
use OCA\Circles\Model\Circle as CirclesCircle;
0 ignored issues
show
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...
30
use OCA\Polls\Exceptions\CirclesNotEnabledException;
31
32
class Circle extends UserGroupClass {
33
	public const TYPE = 'circle';
34
	public const ICON = 'icon-circles';
35
36
	/** @var CirclesCircle */
37
	private $circle;
38
39
	public function __construct(
40
		string $id
41
	) {
42
		parent::__construct($id, self::TYPE);
43
		if (self::isEnabled()) {
44
			$this->icon = self::ICON;
45
			$this->circle = Circles::detailsCircle($id);
46
			$this->displayName = $this->circle->getName();
47
			$this->description = $this->circle->gettypeLongString();
48
		} else {
49
			throw new CirclesNotEnabledException();
50
		}
51
	}
52
53
	public static function isEnabled(): bool {
54
		return self::getContainer()->query(IAppManager::class)->isEnabledForUser('circles');
55
	}
56
57
	/**
58
	 * @return Circle[]
59
	 */
60
	public static function search(string $query = '', array $skip = []): array {
61
		$circles = [];
62
		if (self::isEnabled()) {
63
			foreach (Circles::listCircles(CirclesCircle::CIRCLES_ALL, $query) as $circle) {
64
				if (!in_array($circle->getUniqueId(), $skip)) {
65
					$circles[] = new self($circle->getUniqueId());
66
				}
67
			}
68
		}
69
70
		return $circles;
71
	}
72
73
	/**
74
	 * @return User[]|Email[]|Contact[]
75
	 */
76
	public function getMembers(): array {
77
		$members = [];
78
		if (self::isEnabled()) {
79
			foreach (Circles::detailsCircle($this->id)->getMembers() as $circleMember) {
80
				if ($circleMember->getType() === Circles::TYPE_USER) {
81
					$members[] = new User($circleMember->getUserId());
82
				} elseif ($circleMember->getType() === Circles::TYPE_MAIL) {
83
					$members[] = new Email($circleMember->getUserId());
84
				} elseif ($circleMember->getType() === Circles::TYPE_CONTACT) {
85
					$members[] = new Contact($circleMember->getUserId());
86
				} else {
87
					continue;
88
				}
89
			}
90
		}
91
		return $members;
92
	}
93
}
94