1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Data Analytics |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the LICENSE.md file. |
7
|
|
|
* |
8
|
|
|
* @author Marcel Scherello <[email protected]> |
9
|
|
|
* @copyright 2019 Marcel Scherello |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Analytics\Activity; |
13
|
|
|
|
14
|
|
|
use InvalidArgumentException; |
15
|
|
|
use OCP\Activity\IEvent; |
16
|
|
|
use OCP\Activity\IProvider; |
17
|
|
|
use OCP\IL10N; |
18
|
|
|
use OCP\IURLGenerator; |
19
|
|
|
|
20
|
|
|
class Provider implements IProvider |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
private $l10n; |
24
|
|
|
private $userId; |
25
|
|
|
private $urlGenerator; |
26
|
|
|
|
27
|
|
|
public function __construct(IURLGenerator $urlGenerator, |
28
|
|
|
IL10N $l10n, |
29
|
|
|
$userId) |
30
|
|
|
{ |
31
|
|
|
$this->userId = $userId; |
32
|
|
|
$this->urlGenerator = $urlGenerator; |
33
|
|
|
$this->l10n = $l10n; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $language |
38
|
|
|
* @param IEvent $event |
39
|
|
|
* @param IEvent|null $previousEvent |
40
|
|
|
* @return IEvent |
41
|
|
|
* @throws InvalidArgumentException |
42
|
|
|
* @since 11.0.0 |
43
|
|
|
*/ |
44
|
|
|
public function parse($language, IEvent $event, IEvent $previousEvent = null) |
45
|
|
|
{ |
46
|
|
|
if ($event->getApp() !== 'analytics') { |
47
|
|
|
throw new InvalidArgumentException(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$parsedSubject = ''; |
51
|
|
|
$ownActivity = ($event->getAuthor() === $this->userId); |
52
|
|
|
|
53
|
|
|
switch ($event->getSubject()) { |
54
|
|
|
case ActivityManager::SUBJECT_DATASET_ADD: |
55
|
|
|
$parsedSubject = $this->l10n->t('You created a new report'); |
56
|
|
|
break; |
57
|
|
|
case ActivityManager::SUBJECT_DATASET_DELETE: |
58
|
|
|
$parsedSubject = $this->l10n->t('You deleted report {report}'); |
59
|
|
|
break; |
60
|
|
|
case ActivityManager::SUBJECT_DATASET_SHARE: |
61
|
|
|
if ($ownActivity) { |
62
|
|
|
$parsedSubject = $this->l10n->t('You shared report {report}'); |
63
|
|
|
} else { |
64
|
|
|
$parsedSubject = $event->getSubjectParameters()['author'] . $this->l10n->t(' shared report {report} with you'); |
65
|
|
|
} |
66
|
|
|
break; |
67
|
|
|
case ActivityManager::SUBJECT_DATA_ADD: |
68
|
|
|
if ($ownActivity) { |
69
|
|
|
$parsedSubject = $this->l10n->t('You have added new data to report {report}'); |
70
|
|
|
} else { |
71
|
|
|
$parsedSubject = $event->getSubjectParameters()['author'] . $this->l10n->t(' has added new data to report {report}'); |
72
|
|
|
} |
73
|
|
|
break; |
74
|
|
|
case ActivityManager::SUBJECT_DATA_ADD_API: |
75
|
|
|
$parsedSubject = $this->l10n->t('New data was add via API to report {report}'); |
76
|
|
|
break; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$event->setRichSubject( |
80
|
|
|
$parsedSubject, |
81
|
|
|
['report' => [ |
82
|
|
|
'type' => 'highlight', |
83
|
|
|
'id' => $event->getObjectId(), |
84
|
|
|
'name' => basename($event->getObjectName()), |
85
|
|
|
'link' => $this->Url($event->getObjectId()), |
86
|
|
|
]] |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$event->setParsedSubject($parsedSubject) |
90
|
|
|
->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('analytics', 'app-dark.svg'))); |
91
|
|
|
return $event; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function Url($endpoint) |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
return $this->urlGenerator->linkToRouteAbsolute('analytics.page.index'); |
97
|
|
|
} |
98
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.