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\IConfig; |
26
|
|
|
use OCP\IL10N; |
27
|
|
|
|
28
|
|
|
class CollectionsService { |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $userId; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var IL10N |
37
|
|
|
*/ |
38
|
|
|
private $l10n; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var IConfig |
42
|
|
|
*/ |
43
|
|
|
private $settings; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $appName; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $userId |
52
|
|
|
* @param IL10N $l10n |
53
|
|
|
* @param IConfig $settings |
54
|
|
|
* @param string $appName |
55
|
|
|
*/ |
56
|
|
|
public function __construct(string $userId, IL10N $l10n, IConfig $settings, string $appName) { |
57
|
|
|
$this->userId = $userId; |
58
|
|
|
$this->l10n = $l10n; |
59
|
|
|
$this->settings = $settings; |
60
|
|
|
$this->appName = $appName; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get all collections |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
public function getAll():array { |
69
|
|
|
$collections = [ |
70
|
|
|
[ |
71
|
|
|
'id' => "starred", |
72
|
|
|
'displayName' => (string)$this->l10n->t('Important'), |
73
|
|
|
'show' => 2, |
74
|
|
|
'icon' => 'Star'], |
75
|
|
|
[ |
76
|
|
|
'id' => "today", |
77
|
|
|
'displayName' => (string)$this->l10n->t('Today'), |
78
|
|
|
'show' => 2, |
79
|
|
|
'icon' => 'CalendarToday'], |
80
|
|
|
[ |
81
|
|
|
'id' => "week", |
82
|
|
|
'displayName' => (string)$this->l10n->t('Week'), |
83
|
|
|
'show' => 2, |
84
|
|
|
'icon' => 'CalendarWeek'], |
85
|
|
|
[ |
86
|
|
|
'id' => "all", |
87
|
|
|
'displayName' => (string)$this->l10n->t('All'), |
88
|
|
|
'show' => 2, |
89
|
|
|
'icon' => 'CircleOutline'], |
90
|
|
|
[ |
91
|
|
|
'id' => "current", |
92
|
|
|
'displayName' => (string)$this->l10n->t('Current'), |
93
|
|
|
'show' => 2, |
94
|
|
|
'icon' => 'TrendingUp'], |
95
|
|
|
[ |
96
|
|
|
'id' => "completed", |
97
|
|
|
'displayName' => (string)$this->l10n->t('Completed'), |
98
|
|
|
'show' => 2, |
99
|
|
|
'icon' => 'Check'] |
100
|
|
|
]; |
101
|
|
|
foreach ($collections as $key => $collection) { |
102
|
|
|
$tmp = $this->settings->getUserValue($this->userId, $this->appName,'show_'.$collection['id']); |
103
|
|
|
if (!in_array($tmp, ['0','1','2'])) { |
104
|
|
|
$this->settings->setUserValue($this->userId, $this->appName,'show_'.$collection['id'],$collections[$key]['show']); |
105
|
|
|
} else { |
106
|
|
|
$collections[$key]['show'] = (int)$tmp; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
return $collections; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Set the visibility of a collection by collectionID |
114
|
|
|
* |
115
|
|
|
* @param string $collectionID |
116
|
|
|
* @param int $visibility |
117
|
|
|
* @return bool |
118
|
|
|
*/ |
119
|
|
|
public function setVisibility(string $collectionID, int $visibility):bool { |
120
|
|
|
if (in_array($visibility, [0,1,2])) { |
121
|
|
|
$this->settings->setUserValue($this->userId, $this->appName,'show_'.$collectionID,$visibility); |
122
|
|
|
} |
123
|
|
|
return true; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|