Completed
Push — master ( 46dc92...267b49 )
by Victor
13s queued 11s
created

Activity   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 222
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 25.53%

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 0
dl 0
loc 222
ccs 12
cts 47
cp 0.2553
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getL10N() 0 3 1
A getNotificationTypes() 0 9 1
A getDefaultTypes() 0 7 1
A getTypeIcon() 0 7 2
A translate() 0 14 4
A getSpecialParameterList() 0 3 1
A getGroupParameter() 0 3 1
A getNavigation() 0 16 1
A isFilterValid() 0 3 1
A filterNotificationTypes() 0 3 2
A getQueryForFilter() 0 9 2
1
<?php
2
/**
3
 * ownCloud - Files_antivirus
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Viktar Dubiniuk <[email protected]>
9
 *
10
 * @copyright Viktar Dubiniuk 2015-2018
11
 * @license AGPL-3.0
12
 */
13
14
namespace OCA\Files_Antivirus;
15
16
use OC\L10N\Factory;
17
use OCP\Activity\IExtension;
18
use OCP\IURLGenerator;
19
20
class Activity implements IExtension {
21
	
22
	const APP_NAME = 'files_antivirus';
23
24
	/**
25
	 * Filter with all app related activities
26
	 */
27
	const FILTER_AVIR = 'files_antivirus';
28
29
	/**
30
	 * Activity types known to this extension
31
	 */
32
	const TYPE_VIRUS_DETECTED = 'virus_detected';
33
34
	/**
35
	 * Subject keys for translation of the subjections
36
	 */
37
	const SUBJECT_VIRUS_DETECTED = 'virus_detected';
38
	
39
	/**
40
	 * Infected file deletion notice
41
	 */
42
	const MESSAGE_FILE_DELETED = 'file_deleted';
43
44
45
	/**
46
	 * @var Factory
47
	 */
48
	protected $languageFactory;
49
50
	/**
51
	 * @var IURLGenerator
52
	 */
53
	protected $URLGenerator;
54
55
	/**
56
	 * @param Factory $languageFactory
57
	 * @param IURLGenerator $URLGenerator
58
	 */
59 3
	public function __construct(Factory $languageFactory, IURLGenerator $URLGenerator) {
60 3
		$this->languageFactory = $languageFactory;
61 3
		$this->URLGenerator = $URLGenerator;
62 3
	}
63
64
	protected function getL10N($languageCode = null) {
65
		return $this->languageFactory->get(self::APP_NAME, $languageCode);
66
	}
67
68
	/**
69
	 * The extension can return an array of additional notification types.
70
	 * If no additional types are to be added false is to be returned
71
	 *
72
	 * @param string $languageCode
73
	 *
74
	 * @return array|false
75
	 */
76
	public function getNotificationTypes($languageCode) {
77
		$l = $this->getL10N($languageCode);
78
79
		return [
80
			self::TYPE_VIRUS_DETECTED => (string) $l->t(
81
				'<strong>Infected file</strong> has been <strong>found</strong>'
82
			),
83
		];
84
	}
85
86
	/**
87
	 * For a given method additional types to be displayed in the settings can be returned.
88
	 * In case no additional types are to be added false is to be returned.
89
	 *
90
	 * @param string $method
91
	 * @return array|false
92
	 */
93
	public function getDefaultTypes($method) {
94
		$defaultTypes = [
95
			self::TYPE_VIRUS_DETECTED,
96
		];
97
98
		return $defaultTypes;
99
	}
100
101
	/**
102
	 * A string naming the css class for the icon to be used can be returned.
103
	 * If no icon is known for the given type false is to be returned.
104
	 *
105
	 * @param string $type
106
	 * @return string|false
107
	 */
108 1
	public function getTypeIcon($type) {
109
		switch ($type) {
110 1
			case self::TYPE_VIRUS_DETECTED:
111 1
				return 'icon-info';
112
		}
113 1
		return false;
114
	}
115
116
	/**
117
	 * The extension can translate a given message to the requested languages.
118
	 * If no translation is available false is to be returned.
119
	 *
120
	 * @param string $app
121
	 * @param string $text
122
	 * @param array $params
123
	 * @param boolean $stripPath
124
	 * @param boolean $highlightParams
125
	 * @param string $languageCode
126
	 *
127
	 * @return string|false
128
	 */
129
	public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
130
		$l = $this->getL10N($languageCode);
131
132
		if ($app === self::APP_NAME) {
133
			switch ($text) {
134
				case self::SUBJECT_VIRUS_DETECTED:
135
					return (string) $l->t('File %s is infected with %s', $params);
136
				case self::MESSAGE_FILE_DELETED:
137
					return (string) $l->t('It is going to be deleted', $params);
138
			}
139
		}
140
141
		return false;
142
	}
