Navigation   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 107
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 2
A getTemplate() 0 18 3
A getLinkList() 0 28 1
1
<?php
2
/**
3
 * @author Joas Schilling <[email protected]>
4
 * @author Roeland Jago Douma <[email protected]>
5
 *
6
 * @copyright Copyright (c) 2016, ownCloud, Inc.
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program 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 License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OCA\Activity;
24
25
use OCP\Activity\IManager;
26
use OCP\IL10N;
27
use OCP\IURLGenerator;
28
use OCP\Template;
29
30
/**
31
 * Class Navigation
32
 *
33
 * @package OCA\Activity
34
 */
35
class Navigation {
36
	/** @var IL10N */
37
	protected $l;
38
39
	/** @var IManager */
40
	protected $activityManager;
41
42
	/** @var IURLGenerator */
43
	protected $URLGenerator;
44
45
	/** @var string */
46
	protected $active;
47
48
	/** @var string */
49
	protected $user;
50
51
	/** @var string */
52
	protected $rssLink;
53
54
	/**
55
	 * Construct
56
	 *
57
	 * @param IL10N $l
58
	 * @param IManager $manager
59
	 * @param IURLGenerator $URLGenerator
60
	 * @param string $user
61
	 * @param string $rssToken
62
	 * @param null|string $active Navigation entry that should be marked as active
63
	 */
64 6
	public function __construct(IL10N $l,
65
								IManager $manager,
66
								IURLGenerator $URLGenerator,
67
								$user,
68
								$rssToken,
69
								$active = 'all') {
70 6
		$this->l = $l;
71 6
		$this->activityManager = $manager;
72 6
		$this->URLGenerator = $URLGenerator;
73 6
		$this->user = $user;
74 6
		$this->active = $active;
75
76 6
		if ($rssToken) {
77 1
			$this->rssLink = $this->URLGenerator->linkToRouteAbsolute('activity.Feed.show', ['token' => $rssToken]);
78
		} else {
79 5
			$this->rssLink = '';
80
		}
81 6
	}
82
83
	/**
84
	 * Get the users we want to send an email to
85
	 *
86
	 * @param null|string $forceActive Navigation entry that should be marked as active
87
	 * @return \OCP\Template
88
	 */
89 4
	public function getTemplate($forceActive = null) {
90 4
		$active = $forceActive ?: $this->active;
91
92 4
		$template = new Template('activity', 'stream.app.navigation', '');
93 4
		$entries = $this->getLinkList();
94
95 4
		if (\sizeof($entries['apps']) === 1) {
96
			// If there is only the files app, we simply do not show it,
97
			// as it is the same as the 'all' filter.
98 4
			$entries['apps'] = [];
99
		}
100
101 4
		$template->assign('activeNavigation', $active);
102 4
		$template->assign('navigations', $entries);
103 4
		$template->assign('rssLink', $this->rssLink);
104
105 4
		return $template;
106
	}
107
108
	/**
109
	 * Get all items for the users we want to send an email to
110
	 *
111
	 * @return array Notification data (user => array of rows from the table)
112
	 */
113 4
	public function getLinkList() {
114
		$topEntries = [
115
			[
116 4
				'id' => 'all',
117 4
				'name' => (string) $this->l->t('All Activities'),
118 4
				'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList'),
119
			],
120
		];
121
122 4
		$topEntries[] = [
123 4
			'id' => 'self',
124 4
			'name' => (string) $this->l->t('Activities by you'),
125 4
			'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', ['filter' => 'self']),
126
		];
127 4
		$topEntries[] = [
128 4
			'id' => 'by',
129 4
			'name' => (string) $this->l->t('Activities by others'),
130 4
			'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', ['filter' => 'by']),
131
		];
132
133 4
		$additionalEntries = $this->activityManager->getNavigation();
134 4
		$topEntries = \array_merge($topEntries, $additionalEntries['top']);
135
136
		return [
137 4
			'top'		=> $topEntries,
138 4
			'apps'		=> $additionalEntries['apps'],
139
		];
140
	}
141
}
142