1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
4
|
|
|
* |
5
|
|
|
* @author Joas Schilling <[email protected]> |
6
|
|
|
* @author Roeland Jago Douma <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @license AGPL-3.0 |
9
|
|
|
* |
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
12
|
|
|
* as published by the Free Software Foundation. |
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, version 3, |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\Activity; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
use OCP\Activity\IFilter; |
28
|
|
|
use OCP\Activity\IManager; |
29
|
|
|
use OCP\IConfig; |
30
|
|
|
use OCP\IL10N; |
31
|
|
|
use OCP\IURLGenerator; |
32
|
|
|
use OCP\Template; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class Navigation |
36
|
|
|
* |
37
|
|
|
* @package OCA\Activity |
38
|
|
|
*/ |
39
|
|
|
class Navigation { |
40
|
|
|
/** @var IL10N */ |
41
|
|
|
protected $l; |
42
|
|
|
|
43
|
|
|
/** @var IManager */ |
44
|
|
|
protected $activityManager; |
45
|
|
|
|
46
|
|
|
/** @var IURLGenerator */ |
47
|
|
|
protected $URLGenerator; |
48
|
|
|
|
49
|
|
|
/** @var IConfig */ |
50
|
|
|
protected $config; |
51
|
|
|
|
52
|
|
|
/** @var CurrentUser */ |
53
|
|
|
protected $currentUser; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Construct |
57
|
|
|
* |
58
|
|
|
* @param IL10N $l |
59
|
|
|
* @param IManager $manager |
60
|
|
|
* @param IURLGenerator $URLGenerator |
61
|
|
|
* @param IConfig $config |
62
|
|
|
* @param CurrentUser $currentUser |
63
|
|
|
*/ |
64
|
3 |
|
public function __construct(IL10N $l, |
65
|
|
|
IManager $manager, |
66
|
|
|
IURLGenerator $URLGenerator, |
67
|
|
|
IConfig $config, |
68
|
|
|
CurrentUser $currentUser) { |
69
|
3 |
|
$this->l = $l; |
70
|
3 |
|
$this->activityManager = $manager; |
71
|
3 |
|
$this->URLGenerator = $URLGenerator; |
72
|
3 |
|
$this->config = $config; |
73
|
3 |
|
$this->currentUser = $currentUser; |
74
|
3 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the users we want to send an email to |
78
|
|
|
* |
79
|
|
|
* @param null|string $forceActive Navigation entry that should be marked as active |
80
|
|
|
* @return \OCP\Template |
81
|
|
|
*/ |
82
|
|
|
public function getTemplate($forceActive = 'all') { |
83
|
|
|
$active = $forceActive ?: 'all'; |
84
|
|
|
|
85
|
|
|
$template = new Template('activity', 'stream.app.navigation', ''); |
86
|
|
|
|
87
|
|
|
$template->assign('activeNavigation', $active); |
88
|
|
|
$template->assign('navigations', $this->getLinkList()); |
89
|
|
|
$template->assign('rssLink', $this->getRSSLink()); |
90
|
|
|
|
91
|
|
|
return $template; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
protected function getRSSLink() { |
98
|
|
|
$rssToken = $this->config->getUserValue($this->currentUser->getUID(), 'activity', 'rsstoken'); |
99
|
|
|
if ($rssToken) { |
100
|
|
|
return $this->URLGenerator->linkToRouteAbsolute('activity.Feed.show', array('token' => $rssToken)); |
101
|
|
|
} else { |
102
|
|
|
return ''; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Get all items for the users we want to send an email to |
108
|
|
|
* |
109
|
|
|
* @return array Notification data (user => array of rows from the table) |
110
|
|
|
*/ |
111
|
|
|
public function getLinkList() { |
112
|
|
|
$filters = $this->activityManager->getFilters(); |
113
|
|
View Code Duplication |
usort($filters, function(IFilter $a, IFilter $b) { |
|
|
|
|
114
|
|
|
if ($a->getPriority() === $b->getPriority()) { |
115
|
|
|
return $a->getIdentifier() > $b->getIdentifier(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $a->getPriority() > $b->getPriority(); |
119
|
|
|
}); |
120
|
|
|
|
121
|
|
|
$entries = []; |
122
|
|
|
foreach ($filters as $filter) { |
123
|
|
|
$entries[] = [ |
124
|
|
|
'id' => $filter->getIdentifier(), |
125
|
|
|
'icon' => $filter->getIcon(), |
126
|
|
|
'name' => $filter->getName(), |
127
|
|
|
'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => $filter->getIdentifier())), |
128
|
|
|
]; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return $entries; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.