Completed
Push — master ( 63adda...00bb92 )
by Lukas
09:13
created

Admin::getPriority()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Arthur Schiwon <[email protected]>
4
 *
5
 * @author Arthur Schiwon <[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\Theming\Settings;
25
26
use OCA\Theming\ThemingDefaults;
27
use OCP\AppFramework\Http\TemplateResponse;
28
use OCP\IConfig;
29
use OCP\IL10N;
30
use OCP\IURLGenerator;
31
use OCP\Settings\ISettings;
32
33
class Admin implements ISettings {
34
	/** @var IConfig */
35
	private $config;
36
	/** @var IL10N */
37
	private $l;
38
	/** @var ThemingDefaults */
39
	private $themingDefaults;
40
	/** @var IURLGenerator */
41
	private $urlGenerator;
42
43
	public function __construct(IConfig $config,
44
								IL10N $l,
45
								ThemingDefaults $themingDefaults,
46
								IURLGenerator $urlGenerator) {
47
		$this->config = $config;
48
		$this->l = $l;
49
		$this->themingDefaults = $themingDefaults;
50
		$this->urlGenerator = $urlGenerator;
51
	}
52
53
	/**
54
	 * @return TemplateResponse
55
	 */
56
	public function getForm() {
57
		$path = $this->urlGenerator->linkToRoute('theming.Theming.updateLogo');
58
59
		$themable = true;
60
		$errorMessage = '';
61
		$theme = $this->config->getSystemValue('theme', '');
62
		if ($theme !== '') {
63
			$themable = false;
64
			$errorMessage = $this->l->t('You already use a custom theme');
65
		}
66
67
		$parameters = [
68
			'themable'        => $themable,
69
			'errorMessage'    => $errorMessage,
70
			'name'            => $this->themingDefaults->getEntity(),
71
			'url'             => $this->themingDefaults->getBaseUrl(),
72
			'slogan'          => $this->themingDefaults->getSlogan(),
73
			'color'           => $this->themingDefaults->getMailHeaderColor(),
74
			'logo'            => $this->themingDefaults->getLogo(),
75
			'logoMime'        => $this->config->getAppValue('theming', 'logoMime', ''),
76
			'background'      => $this->themingDefaults->getBackground(),
77
			'backgroundMime'  => $this->config->getAppValue('theming', 'backgroundMime', ''),
78
			'uploadLogoRoute' => $path,
79
		];
80
81
		return new TemplateResponse('theming', 'settings-admin', $parameters, '');
82
	}
83
84
	/**
85
	 * @return string the section ID, e.g. 'sharing'
86
	 */
87
	public function getSection() {
88
		return 'theming';
89
	}
90
91
	/**
92
	 * @return int whether the form should be rather on the top or bottom of
93
	 * the admin section. The forms are arranged in ascending order of the
94
	 * priority values. It is required to return a value between 0 and 100.
95
	 *
96
	 * E.g.: 70
97
	 */
98
	public function getPriority() {
99
		return 5;
100
	}
101
102
}
103