Passed
Push — master ( 2e7eb3...34dc16 )
by Morris
11:12
created

ServerInfo   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 85
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getForm() 0 10 1
A getPriority() 0 2 1
A getAdminListValues() 0 16 1
A getSection() 0 2 1
A __construct() 0 3 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2018 Michael Weimann <[email protected]>
4
 *
5
 * @author Michael Weimann <[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
namespace OC\Settings\Theming;
24
25
use OCP\AppFramework\Http\TemplateResponse;
26
use OCP\IConfig;
27
use OCP\IGroupManager;
28
use OCP\IUser;
29
use OCP\Settings\ISettings;
30
31
/**
32
 * This class describes the server info settings.
33
 */
34
class ServerInfo implements ISettings {
35
36
	const SETTING_LOCATION = 'serverinfo.location';
37
	const SETTING_PROVIDER = 'serverinfo.provider';
38
	const SETTING_PROVIDER_WEBSITE = 'serverinfo.provider.website';
39
	const SETTING_PROVIDER_PRIVACY_LINK = 'serverinfo.provider.privacylink';
40
	const SETTING_PROVIDER_ADMIN_CONTACT = 'serverinfo.admincontact';
41
42
	/**
43
	 * @var IConfig
44
	 */
45
	private $config;
46
47
	/**
48
	 * @var IGroupManager
49
	 */
50
	private $groupManager;
51
52
	/**
53
	 * ServerInfo constructor.
54
	 *
55
	 * @param IConfig $config
56
	 * @param IGroupManager $groupManager
57
	 */
58
	public function __construct(IConfig $config, IGroupManager $groupManager) {
59
		$this->config = $config;
60
		$this->groupManager = $groupManager;
61
	}
62
63
	/**
64
	 * @return TemplateResponse
65
	 */
66
	public function getForm(): TemplateResponse {
67
		$parameters = [
68
			'location' => $this->config->getSystemValue(self::SETTING_LOCATION),
69
			'provider' => $this->config->getSystemValue(self::SETTING_PROVIDER),
70
			'providerWebsite' => $this->config->getSystemValue(self::SETTING_PROVIDER_WEBSITE),
71
			'providerPrivacyLink' => $this->config->getSystemValue(self::SETTING_PROVIDER_PRIVACY_LINK),
72
			'adminUsers' => $this->getAdminListValues(),
73
			'adminContact' => $this->config->getSystemValue(self::SETTING_PROVIDER_ADMIN_CONTACT),
74
		];
75
		return new TemplateResponse('settings', 'settings/admin/server-info', $parameters, '');
76
	}
77
78
	/**
79
	 * Returns the admin list values.
80
	 *
81
	 * @return array[] An array or arrays with the keys 'id' and 'displayName'
82
	 */
83
	private function getAdminListValues(): array {
84
		$adminGroup = $this->groupManager->get('admin');
85
		$users = $adminGroup->getUsers();
86
87
		$users = array_map(function(IUser $user) {
88
			return [
89
				'id' => $user->getUID(),
90
				'displayName' => $user->getDisplayName()
91
			];
92
		}, $users);
93
94
		usort($your_data, function(array $a, array $b) {
95
			return strcmp($a['displayName'], $b['displayName']);
96
		});
97
98
		return $users;
99
	}
100
101
	/**
102
	 * Returns the server info section id.
103
	 *
104
	 * @return string
105
	 */
106
	public function getSection(): string {
107
		return 'theming';
108
	}
109
110
	/**
111
	 * Returns the server info settings priority.
112
	 *
113
	 * @return int whether the form should be rather on the top or bottom of
114
	 * the admin section. The forms are arranged in ascending order of the
115
	 * priority values. It is required to return a value between 0 and 100.
116
	 */
117
	public function getPriority(): int {
118
		return 10;
119
	}
120
121
}
122