1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nextcloud - 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\Service; |
25
|
|
|
|
26
|
|
|
use OCP\IConfig; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
class SettingsService { |
30
|
|
|
|
31
|
|
|
private $userId; |
32
|
|
|
private $config; |
33
|
|
|
private $appName; |
34
|
|
|
public $settings; |
35
|
|
|
|
36
|
|
|
private $numeric_settings = array( |
37
|
|
|
'link_sharing_enabled', |
38
|
|
|
|
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
public function __construct($UserId, IConfig $config, $AppName) { |
42
|
|
|
$this->userId = $UserId; |
43
|
|
|
$this->config = $config; |
44
|
|
|
$this->appName = $AppName; |
45
|
|
|
$this->settings = array( |
46
|
|
|
'folder' => $this->config->getAppValue('nextnote', 'folder', ''), |
47
|
|
|
'sharemode' => $this->config->getAppValue('nextnote', 'sharemode', 'merge'), |
48
|
|
|
|
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get all app settings |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public function getAppSettings() { |
58
|
|
|
return $this->settings; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get a app setting |
63
|
|
|
* |
64
|
|
|
* @param $key string |
65
|
|
|
* @param null $default_value The default value if key does not exist |
66
|
|
|
* @return mixed |
67
|
|
|
*/ |
68
|
|
|
public function getAppSetting($key, $default_value = null) { |
69
|
|
|
$value = ($this->settings[$key]) ? $this->settings[$key] : $this->config->getAppValue('nextnote', $key, $default_value); |
70
|
|
|
if (in_array($key, $this->numeric_settings)) { |
71
|
|
|
$value = intval($value); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $value; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Set a app setting |
79
|
|
|
* |
80
|
|
|
* @param $key string Setting name |
81
|
|
|
* @param $value mixed Value of the setting |
82
|
|
|
*/ |
83
|
|
|
public function setAppSetting($key, $value) { |
84
|
|
|
$this->settings[$key] = $value; |
85
|
|
|
$this->config->setAppValue('nextnote', $key, $value); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Set a user setting |
90
|
|
|
* |
91
|
|
|
* @param $key string Setting name |
92
|
|
|
* @param $value mixed Value of the setting |
93
|
|
|
*/ |
94
|
|
|
|
95
|
|
|
public function setUserSetting($key, $value) { |
96
|
|
|
return $this->config->setUserValue($this->userId, $this->appName, $key, $value); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Check if an setting is enabled (value of 1) |
101
|
|
|
* |
102
|
|
|
* @param $setting |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
|
|
public function isEnabled($setting) { |
106
|
|
|
$value = intval($this->getAppSetting($setting, false)); |
107
|
|
|
return ($value === 1); |
108
|
|
|
} |
109
|
|
|
} |