1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nextcloud - Tasks |
4
|
|
|
* |
5
|
|
|
* @author Raimund Schlüßler |
6
|
|
|
* @copyright 2018 Raimund Schlüßler <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 3 of the License, or any later version. |
12
|
|
|
* |
13
|
|
|
* This library 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 |
19
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OCA\Tasks\Service; |
24
|
|
|
|
25
|
|
|
use OCP\App\IAppManager; |
26
|
|
|
use OCP\IConfig; |
27
|
|
|
|
28
|
|
|
class SettingsService { |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var ?string |
32
|
|
|
*/ |
33
|
|
|
private $userId; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var IConfig |
37
|
|
|
*/ |
38
|
|
|
private $config; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $appName; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var IAppManager |
47
|
|
|
*/ |
48
|
|
|
private $appManager; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $userId |
52
|
|
|
* @param IConfig $settings |
|
|
|
|
53
|
|
|
* @param string $appName |
54
|
|
|
*/ |
55
|
|
|
public function __construct(?string $userId, IConfig $config, string $appName, IAppManager $appManager) { |
56
|
|
|
$this->userId = $userId; |
57
|
|
|
$this->config = $config; |
58
|
|
|
$this->appName = $appName; |
59
|
|
|
$this->appManager = $appManager; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the current settings |
64
|
|
|
* |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function get():array { |
68
|
|
|
$defaultCalendarId = (string)$this->config->getUserValue($this->userId, $this->appName, 'various_defaultCalendarId'); |
69
|
|
|
$showHidden = (bool)$this->config->getUserValue($this->userId, $this->appName, 'various_showHidden', false); |
70
|
|
|
$sortOrder = (string)$this->config->getUserValue($this->userId, $this->appName, 'various_sortOrder', 'default'); |
71
|
|
|
$sortDirection = (bool)$this->config->getUserValue($this->userId, $this->appName, 'various_sortDirection', false); |
72
|
|
|
$allDay = (bool)$this->config->getUserValue($this->userId, $this->appName, 'various_allDay', false); |
73
|
|
|
$initialRoute = (string)$this->config->getUserValue($this->userId, $this->appName, 'various_initialRoute', '/collections/all'); |
74
|
|
|
|
75
|
|
|
$calendarEnabled = $this->appManager->isEnabledForUser('calendar'); |
76
|
|
|
$defaultInitialView = $this->config->getAppValue('calendar', 'currentView', 'dayGridMonth'); |
77
|
|
|
$calendarView = $this->getView($this->config->getUserValue($this->userId, 'calendar', 'currentView', $defaultInitialView)); |
78
|
|
|
$defaultShowTasks = $this->config->getAppValue('calendar', 'showTasks', 'yes'); |
79
|
|
|
$showTasks = $this->config->getUserValue($this->userId, 'calendar', 'showTasks', $defaultShowTasks) === 'yes'; |
80
|
|
|
|
81
|
|
|
return [ |
82
|
|
|
'defaultCalendarId' => $defaultCalendarId, |
83
|
|
|
'showHidden' => $showHidden, |
84
|
|
|
'sortOrder' => $sortOrder, |
85
|
|
|
'sortDirection' => $sortDirection, |
86
|
|
|
'allDay' => $allDay, |
87
|
|
|
'initialRoute' => $initialRoute, |
88
|
|
|
'calendarEnabled' => $calendarEnabled, |
89
|
|
|
'showTasks' => $showTasks, |
90
|
|
|
'calendarView' => $calendarView |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Set setting of type to new value |
96
|
|
|
* |
97
|
|
|
* @param $setting |
98
|
|
|
* @param $value |
99
|
|
|
* @return bool |
100
|
|
|
*/ |
101
|
|
|
public function set($setting, $value):bool { |
102
|
|
|
$this->config->setUserValue($this->userId, $this->appName, 'various_'.$setting, $value); |
103
|
|
|
return true; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Makes sure we don't use the old views anymore |
108
|
|
|
* |
109
|
|
|
* @param string $view |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
private function getView(string $view): string { |
113
|
|
|
switch ($view) { |
114
|
|
|
case 'agendaDay': |
115
|
|
|
return 'timeGridDay'; |
116
|
|
|
|
117
|
|
|
case 'agendaWeek': |
118
|
|
|
return 'timeGridWeek'; |
119
|
|
|
|
120
|
|
|
case 'month': |
121
|
|
|
return 'dayGridMonth'; |
122
|
|
|
|
123
|
|
|
default: |
124
|
|
|
return $view; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.