1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Circles - Bring cloud-users closer together. |
8
|
|
|
* |
9
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
10
|
|
|
* later. See the COPYING file. |
11
|
|
|
* |
12
|
|
|
* @author Maxence Lange <[email protected]> |
13
|
|
|
* @copyright 2021 |
14
|
|
|
* @license GNU AGPL version 3 or any later version |
15
|
|
|
* |
16
|
|
|
* This program is free software: you can redistribute it and/or modify |
17
|
|
|
* it under the terms of the GNU Affero General Public License as |
18
|
|
|
* published by the Free Software Foundation, either version 3 of the |
19
|
|
|
* License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU Affero General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU Affero General Public License |
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
namespace OCA\Circles\Model\Federated; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
use daita\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; |
36
|
|
|
use daita\MySmallPhpTools\IDeserializable; |
37
|
|
|
use daita\MySmallPhpTools\Model\SimpleDataStore; |
38
|
|
|
use daita\MySmallPhpTools\Traits\TArrayTools; |
39
|
|
|
use JsonSerializable; |
40
|
|
|
use OCA\Circles\IFederatedModel; |
41
|
|
|
use OCA\Circles\Model\ManagedModel; |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Class FederatedShare |
46
|
|
|
* |
47
|
|
|
* @package OCA\Circles\Model\Federated |
48
|
|
|
*/ |
49
|
|
|
class FederatedShare extends ManagedModel implements IFederatedModel, JsonSerializable, INC22QueryRow, IDeserializable { |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
use TArrayTools; |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** @var int */ |
56
|
|
|
private $id = 0; |
57
|
|
|
|
58
|
|
|
/** @var string */ |
59
|
|
|
private $itemId = ''; |
60
|
|
|
|
61
|
|
|
/** @var string */ |
62
|
|
|
private $circleId = ''; |
63
|
|
|
|
64
|
|
|
/** @var string */ |
65
|
|
|
private $instance = ''; |
66
|
|
|
|
67
|
|
|
/** @var string */ |
68
|
|
|
private $lockStatus = ''; |
69
|
|
|
|
70
|
|
|
/** @var SimpleDataStore */ |
71
|
|
|
private $data; |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* FederatedShare constructor. |
76
|
|
|
*/ |
77
|
|
|
function __construct() { |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param int $id |
83
|
|
|
* |
84
|
|
|
* @return FederatedShare |
85
|
|
|
*/ |
86
|
|
|
public function setId(int $id): self { |
87
|
|
|
$this->id = $id; |
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return int |
94
|
|
|
*/ |
95
|
|
|
public function getId(): int { |
96
|
|
|
return $this->id; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $itemId |
102
|
|
|
* |
103
|
|
|
* @return FederatedShare |
104
|
|
|
*/ |
105
|
|
|
public function setItemId(string $itemId): self { |
106
|
|
|
$this->itemId = $itemId; |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function getItemId(): string { |
115
|
|
|
return $this->itemId; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param string $circleId |
121
|
|
|
* |
122
|
|
|
* @return FederatedShare |
123
|
|
|
*/ |
124
|
|
|
public function setCircleId(string $circleId): self { |
125
|
|
|
$this->circleId = $circleId; |
126
|
|
|
|
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getCircleId(): string { |
134
|
|
|
return $this->circleId; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param string $instance |
140
|
|
|
* |
141
|
|
|
* @return FederatedShare |
142
|
|
|
*/ |
143
|
|
|
public function setInstance(string $instance): self { |
144
|
|
|
$this->instance = $instance; |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param string $lockStatus |
152
|
|
|
* |
153
|
|
|
* @return FederatedShare |
154
|
|
|
*/ |
155
|
|
|
public function setLockStatus(string $lockStatus): self { |
156
|
|
|
$this->lockStatus = $lockStatus; |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
|
|
public function getLockStatus(): string { |
165
|
|
|
return $this->lockStatus; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return string |
171
|
|
|
*/ |
172
|
|
|
public function getInstance(): string { |
173
|
|
|
return $this->instance; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return bool |
178
|
|
|
*/ |
179
|
|
|
public function isLocal(): bool { |
180
|
|
|
return $this->getManager()->isLocalInstance($this->getInstance()); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param array $data |
186
|
|
|
* |
187
|
|
|
* @return IDeserializable |
188
|
|
|
*/ |
189
|
|
|
public function import(array $data): IDeserializable { |
190
|
|
|
$this->setId($this->getInt('id', $data)); |
191
|
|
|
$this->setItemId($this->get('itemId', $data)); |
192
|
|
|
$this->setCircleId($this->get('circleId', $data)); |
193
|
|
|
$this->setInstance($this->get('instance', $data)); |
194
|
|
|
|
195
|
|
|
return $this; |
|
|
|
|
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param array $data |
201
|
|
|
* |
202
|
|
|
* @return INC22QueryRow |
203
|
|
|
*/ |
204
|
|
|
public function importFromDatabase(array $data): INC22QueryRow { |
205
|
|
|
$this->setId($this->getInt('id', $data)); |
206
|
|
|
$this->setItemId($this->get('item_id', $data)); |
207
|
|
|
$this->setCircleId($this->get('circle_id', $data)); |
208
|
|
|
$this->setInstance($this->get('instance', $data)); |
209
|
|
|
|
210
|
|
|
if ($this->getInstance() === '') { |
211
|
|
|
$this->setInstance($this->getManager()->getLocalInstance()); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
return $this; |
|
|
|
|
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @return array |
220
|
|
|
*/ |
221
|
|
|
public function jsonSerialize(): array { |
222
|
|
|
return [ |
223
|
|
|
'id' => $this->getId(), |
224
|
|
|
'itemId' => $this->getItemId(), |
225
|
|
|
'circleId' => $this->getCircleId(), |
226
|
|
|
'instance' => $this->getInstance() |
227
|
|
|
]; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.