Completed
Push — master ( dfbc21...f148e3 )
by John
64:33 queued 45:49
created

Personal::getForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2018 John Molakvoæ <[email protected]>
4
 *
5
 * @author John Molakvoæ <[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
namespace OCA\Accessibility\Settings;
25
26
use OCA\Accessibility\AccessibilityProvider;
27
use OCP\AppFramework\Http\TemplateResponse;
28
use OCP\IConfig;
29
use OCP\IL10N;
30
use OCP\IURLGenerator;
31
use OCP\IUserSession;
32
use OCP\Settings\ISettings;
33
34
class Personal implements ISettings {
35
36
	/** @var string */
37
	protected $appName;
38
39
	/** @var IConfig */
40
	private $config;
41
42
	/** @var IUserSession */
43
	private $userSession;
44
45
	/** @var IL10N */
46
	private $l;
47
48
	/** @var IURLGenerator */
49
	private $urlGenerator;
50
51
	/** @var AccessibilityProvider */
52
	private $accessibilityProvider;
53
54
	/**
55
	 * Settings constructor.
56
	 *
57
	 * @param string $appName
58
	 * @param IConfig $config
59
	 * @param IUserSession $userSession
60
	 * @param IL10N $l
61
	 * @param IURLGenerator $urlGenerator
62
	 * @param AccessibilityProvider $accessibilityProvider
63
	 */
64
	public function __construct(string $appName,
65
								IConfig $config,
66
								IUserSession $userSession,
67
								IL10N $l,
68
								IURLGenerator $urlGenerator,
69
								AccessibilityProvider $accessibilityProvider) {
70
		$this->appName               = $appName;
71
		$this->config                = $config;
72
		$this->userSession           = $userSession;
73
		$this->l                     = $l;
74
		$this->urlGenerator          = $urlGenerator;
75
		$this->accessibilityProvider = $accessibilityProvider;
76
	}
77
78
	/**
79
	 * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
80
	 * @since 9.1
81
	 */
82
	public function getForm() {
83
84
		$serverData = [
85
			'themes' => $this->accessibilityProvider->getThemes(),
86
			'fonts'  => $this->accessibilityProvider->getFonts(),
87
			'theme'  => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false),
88
			'font'   => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false)
89
		];
90
91
		return new TemplateResponse($this->appName, 'settings-personal', ['serverData' => $serverData]);
92
	}
93
94
	/**
95
	 * @return string the section ID, e.g. 'sharing'
96
	 * @since 9.1
97
	 */
98
	public function getSection() {
99
		return $this->appName;
100
	}
101
102
	/**
103
	 * @return int whether the form should be rather on the top or bottom of
104
	 * the admin section. The forms are arranged in ascending order of the
105
	 * priority values. It is required to return a value between 0 and 100.
106
	 *
107
	 * E.g.: 70
108
	 * @since 9.1
109
	 */
110
	public function getPriority() {
111
		return 40;
112
	}
113
}
114