1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud - Tasks |
4
|
|
|
* |
5
|
|
|
* @author Raimund Schlüßler |
6
|
|
|
* @copyright 2015 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
|
|
|
private $userId; |
31
|
|
|
private $l10n; |
32
|
|
|
private $settings; |
33
|
|
|
private $appName; |
34
|
|
|
|
35
|
|
|
public function __construct($userId, IL10N $l10n, IConfig $settings, $appName) { |
36
|
|
|
$this->userId = $userId; |
37
|
|
|
$this->l10n = $l10n; |
38
|
|
|
$this->settings = $settings; |
39
|
|
|
$this->appName = $appName; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* get all collections |
44
|
|
|
* |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function getAll() { |
48
|
|
|
$collections = array( |
49
|
|
|
array( |
50
|
|
|
'id' => "starred", |
51
|
|
|
'displayname' => (string)$this->l10n->t('Important'), |
52
|
|
|
'show' => 2), |
53
|
|
|
array( |
54
|
|
|
'id' => "today", |
55
|
|
|
'displayname' => (string)$this->l10n->t('Today'), |
56
|
|
|
'show' => 2), |
57
|
|
|
array( |
58
|
|
|
'id' => "week", |
59
|
|
|
'displayname' => (string)$this->l10n->t('Week'), |
60
|
|
|
'show' => 2), |
61
|
|
|
array( |
62
|
|
|
'id' => "all", |
63
|
|
|
'displayname' => (string)$this->l10n->t('All'), |
64
|
|
|
'show' => 2), |
65
|
|
|
array( |
66
|
|
|
'id' => "current", |
67
|
|
|
'displayname' => (string)$this->l10n->t('Current'), |
68
|
|
|
'show' => 2), |
69
|
|
|
array( |
70
|
|
|
'id' => "completed", |
71
|
|
|
'displayname' => (string)$this->l10n->t('Completed'), |
72
|
|
|
'show' => 2) |
73
|
|
|
); |
74
|
|
|
foreach ($collections as $key => $collection){ |
75
|
|
|
$tmp = $this->settings->getUserValue($this->userId, $this->appName,'show_'.$collection['id']); |
76
|
|
|
if (!in_array($tmp, array('0','1','2'))) { |
77
|
|
|
$this->settings->setUserValue($this->userId, $this->appName,'show_'.$collection['id'],$collections[$key]['show']); |
78
|
|
|
} else { |
79
|
|
|
$collections[$key]['show'] = (int)$tmp; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
return $collections; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* set the visibility of a collection by collectionID |
87
|
|
|
* |
88
|
|
|
* @param int $collectionID |
89
|
|
|
* @param int $visibility |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
|
|
public function setVisibility($collectionID, $visibility){ |
93
|
|
|
if (in_array($visibility, array(0,1,2))){ |
94
|
|
|
$this->settings->setUserValue($this->userId, $this->appName,'show_'.$collectionID,$visibility); |
95
|
|
|
} |
96
|
|
|
return true; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|