|
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\Db; |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
use OCA\Circles\Exceptions\CircleNotFoundException; |
|
36
|
|
|
use OCA\Circles\Model\Circle; |
|
37
|
|
|
use OCA\Circles\Model\Member; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Class CircleRequest |
|
42
|
|
|
* |
|
43
|
|
|
* @package OCA\Circles\Db |
|
44
|
|
|
*/ |
|
45
|
|
|
class CircleRequest extends CircleRequestBuilder { |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param Circle $circle |
|
50
|
|
|
*/ |
|
51
|
|
|
public function save(Circle $circle): void { |
|
52
|
|
|
$qb = $this->getCircleInsertSql(); |
|
53
|
|
|
$qb->setValue('id', $qb->createNamedParameter($circle->getId())); |
|
54
|
|
|
// ->setValue('instance', $qb->createNamedParameter($circle->getInstance())) |
|
55
|
|
|
// ->setValue('href', $qb->createNamedParameter($remote->getId())) |
|
56
|
|
|
// ->setValue('item', $qb->createNamedParameter(json_encode($remote->getOrigData()))); |
|
57
|
|
|
|
|
58
|
|
|
$qb->execute(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param Circle $circle |
|
64
|
|
|
*/ |
|
65
|
|
|
public function update(Circle $circle) { |
|
66
|
|
|
$qb = $this->getCircleUpdateSql(); |
|
67
|
|
|
// $qb->set('uid', $qb->createNamedParameter($circle->getUid(true))) |
|
68
|
|
|
// ->set('href', $qb->createNamedParameter($circle->getId())) |
|
69
|
|
|
// ->set('item', $qb->createNamedParameter(json_encode($circle->getOrigData()))); |
|
70
|
|
|
|
|
71
|
|
|
$qb->limitToUniqueId($circle->getId()); |
|
72
|
|
|
|
|
73
|
|
|
$qb->execute(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param Member|null $viewer |
|
79
|
|
|
* @param Member|null $filter |
|
80
|
|
|
* |
|
81
|
|
|
* @return Circle[] |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getCircles(?Member $viewer = null, ?Member $filter = null): array { |
|
84
|
|
|
$qb = $this->getCircleSelectSql(); |
|
85
|
|
|
$qb->leftJoinOwner(); |
|
86
|
|
|
|
|
87
|
|
|
if (!is_null($viewer)) { |
|
88
|
|
|
$qb->limitToViewer($viewer); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (!is_null($filter)) { |
|
92
|
|
|
$qb->limitToMembership($filter); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return $this->getItemsFromRequest($qb); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param string $id |
|
101
|
|
|
* |
|
102
|
|
|
* @return Circle |
|
103
|
|
|
* @throws CircleNotFoundException |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getCircle(string $id): Circle { |
|
106
|
|
|
$qb = $this->getCircleSelectSql(); |
|
107
|
|
|
$qb->limitToUniqueId($id); |
|
108
|
|
|
$qb->leftJoinOwner(); |
|
109
|
|
|
|
|
110
|
|
|
return $this->getItemFromRequest($qb); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return Circle[] |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getFederated(): array { |
|
118
|
|
|
$qb = $this->getCircleSelectSql(); |
|
119
|
|
|
$qb->filterConfig(Circle::CFG_FEDERATED); |
|
120
|
|
|
$qb->leftJoinOwner(); |
|
121
|
|
|
|
|
122
|
|
|
return $this->getItemsFromRequest($qb); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
|