1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nextcloud - namespace OCA\Nextnote |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
6
|
|
|
* @license GNU AGPL version 3 or any later version |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
11
|
|
|
* License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OCA\NextNote\Controller; |
24
|
|
|
|
25
|
|
|
use OCP\IL10N; |
26
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
27
|
|
|
use OCP\AppFramework\ApiController; |
28
|
|
|
use OCP\IRequest; |
29
|
|
|
use OCA\NextNote\Service\SettingsService; |
30
|
|
|
|
31
|
|
|
class SettingsController extends ApiController { |
32
|
|
|
private $userId; |
33
|
|
|
private $settings; |
34
|
|
|
|
35
|
|
|
public function __construct( |
36
|
|
|
$AppName, |
37
|
|
|
IRequest $request, |
38
|
|
|
$userId, |
39
|
|
|
SettingsService $settings, |
40
|
|
|
IL10N $l) { |
41
|
|
|
parent::__construct( |
42
|
|
|
$AppName, |
43
|
|
|
$request, |
44
|
|
|
'GET, POST, DELETE, PUT, PATCH, OPTIONS', |
45
|
|
|
'Authorization, Content-Type, Accept', |
46
|
|
|
86400); |
47
|
|
|
$this->settings = $settings; |
48
|
|
|
$this->l = $l; |
49
|
|
|
$this->userId = $userId; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get all settings |
55
|
|
|
* |
56
|
|
|
* @NoAdminRequired |
57
|
|
|
* @NoCSRFRequired |
58
|
|
|
*/ |
59
|
|
|
public function getSettings() { |
60
|
|
|
$settings = $this->settings->getAppSettings(); |
61
|
|
|
return new JSONResponse($settings); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Save a user setting |
66
|
|
|
* |
67
|
|
|
* @NoAdminRequired |
68
|
|
|
* @NoCSRFRequired |
69
|
|
|
*/ |
70
|
|
|
public function saveUserSetting($key, $value) { |
71
|
|
|
$this->settings->setUserSetting($key, $value); |
72
|
|
|
return new JSONResponse($this->settings->getSettings()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Save a app setting |
78
|
|
|
* |
79
|
|
|
* @NoCSRFRequired |
80
|
|
|
*/ |
81
|
|
|
public function saveAdminSetting($field, $value) { |
82
|
|
|
$this->settings->setAppSetting($field, $value); |
83
|
|
|
return new JSONResponse('OK'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |