Completed
Pull Request — master (#841)
by Blizzz
10:54 queued 01:57
created

Admin::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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