|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Viktar Dubiniuk <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH |
|
6
|
|
|
* @license AGPL-3.0 |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\FederatedFileSharing\Ocm\Notification; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class AbstractNotification |
|
26
|
|
|
* |
|
27
|
|
|
* @package OCA\FederatedFileSharing\Ocm\Notification |
|
28
|
|
|
*/ |
|
29
|
|
|
abstract class Notification { |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string Specifies to which shared resource the notification belong to |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $providerId; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string Resource-specific type of the notification. |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $notificationType; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var string[] Payload of the notification |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $notificationData = []; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get all available notification types for this resource type |
|
48
|
|
|
* |
|
49
|
|
|
* @return string[] |
|
50
|
|
|
*/ |
|
51
|
|
|
abstract public function getNotificationTypes(); |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
abstract public function getResourceType(); |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getProviderId() { |
|
62
|
|
|
return $this->providerId; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $providerId |
|
67
|
|
|
* |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setProviderId($providerId) { |
|
71
|
|
|
$this->providerId = $providerId; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Check if notification is supported |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $type |
|
78
|
|
|
* |
|
79
|
|
|
* @return bool |
|
80
|
|
|
*/ |
|
81
|
|
|
public function isValidNotificationType($type) { |
|
82
|
|
|
return \in_array($type, $this->getNotificationTypes()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param string $field |
|
87
|
|
|
* @param mixed $value |
|
88
|
|
|
* |
|
89
|
|
|
* @return void |
|
90
|
|
|
*/ |
|
91
|
|
|
public function addNotificationData($field, $value) { |
|
92
|
|
|
$this->notificationData[$field] = $value; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Prepare notification |
|
97
|
|
|
* |
|
98
|
|
|
* @return array |
|
99
|
|
|
*/ |
|
100
|
|
|
public function toArray() { |
|
101
|
|
|
return [ |
|
102
|
|
|
'notificationType' => $this->notificationType, |
|
103
|
|
|
'resourceType' => $this->getResourceType(), |
|
104
|
|
|
'providerId' => $this->providerId, |
|
105
|
|
|
'notification' => $this->notificationData |
|
106
|
|
|
]; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|