Passed
Pull Request — master (#1169)
by René
06:00
created

User   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 5
Bugs 2 Features 3
Metric Value
wmc 6
eloc 19
c 5
b 2
f 3
dl 0
loc 58
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserIsDisabled() 0 2 1
A listRaw() 0 2 1
A search() 0 8 3
A __construct() 0 12 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
class User extends UserGroupClass {
28
	public const TYPE = 'user';
29
	public const ICON = 'icon-user';
30
31
	private $user;
32
33
	/**
34
	 * User constructor.
35
	 * @param $id
36
	 */
37
	public function __construct(
38
		$id
39
	) {
40
		parent::__construct($id, self::TYPE);
41
		$this->icon = self::ICON;
42
		$this->isNoUser = false;
43
		$this->description = \OC::$server->getL10N('polls')->t('User');
44
45
		$this->user = \OC::$server->getUserManager()->get($this->id);
46
		$this->displayName = $this->user->getDisplayName();
47
		$this->emailAddress = $this->user->getEMailAddress();
48
		$this->language = \OC::$server->getConfig()->getUserValue($this->id, 'core', 'lang');
49
	}
50
51
	/**
52
	 * getUserIsDisabled
53
	 * @NoAdminRequired
54
	 * @return Boolean
55
	 */
56
	public function getUserIsDisabled() {
57
		return !\OC::$server->getUserManager()->get($this->id)->isEnabled();
58
	}
59
60
	/**
61
	 * listRaw
62
	 * @NoAdminRequired
63
	 * @param string $query
64
	 * @return Array
65
	 */
66
	public static function listRaw($query = '') {
67
		return \OC::$server->getUserManager()->search($query);
68
	}
69
70
	/**
71
	 * search
72
	 * @NoAdminRequired
73
	 * @param string $query
74
	 * @param array $skip - group names to skip in return array
75
	 * @return User[]
76
	 */
77
	public static function search($query = '', $skip = []) {
78
		$users = [];
79
		foreach (self::listRaw($query) as $user) {
80
			if (!in_array($user->getUID(), $skip)) {
81
				$users[] = new Self($user->getUID());
82
			}
83
		}
84
		return $users;
85
	}
86
}
87