Completed
Push — master ( 618c55...e17b77 )
by
unknown
02:42
created

Navigation::getLinkList()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

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