143
144
	/**
145
	 * The extension can define the type of parameters for translation
146
	 *
147
	 * Currently known types are:
148
	 * * file		=> will strip away the path of the file and add a tooltip with it
149
	 * * username	=> will add the avatar of the user
150
	 *
151
	 * @param string $app
152
	 * @param string $text
153
	 *
154
	 * @return array|false
155
	 */
156 1
	public function getSpecialParameterList($app, $text) {
157 1
		return false;
158
	}
159
160
	/**
161
	 * The extension can define the parameter grouping by returning the index as integer.
162
	 * In case no grouping is required false is to be returned.
163
	 *
164
	 * @param array $activity
165
	 *
166
	 * @return integer|false
167
	 */
168 1
	public function getGroupParameter($activity) {
169 1
		return false;
170
	}
171
172
	/**
173
	 * The extension can define additional navigation entries. The array returned has to contain two keys 'top'
174
	 * and 'apps' which hold arrays with the relevant entries.
175
	 * If no further entries are to be added false is no be returned.
176
	 *
177
	 * @return array|false
178
	 */
179
	public function getNavigation() {
180
		$l = $this->getL10N();
181
		return [
182
			'apps' => [
183
				self::FILTER_AVIR => [
184
					'id' => self::FILTER_AVIR,
185
					'name' => (string) $l->t('Antivirus'),
186
					'url' => $this->URLGenerator->linkToRoute(
187
						'activity.Activities.showList',
188
						['filter' => self::FILTER_AVIR]
189
					),
190
				],
191
			],
192
			'top' => []
193
		];
194
	}
195
196
	/**
197
	 * The extension can check if a customer filter (given by
198
	 * a query string like filter=abc) is valid or not.
199
	 *
200
	 * @param string $filterValue
201
	 *
202
	 * @return boolean
203
	 */
204
	public function isFilterValid($filterValue) {
205
		return $filterValue === self::FILTER_AVIR;
206
	}
207
208
	/**
209
	 * The extension can filter the types based on the filter if required.
210
	 * In case no filter is to be applied false is to be returned unchanged.
211
	 *
212
	 * @param array $types
213
	 * @param string $filter
214
	 *
215
	 * @return array|false
216
	 */
217
	public function filterNotificationTypes($types, $filter) {
218
		return $filter === self::FILTER_AVIR ? [self::TYPE_VIRUS_DETECTED] : $types;
219
	}
220
221
	/**
222
	 * For a given filter the extension can specify the sql query conditions
223
	 * including parameters for that query.
224
	 * In case the extension does not know the filter false is to be returned.
225
	 * The query condition and the parameters are to be returned as array with two elements.
226
	 * E.g. return ['`app` = ? and `message` like ?', array('mail', 'ownCloud%')];
227
	 *
228
	 * @param string $filter
229
	 *
230
	 * @return array|false
231
	 */
232
	public function getQueryForFilter($filter) {
233
		if ($filter === self::FILTER_AVIR) {
234
			return [
235
				'(`app` = ?)',
236
				[self::APP_NAME],
237
			];
238
		}
239
		return false;
240
	}
241
}
242