Completed
Push — master ( 64c085...273428 )
by Sander
16s queued 13s
created

SettingsController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 56
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
A getSettings() 0 4 1
A saveUserSetting() 0 4 1
A saveAdminSetting() 0 4 1
1
<?php
2
/**
3
 * Nextcloud - namespace OCA\Nextnote
4
 *
5
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
6
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
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\NextNote\Controller;
25
26
use OCP\IL10N;
27
use OCP\Settings\ISettings;
28
use OCP\AppFramework\Http\TemplateResponse;
29
use OCP\AppFramework\Http\JSONResponse;
30
use OCP\AppFramework\ApiController;
31
use OCP\IRequest;
32
use OCA\NextNote\Service\SettingsService;
33
34
class SettingsController extends ApiController {
35
	private $userId;
36
	private $settings;
37
38
	public function __construct(
39
		$AppName,
40
		IRequest $request,
41
		$userId,
42
		SettingsService $settings,
43
		IL10N $l) {
44
		parent::__construct(
45
			$AppName,
46
			$request,
47
			'GET, POST, DELETE, PUT, PATCH, OPTIONS',
48
			'Authorization, Content-Type, Accept',
49
			86400);
50
		$this->settings = $settings;
51
		$this->l = $l;
52
		$this->userId = $userId;
53
	}
54
55
56
	/**
57
	 * Get all settings
58
	 *
59
	 * @NoAdminRequired
60
	 * @NoCSRFRequired
61
	 */
62
	public function getSettings() {
63
		$settings = $this->settings->getAppSettings();
64
		return new JSONResponse($settings);
65
	}
66
67
	/**
68
	 * Save a user setting
69
	 *
70
	 * @NoAdminRequired
71
	 * @NoCSRFRequired
72
	 */
73
	public function saveUserSetting($key, $value) {
74
		$this->settings->setUserSetting($key, $value);
75
		return new JSONResponse('OK');
76
	}
77
78
79
	/**
80
	 * Save a app setting
81
	 *
82
	 * @NoCSRFRequired
83
	 */
84
	public function saveAdminSetting($field, $value) {
85
		$this->settings->setAppSetting($field, $value);
86
		return new JSONResponse('OK');
87
	}
88
89
}